Mastering SAP ABAP Module Pool Programming: Handling User Interactions with 'At Exit' Commands
- In SAP ABAP, Module Pool programming involves creating interactive applications within the SAP system. These applications typically consist of multiple screens or dialog steps. At exit commands are used to trigger actions when a user exits a screen within the module pool. There are primarily two types of "at exit" commands:
AT EXIT-COMMAND:
- This is used at the screen level to handle user actions such as pressing the Cancel or Back button on the screen toolbar.
- It is typically used to perform cleanup tasks or to navigate to other screens based on user input.
- At EXIT-COMMAND statement is normally used to leave the current screen without the automatic input checks taking place.
- Syntax:
PROCESS AFTER INPUT.
MODULE user_command_1000 AT EXIT-COMMAND.
AT EXIT-COMMAND ON END-OF-SELECTION:
- This is used at the program level and is triggered when the user exits the entire program or when the end-of-selection event is reached.
- It is often used to perform final processing tasks or to display summary information before exiting the program.
- Syntax:
AT EXIT-COMMAND ON END-OF-SELECTION.
In both cases, the associated module or event is executed when the specified exit condition is met. This allows developers to control the flow of the program and perform necessary actions when a user exits a screen or the program itself.
Requirement :-
-
As you remember, In the Sub screen Part we have created a Module Pool Program.
- Now, When I am clicking on Submit button without any input in the Order Number, I want that it should give me a Error message.
Solution :-
-
Open the screen 100 and Click on Layout.
-
In the layout Double click on the input fields of Order number → Program → required → save the layout.
-
Activate and execute the program.
-
Now, I am clicking on Submit button without any input, We can see that It is giving a error message.
-
Now, Suppose I create a pushbutton named ‘BACK’.
-
And if I am clicking on back button, without any input, It is giving same error.
Requirement :-
- Now Customer wants that on clicking on back button, It should take him back to the main program without giving any error.
Solution :-
- Step 1 :- Open the layout on the screen 100.
- Step 2 :- Give a function code and select function type as E {Exit Command } for BACK button.
-
Step 3 :- Save the layout and activate the screen.
-
Step 4 :- Open the flow logic of Screen 100, Write the below commands.
-
Step 5 :- Double click EXIT above and create a program in master program.
Code :-
*&---------------------------------------------------------------------*
*& Modulpool ZAR_SUB_SCREEN
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
PROGRAM ZAR_SUB_SCREEN.
TABLES : ZAR_HEADER.
types : begin of ty_header,
ORDER_NUMBER type ZAR_ORDER_NUMBER,
ORDER_DATE type ZAR_ORDER_DATE,
PAYMENT_MODE type ZAR_PAYMENT_MODE,
TOTAL_AMOUNT type ZAR_TOTAL_AMOUNT,
CURRENCY type ZAR_CURENCY,
end of ty_header.
data : lt_header type table of ty_header,
ls_header type ty_header.
*&---------------------------------------------------------------------*
*& Module STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
MODULE status_0100 OUTPUT.
SET PF-STATUS 'HEADER'.
SET TITLEBAR 'HDR'.
ENDMODULE.
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE user_command_0100 INPUT.
if sy-ucomm eq 'SUBMIT'.
select ORDER_NUMBER order_date
payment_mode total_amount currency
from ZAR_HEADER into table lt_header
where order_number = ZAR_HEADER-ORDER_NUMBER.
Read table lt_header into ls_header index 1.
if sy-subrc eq 0.
ZAR_HEADER-ORDER_DATE = ls_header-order_date.
ZAR_HEADER-payment_mode = ls_header-payment_mode.
ZAR_HEADER-total_amount = ls_header-total_amount.
ZAR_HEADER-currency = ls_header-currency.
endif.
endif.
if sy-ucomm eq 'BACK'.
leave to screen 0.
endif.
ENDMODULE.
*&---------------------------------------------------------------------*
*& Module EXIT INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE exit INPUT.
if sy-ucomm eq 'CANCEL'.
leave to screen 0.
endif.
ENDMODULE.
Execute the Program :-
-
Click on Back button.
- As we can see it is redirecting us back to main program.
Comments
Post a Comment