List Events in an ABAP Program
After a user interaction on a list, the ABAP runtime environment checks whether it should process the function code itself (for example, %EX or %PC), or whether it should trigger the relevant event. Unlike normal screens, in which the PAI event is triggered, the runtime environment triggers three special events when list events occur. You can use the corresponding event blocks in your ABAP program to react to the user action. From within the program, you can use the sy-ucomm system field to access the function code. There is no OK_CODE field to be filled here.
Event Blocks for Function Codes PFnn (Obsolete)
When the user chooses a function code PFnn (nn can be between 01 and 24), the system always triggers the AT PFnn event. In the standard list status, the function keys Fnn that are not reserved for predefined system functions all have the function code PFnn as long as a corresponding event block is defined in the program.
AT PFnn statements.
These event blocks are executed when the user chooses the corresponding function key. The position of the cursor in the list is irrelevant.
If you use these event blocks at all, it should only be for temporary test versions . In production programs, you should only use AT USER-COMMAND with a dialog status of your own to assign function codes to function keys. When you use your own interfaces, the system displays a function text explaining what the function does. This does not happen when you use AT PFnn event blocks.
Event Block for Function Code PICK
When the user triggers the function code PICK, AT LINE-SELECTION is always triggered if the cursor is positioned on a list line. The function code PICK is, by default, always linked with function key F2 and hence with the mouse double-click. Consequently, if you have a simple program that does not react to any further user actions, you only need to write this event block.
AT LINE-SELECTION. statements.
As described in the section Dialog Status for Lists , the function code PICK is always added to the standard list status when you have an AT LINE-SELECTION event in your program.
If you assign PICK to other function keys or menu entries, AT LINE-SELECTION is also triggered when the user chooses then. You should avoid this for the sake of the semantics.
Conversely, if you have a more extensive program that does not react to line selection, you should not use the function code PICK. Instead you should assign a different function code to F2 , to ensure that as many events as possible trigger the AT USER-COMMAND event.
Event Block for User-Defined Function Codes
If the user chooses a function code during list processing that is neither processed by the system, or PICK or PFnn, the system triggers the event AT USER-COMMAND . For this event, you must define your own GUI status for a list . To react to your own function codes in a program, you must define the following event block:
AT USER-COMMAND. statements.
In this event block, you can use an IF or CASE structure to differentiate between the function codes. They are available in the system field sy-ucomm . There are further system fields that are filled in list events, such as sy-lsind and sy-pfkey , that allow you to make further case distinctions.
Triggering a List Event from the Program
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 PFnn trigger the AT LINE-SELECTION and AT PFnn 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.