You can trigger a list event from the program as follows:
SET USER-COMMAND <fc>.
This statement takes effect after the current list is completed. Before the list is displayed, the event assigned to function code <fc> is triggered, regardless of the dialog status you are using.
The effect is the same as when the user chooses the function. In other words, predefined list function codes are trapped and processed by the runtime environment, the function codes PICK and PF<nn> trigger the AT LINE-SELECTION and AT PF<nn> events, and user-defined function codes trigger the AT USER-COMMAND event block.
Function code PICK triggers an event only if the cursor is located on a list line.
Using this statement in conjunction with the function codes reserved for system functions, you can call the system functions from the program. For example, you can use SET USER- COMMAND '%SC' to call the Find dialog box directly, or to position the list correctly before it is displayed.
If you use several SET USER-COMMAND statements while creating a list, the system executes only the last one.
Examples
Example for AT LINE-SELECTION.
REPORT demo_list_at_line_selection.
START-OF-SELECTION.
WRITE 'Basic List'.
AT LINE-SELECTION.
WRITE: 'Secondary List by Line-Selection', / 'SY-UCOMM =', sy-ucomm.
When you run the program, the basic list appears with the standard list status. The detail list shows that SY-UCOMM has the value PICK.
Example for AT PF<nn>.
REPORT demo_list_at_pf.
START-OF-SELECTION.
WRITE 'Basic List, Press PF5, PF6, PF7, or PF8'.
AT pf5.
PERFORM out.
AT pf6.
PERFORM out.
AT pf7.
PERFORM out.
List Events in an ABAP Program AT pf8.
PERFORM out.
FORM out.
WRITE: 'Secondary List by PF-Key Selection', / 'SY-LSIND =', sy-lsind,
/ 'SY-UCOMM =', sy-ucomm.
ENDFORM.
After executing the program, the system displays the basic list. The user can press the function keys F5, F6, F7, and F8 to create secondary lists. If, for example, the 14th key the user presses is F6, the output on the displayed secondary list looks as follows:
Secondary List by PF-Key Selection SY-LSIND = 14
SY-UCOMM = PF06
Example for AT USER-COMMAND.
REPORT demo_list_at_user_command NO STANDARD PAGE HEADING.
START-OF-SELECTION.
WRITE: 'Basic List',
/ 'SY-LSIND:', sy-lsind.
TOP-OF-PAGE.
WRITE 'Top-of-Page'.
ULINE.
TOP-OF-PAGE DURING LINE-SELECTION.
CASE sy-pfkey.
WHEN 'TEST'.
WRITE 'Self-defined GUI for Function Codes'.
ULINE.
ENDCASE.
AT LINE-SELECTION.
SET PF-STATUS 'TEST' EXCLUDING 'PICK'.
PERFORM out.
sy-lsind = sy-lsind - 1.
AT USER-COMMAND.
CASE sy-ucomm.
WHEN 'FC1'.
PERFORM out.
WRITE / 'Button FUN 1 was pressed'.
WHEN 'FC2'.
PERFORM out.
WRITE / 'Button FUN 2 was pressed'.
WHEN 'FC3'.
PERFORM out.
WRITE / 'Button FUN 3 was pressed'.
WHEN 'FC4'.
PERFORM out.
WRITE / 'Button FUN 4 was pressed'.
WHEN 'FC5'.
PERFORM out.
WRITE / 'Button FUN 5 was pressed'.
ENDCASE.
sy-lsind = sy-lsind - 1.
List Events in an ABAP Program FORM out.
WRITE: 'Secondary List', / 'SY-LSIND:', sy-lsind, / 'SY-PFKEY:', sy-pfkey.
ENDFORM.
When you run the program, the system displays the following basic list with a the page header defined in the program:
You can trigger the AT LINE-SELECTION event by double-clicking a line. The system sets the status TEST and deactivates the function code PICK. The status TEST contains function codes FC1 to FC5. These are assigned to pushbuttons in the application toolbar. The page header of the detail list depends on the status.
Here, double-clicking a line no longer triggers an event. However, there is now an application toolbar containing five user-defined pushbuttons. You can use these to trigger the AT USER-COMMAND event. The CASE statement contains a different reaction for each pushbutton.
For each interactive event, the system decreases the SY-LSIND system field by one, thus canceling out the automatic increase. All detail lists now have the same level as the basic list and thus overwrite it. While the detail list is being created, SY-LSIND still has the value 1.
Example for SET USER-COMMAND.
REPORT demo_list_set_user_command NO STANDARD PAGE HEADING.
START-OF-SELECTION.
SET USER-COMMAND 'MYCO'.
WRITE 'Basic List'.
AT USER-COMMAND.
CASE sy-ucomm.
WHEN 'MYCO'.
WRITE 'Secondary List from USER-COMMAND,'.
WRITE: 'SY-LSIND', sy-lsind.
SET USER-COMMAND 'PF05'.
ENDCASE.
AT pf05.
WRITE 'Secondary List from PF05,'.
WRITE: 'SY-LSIND', sy-lsind.
SET CURSOR LINE 1.
SET USER-COMMAND 'PICK'.
AT LINE-SELECTION.
WRITE 'Secondary List from LINE-SELECTION,'.
WRITE: 'SY-LSIND', sy-lsind.
SET USER-COMMAND '%SC'.
This program creates one basic list and three detail lists. When the program starts, the third detail list is displayed immediately, along with a dialog box for searching in the list. The dialog box is displayed by setting the predefined function code %SC. To view the other lists, the user chooses Back.
Note that in the event AT PF05, the SET CURSOR statement is used to position the cursor on a list line in order to support the function code PICK.