Anthony Cecchini is the President of Information Technology Partners (ITP), an SAP consulting company headquartered in Pennsylvania. ITP offers comprehensive planning, resource allocation, implementation, upgrade, and training assistance to companies. Anthony has over 17 years of experience in SAP R/3 business process analysis and SAP systems integration. His areas of expertise include SAP NetWeaver integration; ALE development; RFC, BAPI, IDoc, Dialog, and Web Dynpro development; and customized Workflow development. You can reach him at [email protected].
Configuring the ALV Grid Control Instance
When we ended the last blog on the ALV Grid Control I promised that we would cover some simple extensions in this blog. So lets begin………..
The key to configuring the ALV Grid Control for your particular application is the structures that are passed by the application to an ALV Grid instance before or during list display. For some simple extensions of your ALV Grid instance, you only need to set the right parameter and pass the table or structure by using method set_table_for_first_display.
Once the ALV Grid control has been integrated on the screen, you will likely want to configure it to do things like:
– Calculate totals initially
– Hide columns, the toolbar, the grid title, or the column headers
– Add, replace, or hide functions from the toolbar
– React to a double-click on a row to show a detail list
– Interpret values of a column as icons
Like it was stated above, The key to configuring the ALV Grid Control for your particular application is the structures that are passed by the application to an ALV Grid Control instance. Below is a list of the structures that can be passed.
Of the seven structure/tables listed above, the field catalog is the most important one for the ALV Grid Control.
Let’s take a look at a specific example. Lets say we want to provide a title to our ALV Grid Control. We also would like to hide the search capability from the standard toolbar so the user doesn’t have that ability.
OK — let’s grab a code snippet from the previous Blog A Guide to the New ALV Grid Control – Part 1. Look at the bold font lines below.
data: gt_exclude type ui_functions. data: gs_exclude type ui_func. data: gs_layout type lvc_s_layo.
gs_exclude = cl_gui_alv_grid=>mc_fc_find. append gs_exclude to gt_exclude.
gs_layout-grid_title = 'My Grid Title'.
CALL METHOD G_GRID->SET_TABLE_FOR_FIRST_DISPLAY EXPORTING I_STRUCTURE_NAME = 'SFLIGHT' IS_LAYOUT = GS_LAYOUT IT_TOOLBAR_EXCLUDING = GT_EXCLUDE CHANGING IT_OUTTAB = GT_SFLIGHT.
The structure gs_exclude of type ui_func is used in the internal table gt_exclude of type ui_functions. The “g” is for Global and “s” and “t” are for structure and table respectively. The search function is referenced by the class attribute MC_FC_FIND of class CL_GUI_ALV_GRID. You can hide other standard functions or menu buttons as well by adding other attributes with prefix MC_FC_ or MC_MB_, respectively.
We added the title to gs_layout-grid_title.
Finally to get these changes to manifest in our ALV Grid Control, we added IS_LAYOUT = GS_LAYOUT and IT_TOOLBAR_EXCLUDING = GT_EXCLUDE to the call statement for the method “SET_TABLE_FOR_FIRST_DISPLAY”
Setting Properties Using the Field Catalog in the ALV Grid Control
As mentioned earlier, the ALV determines the output format of values using the field catalog. If you choose to build the field catalog manually, you need to know which fields are mandatory.
Listed below are the required fields.
Fortunately, in most cases you can generate the field catalog (semi-)automatically, as I will show you, so you don’t need to fill in these fields.
Generating the Field Catalog for the ALV Grid Control
You have several options for building a field catalog:
1)Automatically through an ABAP Dictionary structure (as in our example above) — the ALV Grid Control then uses this structure to generate the field catalog on its own
2)Manually in your ABAP program (by filling at least the mandatory fields for each entry of our output table)
3)Semi-automatically by combining the first two procedures
In the case of the first option, you use parameter I_STRUCTURE_NAME, and in the latter cases IT_FIELDCATALOG of method set_table_for_first_display.
Since the last option is the most commonly used, it will be the focus of our discussion. When generating the field catalog semi-automatically, you combine structure information of the ABAP Dictionary with your own structure information.
This allows you to modify or add structure descriptions of new fields to the automatically generated field catalog, which may be helpful for the following scenarios:
– You want to display an ABAP Dictionary table without displaying all possible columns initially (using field NO_OUT, another field of the field catalog).
– You want to display additional columns containing icons or other information.
To generate a field catalog semi-automatically all you need to do is call function module LVC_FIELDCATALOG_MERGE and pass the ABAP Dictionary structure of the output table and the internal table for the field catalog.
The function module generates the field catalog and fills the internal table accordingly.
Please remember to read the rows you want to change, and adapt the fields accordingly. If your output table contains more fields than are stored in the ABAP Dictionary, you must append one row for each new field to the field catalog.
Again, an example will help clear this up. The code snippet below deals again with a list of the good old flight model. In the code, column PLANETYPE is hidden and an additional column is used to display icons.
data: begin of outtab occurs 0. include structure sflight. data: icon_column(40) type c. data: end of outtab.
OK, now lets semi-generate the Field Catalog for the ALV Grid Control.
CALL FUNCTION 'LVC_FIELDCATALOG_MERGE' EXPORTING I_STRUCTURE_NAME = 'SFLIGHT' CHANGING CT_FIELDCAT = fieldcat.
Now that we have a field catalog, lets modify entry of field catalog for the column PLANETYPE and stop it from displaying on the ALV Grid Control.
read table fieldcat into wa_fieldcat with key fieldname="PLANETYPE".
if sy-subrc eq 0. l_index = sy-tabix. wa_fieldcat-no_out = 'X'. modify fieldcat from wa_fieldcat index l_index. endif.
Now lets add an entry to the field catalog titled “ICON COLUMN”. This is where we would put an ICON. Later in the code, we will put the delete icon at the end of a data row.
clear wa_fieldcat. wa_fieldcat-fieldname = 'ICON_COLUMN'. wa_fieldcat-outputlen = 5. wa_fieldcat-just = 'C'. wa_fieldcat-coltext = 'Icons'. wa_fieldcat-seltext = 'Icon column'. append wa_fieldcat to fieldcat.
Finally, lets select the data from the table SFLIGHT and add the the delete icon at the end of the row and display the ALV Grid Control.
SELECT * FROM SFLIGHT INTO table sflight.
loop at sflight into wa_sflight. move-corresponding wa_sflight to wa_outtab. wa_outtab-icon_column = ICON_DELETE. append wa_outtab to outtab. endloop.
[...] CALL METHOD GRID1->SET_TABLE_FOR_FIRST_DISPLAY CHANGING it_fieldcatalog = fieldcat IT_OUTTAB = outtab.
Some final thoughts……..
SAP developed the ALV Grid Control using a continuous naming convention, which helps you to remember structure or table names:
– LVC_S_XXXX — structures
– LVC_T_XXXX — tables; for a table there exists a table type and a corresponding line type in the ABAP Dictionary (e.g., LVC_S_HYPE is a line type for table LVC_T_HYPE)
– I_*, IS_*, or IT_* — for import or changing parameters (simple type, structure, or table) of methods
– E_*, ES_*, or ET_* — for export parameters (simple type, structure, or table)
In the next blog we will look at adding Application Specific functions like push buttons or context menu that provides different functions to the ALV Grid Control. We will also examine how we can use Interactive Reporting with the ALV Grid Control.
If you want to read the first part of this Blog series on The New ALV Grid Control, click A Guide to the New ALV Grid Control – Part 1