By default, the function toolbar is not displayed in the new ALV Display. It must be activated. The functions object is retrieved from the ALV Object. In order to activate the complete function toolbar, the set_all( ) method of the function object must be called.
DATA lr_functions_list TYPE REF TO cl_salv_functions_list.
The new ALV Display model based on the class CL_SALV_TABLE provides various functionalities similar to the old ALV Display. But the data fields of the ALV Table are not directly editable.
There are two Display modes for the new SAP ALV Display based on class CL_SALV_TABLE.
Full Screen mode: There is no need of container and Dynpro.
Container mode: It is created through the Dynpro and container.
Full Screen mode: The following steps are necessary to construct an SAP ALV Display based on the class CL_SALV_TABLE.
Fill an Internal table with the Details.
Create an object of class CL_SALV_Table through FACTORY( ) method.
Display ALV.
Loading Internal Table
DATA lt_contact TYPE TABLE OF ztt_db_table2.
SELECT * FROM ztt_db_table2 INTO TABLE lt_contact.
Creation of object of type CL_SALV_TABLE
The static method ‘FACTORY’ of the class CL_SALV_TABLE returns the object of class CL_SALV_TABLE as an exporting parameter. This is the instance of the ALV object.
DATA lr_salv_table TYPE REF TO cl_salv_table.
CALL METHOD cl_salv_table => factory
IMPORTING
r_salv_table = lr_salv_table
CHANGING
t_table = lt_contact.
ALV Display
Finally the ALV List is displayed by calling the Display method of the ALV object.
lr_salv_table -> Display ().
Container mode :
In order to display the ALV list in container mode, you need a Dynpro with a container.
The following steps are written to Display the ALV.
Creation of container object.
DATA lr_container TYPE REF TO cl_gui_custom_container.
CREATE OBJECT lr_container
EXPORTING
Container_name = ‘SALV_CONTAINER’.
Creation of ALV object.
In this mode as well, the static method ‘FACTORY’ of the class cl_salv_table is used to create the ALV object. The container object is given as an exporting parameter in the method call. The Internal table with the ALV contents is specified in the changing parameter.
The user can be able to change the layout such as hiding columns, sorting specific columns or adding a filter in ALV Table List. The user can also be able to save the layouts of ALV Report in the toolbar. In order to enable this feature, the user must activate this option programmatically.
There are two key steps to activate the save layout option in ALV table list.
Assign the fields report, username of the structure disvariant.
Set the exporting parameters is_variant, i_save during the method call SET_TABLE_FOR_FIRST_DISPLAY of ALV object.
Assign fields of structure DISVARIANT
It contains the details of the report and username to which the layout can be saved.
DATA ls_variant TYPE disvariant.
ls_variant-report = sy-repid.
ls_variant-username = sy-uname.
Setting the exporting parameters is_variant, i_save.
There are different saving options such as ‘U’, ‘X’, ‘A’ for the exporting parameter i_save.
U: User defined layout can be saved in this option. The layout cannot be seen by other users.
X: It is the Global layout. Other users can also see this layout.
A: The user can save both user defined layout and Global layout.
Let us look at the following SET_TABLE_FOR_FIRST_DISPLAY Method.
If you are having more than one ALV in the same program, then each ALV must be uniquely differentiated through the field HANDLE. The field HANDLE hold a ID with four characters which is unique. Each ALV variant is differentiated through this unique ID.
The colums can be sorted by default in the ALV table. So that it is sorted initially when it is first displayed.
The internal table of type LVC_T_SORT can be used for this purpose.
The following key fields of LVC_T_SORT to be filled are:
Fieldname: The column to be sorted must be mentioned in this field.
UP: If the column must be sorted in increasing or ascending order,then the value ‘X’ must be set to the field ‘UP’.
DOWN: If the column must be sorted in descending or decreasing order, then the value ‘X’must be set to the field ‘DOWN’.
SPOS: If two or more columns must be sorted. Then we can prioritize the sorting sequence. For example, second column must be sorted before the first column.
Let us look at the ALV table sorting with the following example.
The width of the column in the SAP ALV List is controlled through the fields OUTPUTLEN and COL_OPT of the field catalog. The field OUTPUTLEN of the field catalog sets the size of the column with an Integer value. By setting the field COL_OPT of the field catalog to ABAP_TRUE, the width of the column is adjusted according to the text content of the column.
So the content with the maximum value defines the width of the column. If both the fields of the field catalog is used, then the optimized column width option is preferred automatically.
Let us look at the following example.
FIELD-SYMBOLS <ls_field_cat> TYPE lvc_s_fcat.
LOOP AT lt_field_cat ASSIGNING <ls_field_cat> WHERE fieldname = ‘CONTACT_ADDRESS’.