Introduction – The Idea |
Developers would like build the various ALV interactive Event handlers of a Report with the minimum effort and would like to devote more time on the data extraction and data display logic. At the same time Client would like to have all the Reports maintain a consistence Event pattern like Top-of-page, End-of-Page pattern and invest more time in verifying data display in ALV.
This document will help in implementing a global ALV Utility class which can be used by all Reports for displaying output in ALV format.
Developers will be able to create ALV handlers just by calling a method of this ALV Utility global class and passing the name of the Report Program. Details of the Report will be automatically picked by the Utility class.
Moreover this Class has options for enhancements and hence can be customized as per the Project need.
This Guide will demonstrate how to automate the creation of Top-Of-Page event of an ALV output.
How to reach there? |
We have developed a Utility Class ZCL_ALV_HEADER_UTILITY which can be used to implement Top-of-page section of any ALV Report with minimum coding effort. This class has different methods which, if used in proper sequence, can build a Top-of-page in any customized way.
Basic steps to implement the Top-of-page logic using this Utility class:
v Create Object of this Class.
v Pass the current Report name to this Object.
v Display the Top-of-page by passing the desired Report header text to this Object.
Prerequisite: |
1. Selection screen naming convention should be as per Project naming convention guideline. This will help in configuring the Utility program for generic use.
For example:
1.1. Parameter: P_
1.2. Select-options: S_
2. All the Selection screen elements should have their correspondence Text created in the Text pool of the Report program. This is crucial since the Utility class reads the Text pool of the report.
3. Report program can use either ALV with OOPs approach or ALV with Function Module approach.
Steps to use the class in an ALV OOPs Report |
ALV using OOPs approach – CL_GUI_ALV_GRID |
4. For events of ALV grid we always create a Local Class to handle the events. Design the Local class in the Program to handle TOP-OF-PAGE. This Local Class should have a method to write code for TOP_OF_PAGE of Class CL_GUI_ALV_GRID. Here this method is LCL_EVENT_HANDLER.
CLASS lcl_event_handler DEFINITION FINAL. |
CLASS lcl_event_handler IMPLEMENTATION. |
5. The FORM will have an object of the Class CL_DD_DOCUMENT. This Object has to be designed to display the TOP-OF-PAGE form. Here this object is E_DYNDOC_ID.
FORM f_event_top_of_page USING p_dyndoc_id TYPE REF TO cl_dd_document. *********************************************************** * Define Object for Utility Class *********************************************************** |
In the above code:
5.1. The Object for the Utility Class is built using the Constructor method. This Constructor needs a reference object of Class CL_DD_DOCUMENT, which will be used internally by the Class to build up the TOP_OF_PAGE.
The reference Object shown here is P_DYNDOC_ID. This Object has been created while creating the implementation of the local class event.
* Define Object for Utility Class |
5.2. After the Utility Class object is created, we have to use the READ_SELECTION_SCREEN method of this class to read the Selection screen elements of our current program. This is done by simply passing the Report program name using SY-REPID system variable.
* Read the current Report Selection screen |
5.3. If there are any Parameters or Select Options in the Selection screen which has to have special formatting while display, then the method ADD_SPECIAL_PARAM has to be used. In this method we have to pass the name of the special parameter/select-option and also pass the type of this parameter.
Presently in this example, we wanted to display S_DATE select-option of the selection screen using External Date formatting. Passing the details of the parameter to this class method, internally the class will be converting the Date entry for this select-option to external user recognized format and will display it.
* Add any special parameter of Selection Screen(if present) |
5.4. Finally call the method SET_GRID_TOP to display the top of the page. In this method interface we can define a maximum of 4 titles for the Report. These titles will be displayed in the top before the Selection parameters are listed.
* Display the ALV Top of Page by passing the desired Titles |
Result: |
Program: ZUTILITY_TEST |
ALV using Function Module approach - REUSE_ALV_GRID_DISPLAY |
1. Call ALV Function Module for display. Here we are supposed to call I_CALLBACK_HTML_TOP_OF_PAGE for calling Top-of-page routine.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY' |
2. The FORM for this ‘TOP_OF_PAGE’ as shown above has to be build as shown below. This FORM will be using a CL_DD_DOCUMENT to build the Top-of-page. Inside this FORM we have to call the Utility class object and the Top-of-page is displayed.
FORM TOP_OF_PAGE USING p_dyndoc_id TYPE REF TO CL_DD_DOCUMENT. |
The above code is similar to the Code for OOPs approach and has the same logic for displaying Top-of-page.
Result: |
Program: ZUTILITY_TEST_FM |
Great information.thanks for same.
ReplyDeleteUltimateblogger
SAP-edi.blogspot.com
learnabapprogramming.blogspot.com
nice information but how to create utility class
ReplyDeleteUtility class is a stand alone class with methods and created on Global SAP level and not on program level.
Delete