Hello everyone, in our previous tutorial we introduced you to the new flavor of ABAP ALV called ALV with Integrated Data Access(IDA).
In this tutorial we will learn how to modify default field catalog of ABAP ALV with IDA on HANA.
To modify the field catalog of ALV with IDA
- Get the reference object for the field catalog by calling the method FIELD_CATALOG( ) in interface IF_SALV_GUI_TABLE_IDA.
- Use the method GET_ALL_FIELDS( ) to get columns of ALV.Modify the field catalog as per your requirement.
- Use the method SET_AVAILABLE_FIELDS( ) to set back the field catalog of ALV
1. Create an ABAP Program in Eclipse.Enter Name, Description and click on Next.
2. In the Selection of Transport Request window, choose the transport request. As we are saving the program in $TMP package in our case no transport request is required.Click on Finish.
3. Copy and paste the below code.
START-OF-SELECTION. *1... Create object reference ALV with IDA DATA(lo_alv_display) = cl_salv_gui_table_ida=>create( iv_table_name = 'SNWD_PD' ). *2... Get Field Catalog reference DATA(lo_fldcatlog) = lo_alv_display->field_catalog( ). *3... Get all columns of ALV lo_fldcatlog->get_all_fields( IMPORTING ets_field_names = DATA(lts_field_names) ). *4... Remove unwanted columns DATA: lr_fldnames TYPE RANGE OF fieldname, ls_fldname LIKE LINE OF lr_fldnames. ls_fldname-sign = 'I'. ls_fldname-option = 'EQ'. ls_fldname-low = 'CATEGORY'. APPEND ls_fldname TO lr_fldnames. DELETE lts_field_names WHERE table_line IN lr_fldnames. lo_fldcatlog->set_available_fields( lts_field_names ). *3... Display ALV lo_alv_display->fullscreen( )->display( ).
4. Lets look at what have we written,
- Create a reference object of ALV by passing the table name SNWD_PD.
- Get the field catalog reference object by calling the method FIELD_CATALOG( ).
- Get all the columns of ALV by calling the method GET_ALL_FIELDS( ).
- By default all columns available in the table/view will be available in the ALV field catalog. So either remove the columns which are not required (or) clear the default field catalog and add the columns which are required.
- Finally set the field catalog back to the ALV by calling the method SET_AVAILABLE_FIELDS( ).
5. Activate and execute the ABAP program/report.
6. Below is the output before removing the column Category.
7. Below is the output after removing the column category.
Please feel free to comment and let us know your feedback.Thank you.
SAPLearners.com is now on Telegram. Click here to join our channel and stay updated with the latest tutorials and updates.