How to skip mandatory fields on selection screen?

13,651

Solution 1

What you need to do is have a function code assigned to the pushbutton on the screen that has the function type "Exit".

Then you can use the event AT SELECTION-SCREEN ON EXIT-COMMAND in your report (I assume you are talking about a report because you talk about selection screens). This event is called by the system before validating the fields on the screen. Here you can implement all your necessary logic.

However, the only way I can think how to do that is to copy the standard GUI status %_00 from program RSSYSTDB to your program and add your function code and make it a type "exit". Then in AT SELECTION-SCREEN OUTPUT you can use the SET PF-STATUS command to override the standard GUI status. (Otherwise if you assign a function code to your pushbutton, but it will not receive special treatment to trigger the ON EXIT-COMMAND event).

EDIT: I just tried this and it works, but not when assigning the function code to a pushbutton (using SELECTION-SCREEN PUSHBUTTON). Instead, I had to add the function code as a button on the toolbar. Then it triggers the AT SELECTION-SCREEN OUTPUT event).

EDIT 2: (Just copied my comment from below into here because it is important to note) By the way, I had to rename the %_00 GUI status to something else when I copied it. Otherwise, even when specifying the addition FROM PROGRAM in SET PF-STATUS, it would still use the old GUI status from RSSYSTDB.

Solution 2

You can do the following trick to achieve your requirement.

Prerequisites:

  1. First and the foremost! Do NOT declare your parameters using OBLIGATORY clause. This constraint overrides all internal checks and validations during selection screens processing.

  2. Here I assume that you use standard GUI status with buttons activated on Application Toolbar. Standard Execute button has standard ONLI fcode, whereas İptal has IPT.

  3. To manipulate target fields we need IDs assigned to them:

    PARAMETERS: p_matnr TYPE mara-matnr MODIF ID OBL,
                p_mtart TYPE mara-mtart MODIF ID OBL.
    

Solution details:

  1. Declare AT SELECTION-SCREEN OUTPUT event where fields' attributes would be edited.

    AT SELECTION-SCREEN OUTPUT.
    
    SET PF-STATUS 'SSCR'.       "<<- our GUI-status
    LOOP AT SCREEN.
     IF screen-group1 = 'OBL'.
       screen-required = '2'.   "<<- default obligatory-like field appearance
       MODIFY SCREEN.
     ENDIF.
    ENDLOOP.
    IF sy-ucomm = 'ONLI'.       "<<- making fields really obligatory
     LOOP AT SCREEN.
      IF screen-group1 = 'OBL'.
       screen-required = '1'.
       MODIFY SCREEN.
      ENDIF.
     ENDLOOP.
    ENDIF.
    
  2. Handling function codes in AT SELECTION-SCREEN event.

    AT SELECTION-SCREEN.
    
     IF sy-ucomm = 'ONLI'.
      LEAVE TO SCREEN 1000.
     ENDIF.
     IF sy-ucomm = 'IPT'.
      "<do whatever you want>
     ENDIF.
    

Explanation: on program start your fields have required attribute set to 2, which means they have obligatory tick, but not really acts like obligatory, i.e. that is exactly what you need. You can perfectly press your İptal button and run any other program.
However, if you want to enable obligatory constraints you simply press standard Execute and it invokes our selection screen again (LEAVE TO SCREEN 1000) but with another ONLI fcode upon which required attribute is overridden and voila! Going further is impossible until you fill these fields.

Share:
13,651
cethint
Author by

cethint

Updated on June 04, 2022

Comments

  • cethint
    cethint over 1 year

    I want it to skip mandatory fields when i clicked on 'İptal' button .

    But i don't want to control mandatory fields without "obligatory" . I want to see check mark in textboxes like screenshot.

    Normally 'İptal' button calls a different screen when there is no mandatory fields.

    When i clicked on İptal button, i want it to skip this mandatory fields

    Note: Screens are standard selection screens.

  • mydoghasworms
    mydoghasworms over 10 years
    By the way, I had to rename the %_00 GUI status to something else when I copied it. Otherwise, even when specifying the addition FROM PROGRAM in SET PF-STATUS, it would still use the old GUI status from RSSYSTDB.