SAP ALV Tutorial – Event
This article deals with event handling in SAP ALV and mechanism behind it. In a nutshell, ALV Grid is an implementation of custom control. You must be very familiar with the dynpro programming. In dynpro programming, we general have two events: PBO and PAI. If user have some actions in the frontend screen, the event PAI will be triggered and program can have different reactions according to different function codes. In the custom control, things become a slight different. It will trigger an specific event, if user does some actions in the frontend. There are two types of event: system event and application event.
The only difference of the two events are the sequence of triggering event handler method and the PAI event.
System event: A system event is triggered before any automatic field checks (for example,required fields) have taken place on the screen, and before any field transport. The PAI and PBO events are not triggered. Consequently, you cannot access any values that the user has just changed on the screen. Furthermore, there is no field transport back to the screen after the event, so values that you have changed in the event handling are not updated onthe screen.
The handler method that you defined for the event is called automatically by the system.However, you can use the method set_new_ok_code to set a new value for the OK_CODE field. This then triggers the PAI and PBO modules, and you can evaluate the contents of the OK_CODE field as normal in a PAI module.
Application event: This event is processed in the PAI event. Consequently, all field checks and field transport has taken place. If you want the event handler method to be called at a particular point in your application program, you must process the event using the static method CL_GUI_CFW=>DISPATCH.
Events in ALV
The ALV Grid Control uses the grid control to display the output table. So we can say that the ALV Grid Control is a wrapper that uses the wrapper of a Basis control. As the ‘outer layer’, this wrapper spares the developer from having to register the events on the frontend in order to simplify event handling. The ALV Grid Control differs from Basis controls in the following respects:All events are registered as system events when the control is instantiated.If you want to register all events as application events, you must use parameter I_APPL_EVENTS ( See also: CONSTRUCTOR). As usual, you must then call method CL_GUI_CFW=>DISPATCH in the PAI module.
Events DELAYED_CALLBACK or DELAYED_CHANGED_SEL_CALLBACK are registered using method register_delayed_event.
Below are all the events that are valid in ALV. But there are some differences depanding on how we call the ALV.
In object oriented method, we generally have below events:
User-defined Text Output
print_end_of_list Define output text to be printed at the end of the entire list
print_top_of_list Define output text to be printed at the beginning of the entire list
print_end_of_page Define output text to be printed at the end of each page
print_top_of_page Define output text to be printed at the beginning of each page
subtotal_text Define self-defined subtotals texts
Mouse-controlled Actions in the Grid Control
button_click Query a click on a pushbutton in the ALV Grid Control
double_click Query a double-click on a cell of the ALV Grid control
hotspot_click Query a hotspot click on columns defined for this purpose in advance
onDrag Collect information when elements of the ALV Grid Control are dragged
onDrop Process information when elements of theALV Grid Control are dropped
onDropComplete Perform final actions after successful Drag&Drop
onDropGetFlavor Distinguish between options for Drag&Drop behavior
Processing of Self-defined and Standard Functions
before_user_command Query self-defined and standard function codes
user_command Query self-defined function codes
after_user_command Query self-defined and standard function codes
Definition of Self-defined Functions
toolbar Change, delete or add GUI elements in the toolbar
menu_button Define menus for menu buttons in the toolbar
context_menu_request Change context menu
onf1 Define self-defined F1 help
In function module method, we can call funciton module ’REUSE_ALV_EVENTS_GET’to get all the events supported by FM ‘REUSE_ALV_GRID_DISPLAY’. You can also find all the event constants in the type pool SLIS, e.g. SLIS_EV_TOP_OF_PAGE,SLIS_EV_USER_COMMAND.
Ok, above are all the basic introduction about ALV event and its mechanism. In the next article of this series, I will use some specific code to demo how to use event both in OO and FM method.