Development resources, articles, tutorials, code samples, tools and downloads for SAP HANA and ABAP, HANA Database, SQLScript, SAP UI5, Screen Personas, Web Dynpro, Workflow
SAP ABAP Tutorial - ALV Grid Example with cl_gui_alv_grid and Screen Painter
This ABAP ALV tutorial includes an example ABAP program which lists VBAK and VBAP sales order items between given two VBELN numbers on an SAP screen on ALV grid using cl_gui_alv_grid class.
Tutorial includes a screenshot from the SAP program showing the output of the example ABAP program that filters data from VBAK and VBAP transparent tables and displays data on an ABAP ALV grid control cl_gui_alv_grid placed in a custom container on a dynpro screen.
Display data using cl_gui_alv_grid in ABAP programming
Let's begin with the source code of the example ABAP report codes.
Following ABAP codes include required data definitions, custom container and ALV grid object definitions as well as a call to SAP Dynpro screen to display ALV table with populated data.
Let's continue reviewing the sample ABAP program code with the screen 100 dynpro object.
Double click on 100 at ABAP statement "call screen 100" to create the dynpro screen.
In the below screenshot you can see the layout view of the screen on the SAP Screen Painter editor.
This Screen Painter example shows a Custom Control cl_gui_custom_container object and the ALV grid object cl_gui_alv_grid placed in that container.
If you double click on the custom control to display the element attributes, you can name the control as "CC_CONTAINER_GRID"
Please pay attention to the FctCode (function code) of the Button object BTNLIST. The FctCode is set as "BTNLIST" and will be controlled in the PAI (Process After Input) module with the ABAP CASE statement controlling the value of OK_CODE.
I named the two text box objects which I'll use to filter sales order documents according to document number VBELN fields as follows:
The first text element name: GRS_VBELN-LOW
Second text element name as: GRS_VBELN-HIGH
One last step for the screen 100 configuration is assigning OK_CODE variable by adding it to the general attributes in Element list of the screen.
Add below Process Before Output (PBO) module code or ABAP code block of the Screen 100 after all above screen element attributes are set.
Double click on TITLE to create a new title bar.
Also double click on MAINSTATUS to create a PF-STATUS object.
It is enough for this ABAP tutorial to navigate on the ABAP program if you define below standard toolbar commands.
And you can use below Process After Input (PAI) module code or ABAP code block of the Screen 100.
In U_FILTER_VBAK, the required ABAP code to select data from related data dictionary objects, tables according to the given criteria takes place.
Within this ABAP code block, the necessary internal tables are populated with data from SAP database.
And below ABAP developers can see how I build the field catalog required for displaying data on ALV grid.
The field catalog layout is used as a parameter for the ALV grid object's SET_TABLE_FOR_FIRST_DISPLAY method and forms the columns and display structure of the internal data.
The field catalog prepares ALV grid columns for display and sets properties of table columns.
For example, there are 7 columns displayed on the first screenshot of this ABAP tutorial.
But we have 9 fields in our field catalog.
ABAP programmers can notice field catalog property "NO_OUT" is used to hide a field on the ALV grid.
"no_out" enables programmers to set a column hidden on the ALV grid display but the values are still accessible when a click or double click event is triggered.
So if ABAP developer needs to hide a column on ALV grid, field catalog structure no_out field can be set to "X" to hide as seen in above sample code.
I hope I could help ABAP developers with a start-to-end sample code which they can use to display data on an ALV grid table on their SAP Dynpro screens.