How to skip mandatory fields on ABAP

六眼飞鱼酱① 提交于 2019-12-24 11:54:17

问题


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.

Note: Screens are standard selection screens.


回答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.




回答2:


the way that I have solved this not to make the fields obligatory in the layout but in your code to create some conditions example I have my input output field called ekpo-ebeln:

 IF ekpo-ebeln IS INITIAL.
    CASE ok_code.
      WHEN 'EXIT'.
        LEAVE PROGRAM.
      WHEN 'BACK'.
        CALL SCREEN 100.
    ENDCASE.
    MESSAGE 'Fill both of the fields' TYPE 'I'.

this solved my problem,and it works!




回答3:


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 fcode (ONLI) upon which required attribute is overriden and voila! Going further is impossible until you fill these fields.



来源:https://stackoverflow.com/questions/15084916/how-to-skip-mandatory-fields-on-abap

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!