Calling Modules Unconditionally 

In the PAI event, the PAI modules are called in the sequence in which they occur in the screen flow logic, after the automatic field checks. This means that the input on the screen must satisfy the automatic checks before the first module can be called. In particular, all required fields must be filled, and any checks against value lists or check tables defined for the field in the ABAP Dictionary must be successful.

In some cases, the user may have to enter a considerable amount of data merely in order to be able to leave the screen. To avoid this, you can use special function codes with a special module call, which calls the module regardless of what the user enters on the screen.

Type E Function Codes

You can assign the function type E to the function codes of both pushbuttons on the screen and of elements in the GUI status. To do this for a pushbutton, set the Function type attribute in the Screen Painter to E. To do it in the GUI status, choose Goto ® Object lists ® Function list in the Menu Painter, select the required function codes, and enter E for the function type.

If the user chooses a pushbutton or a function in the status, the system bypasses the automatic field checks and calls a special module in the screen flow logic. If the special module call does not exist, the system resumes normal PAI processing, that is, the automatic field checks take place after all.

As a rule, type E functions should allow the user to leave the screen. Consequently, the function codes for Back (F3), Exit (Shift + F3), and Cancel (F12) usually have type E.

Calling a PAI Module for Type E Functions

When the user chooses a function with type E, the screen flow logic jumps directly to the following statement:

MODULE <mod> AT EXIT-COMMAND.

Regardless of where it occurs in the screen flow logic, this statement is executed immediately, and before the automatic checks for the field contents on the screen. Before the module <mod> is executed, the contents of the OK-CODE field are transported to the ABAP field with the same name. However, no other screen fields are transported to the program at this stage. If you have more than one MODULE statement with the AT EXIT-COMMAND addition, only the first is executed. If there are no MODULE statements with the AT EXIT-COMMAND statement, normal PAI processing resumes.

If the user chooses a function whose function code does not have type E, the MODULE <mod> AT EXIT-COMMAND statement is not executed.

PAI Modules for Type E Functions

The MODULE ... AT EXIT-COMMAND statement is normally used to leave the current screen without the automatic input checks taking place. You should therefore program it to contain an appropriate variant of the LEAVE statement, to leave the current screen, the call chain, or the entire program, as appropriate. If the module does not leave the screen, normal PAI processing resumes after it has finished, that is, the automatic field checks take place, and the normal PAI modules are called, with data being transported from the screen back to the program according to the sequence defined in the FIELDS statements.

Unconditional module call

PROGRAM DEMO_DYNPRO_AT_EXIT_COMMAND.

DATA: OK_CODE LIKE SY-UCOMM,
      SAVE_OK LIKE OK_CODE,
      INPUT1(20), INPUT2(20).

CALL SCREEN 100.

MODULE INIT_SCREEN_0100 OUTPUT.
  SET PF-STATUS 'STATUS_100'.
ENDMODULE.

MODULE CANCEL INPUT.
  MESSAGE I888(BCTRAIN) WITH TEXT-001 OK_CODE INPUT1 INPUT2.
  IF OK_CODE = 'CANCEL'.
    CLEAR OK_CODE.
    LEAVE PROGRAM.
  ENDIF.
ENDMODULE.

MODULE BACK INPUT.
  MESSAGE I888(BCTRAIN) WITH TEXT-002 OK_CODE INPUT1 INPUT2.
  IF OK_CODE = 'BACK'.
    CLEAR: OK_CODE, INPUT1, INPUT2.
    LEAVE TO SCREEN 100.
  ENDIF.
ENDMODULE.

MODULE EXECUTE1 INPUT.
  MESSAGE I888(BCTRAIN) WITH TEXT-003 OK_CODE INPUT1 INPUT2.
  SAVE_OK = OK_CODE.
  CLEAR OK_CODE.
ENDMODULE.

MODULE EXECUTE2 INPUT.
  MESSAGE I888(BCTRAIN) WITH TEXT-004 OK_CODE INPUT1 INPUT2.
  IF SAVE_OK = 'EXECUTE'.
    MESSAGE S888(BCTRAIN) WITH TEXT-005.
  ENDIF.
ENDMODULE.

The next screen (statically defined) for screen 100 is itself. It has the following layout:

The input fields have the names INPUT1 and INPUT2, and are obligatory fields. The function codes of the pushbuttons are EXECUTE and CANCEL. CANCEL has function type E.

In the GUI status STATUS_100, the back (F3) and cancel (F12) icons are activated with the function codes BACK and CANCEL respectively. Both have the function type E. The function code EXECUTE is assigned to the function key F8. It does not have function type E.

The screen flow logic is as follows:

PROCESS BEFORE OUTPUT.
  MODULE INIT_SCREEN_0100.

PROCESS AFTER INPUT.
  MODULE EXECUTE1.
  MODULE CANCEL AT EXIT-COMMAND.
  MODULE BACK AT EXIT-COMMAND.
  MODULE EXECUTE2.

The program uses information and status messages to show which modules are called following user interaction and which data is transported.

The BACK module is never called, since only the first module with the AT EXIT-COMMAND addition is ever called. In the above example, the function code BACK should be processed in the CANCEL module. Then, since there is only one module statement with the AT EXIT-COMMAND addition, the position of the statement is irrelevant.