SALV Limitations: Separator in Toolbar
In this new series on SALV Object Model (SALV OM), I will document some of the Limitations which are not documented in standard SAP documentation.
In the ALV GRID (created using container) type of SALV, we can't have a Separator in the Toolbar. To add the separator in the Toolbar, button type (BUTN_TYPE) field of toolbar must be set to "3". SALV OM doesn't allow to specify this button type. It assumes that there would be only normal buttons (BUTN_TYPE = '0'). Method IF_SALV_TOOLBAR_ADAPTER~BUILD_UIFUNCTION in class CL_SALV_GRID_ADAPTER, creates the toolbar functions.
Code Lines which impose this restriction in SALV OMTo overcome this limitation, SAP could enhance SALV OM to provide us the method to set the button type in the CL_SALV_FUNCTION and use that button type here in the code instead of assuming that button as the normal button.
Apply Filters to SALV Table
In the series of the SALV Model Table display in SAP ABAP, today we will see how to apply Filters to the ALV Grid. You can find all the Previous discussion at
Tutorials > SALV Table Display.
Filters are important to display only values required by the users. i.e. See only the "Red" Lights from the Traffic Light report. To achieve this functionality, we have the CL_SALV_FILTERS class of SAP OM.
We can use the method ADD_FILTERS of the class CL_SALV_FILTERS to apply the filter on a specific column. The values in the filters would work exactly like values in a Range or Select-options i.e. SIGN, OPTION, LOW & HIGH. For this example, I have applied filters on the ERDAT column to only show records with a specific date.
| Code Snippet to Apply Filters |
REPORT ztest_oo_alv_filters. * *----------------------------------------------------------------------* * Code to Apply Filters to SALV Table Display *----------------------------------------------------------------------* * CLASS lcl_report DEFINITION *----------------------------------------------------------------------* CLASS lcl_report DEFINITION. * PUBLIC SECTION. * * Final output table TYPES: BEGIN OF ty_vbak, vbeln TYPE vbak-vbeln, erdat TYPE erdat, auart TYPE auart, kunnr TYPE kunnr, netwr TYPE netwr, END OF ty_vbak. TYPES: ty_t_vbak TYPE STANDARD TABLE OF ty_vbak. * DATA: t_vbak TYPE STANDARD TABLE OF ty_vbak. * * ALV reference DATA: o_alv TYPE REF TO cl_salv_table. * METHODS: * data selection get_data, * * Generating output generate_output. * *$*$*.....CODE_ADD_1 - Begin..................................1..*$*$* * * In this section we will define the private methods which can * be implemented to set the properties of the ALV and can be * called in the * PRIVATE SECTION. METHODS: set_pf_status CHANGING co_alv TYPE REF TO cl_salv_table. * METHODS: set_filters CHANGING co_alv TYPE REF TO cl_salv_table. * *$*$*.....CODE_ADD_1 - End....................................1..*$*$* * ENDCLASS. "lcl_report DEFINITION * * START-OF-SELECTION. DATA: lo_report TYPE REF TO lcl_report. * CREATE OBJECT lo_report. * lo_report->get_data( ). * lo_report->generate_output( ). * *----------------------------------------------------------------------* * CLASS lcl_report IMPLEMENTATION *----------------------------------------------------------------------* CLASS lcl_report IMPLEMENTATION. * METHOD get_data. * data selection SELECT vbeln erdat auart kunnr netwr INTO CORRESPONDING FIELDS OF TABLE t_vbak FROM vbak where erdat ge '20090101'. * ENDMETHOD. "get_data * *....................................................................... METHOD generate_output. * New ALV instance * We are calling the static Factory method which will give back * the ALV object reference. * * exception class DATA: lx_msg TYPE REF TO cx_salv_msg. TRY. cl_salv_table=>factory( IMPORTING r_salv_table = o_alv CHANGING t_table = t_vbak ). CATCH cx_salv_msg INTO lx_msg. ENDTRY. * *$*$*.....CODE_ADD_2 - Begin..................................2..*$*$* * * In this area we will call the methods which will set the * different properties to the ALV * * Set default PF status CALL METHOD set_pf_status CHANGING co_alv = o_alv. * * Set Filters CALL METHOD set_filters CHANGING co_alv = o_alv. *$*$*.....CODE_ADD_2 - End....................................2..*$*$* * * * Displaying the ALV * Here we will call the DISPLAY method to get the output on the screen o_alv->display( ). * ENDMETHOD. "generate_output * *$*$*.....CODE_ADD_3 - Begin..................................3..*$*$* * * In this area we will implement the methods which are defined in * the class definition * * METHOD set_pf_status. * DATA: lo_functions TYPE REF TO cl_salv_functions_list. * lo_functions = co_alv->get_functions( ). lo_functions->set_default( abap_true ). * ENDMETHOD. "set_pf_status * METHOD set_filters. * DATA: lo_filters TYPE REF TO cl_salv_filters. * lo_filters = co_alv->get_filters( ). * * Set the filter for the column ERDAT * the filter criteria works exactly same as any * RANGE or SELECT-OPTIONS works. TRY. CALL METHOD lo_filters->add_filter EXPORTING columnname = 'ERDAT' sign = 'I' option = 'EQ' low = '20091214' * high = . CATCH cx_salv_not_found . "#EC NO_HANDLER CATCH cx_salv_data_error . "#EC NO_HANDLER CATCH cx_salv_existing . "#EC NO_HANDLER ENDTRY. * * ENDMETHOD. "set_filters * * * *$*$*.....CODE_ADD_3 - End....................................3..*$*$* ENDCLASS. "lcl_report IMPLEMENTATION
|