How to set SELECT-OPTIONS to the ALV with IDA on HANA

0
3862

[adsenseyu2]

Hello everyone, In our previous tutorial we introduced you to the new flavor of ABAP ALV called ALV with Integrated Data Access(IDA). In our previous tutorial we have retrieved the full data, but usually users want to restrict the data retrieved by using select options.In this tutorial, we will learn how to set SELECT-OPTIONS to the ALV with IDA. So lets get started.

To set the select options to the ALV with IDA

  • Create a range table for select-options on the selection screen using the method ADD_RANGES_FOR_NAME of class CL_SALV_RANGE_TAB_COLLECTOR.
  • Use the method GET_COLLECTED_RAGES method of class CL_SALV_RANGE_TAB_COLLECTOR to get the ranges.
  • Pass the above created ranges to the method SET_SELECT_OPTIONS of IDA class CL_SALV_GUI_TABLE_IDA.

1. Create an ABAP Program in Eclipse.Enter Name, Description and click on Next.

New ABAP Programm

 

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.

Selection of Transport Request

3. Copy and paste the below code.

TABLES : SNWD_PD.

*1... Declare SELECT-OPIONS
SELECT-OPTIONS s_prdid FOR SNWD_PD-PRODUCT_ID.

START-OF-SELECTION.
*2... Create object reference ALV with IDA
 DATA(lo_alv_display) = cl_salv_gui_table_ida=>create( iv_table_name = 'SNWD_PD' ).

*3... Build range tables
DATA(lo_range_collector) = NEW cl_salv_range_tab_collector( ).

lo_range_collector->add_ranges_for_name( iv_name = 'PRODUCT_ID' 
                                         it_ranges = s_prdid[] ).
lo_range_collector->get_collected_ranges( 
                    IMPORTING 
                       et_named_ranges = DATA(lt_select_options) ).

*4... Set select options
lo_alv_display->set_select_options( it_ranges = lt_select_options ).

*5... Display ALV
 lo_alv_display->fullscreen( )->display( ).

4. Lets look at what have we written,

  1. Declared the select options for the field PRODUCT_ID.
  2. Create and add the range table for the select options PRODUCT_ID.
  3. Get the ranges of select options into the table LT_SELECT_OPTIONS.
  4. Finally set the select options to the ALV with IDA using SET_SELECT_OPTIONS.

5. Activate and execute the ABAP program/report.

[adsenseyu1][adsenseyu1]

6. Provide values for select options of product id and hit execute button.

Select-Options

7. You should see the output for the selected product ids only like below.

Output

8. You can add as many as select options you want.

You have successfully created an ABAP ALV with IDA using Select Options. Please stay tuned to us for ABAP on HANA and ABAP in Eclipse tutorials.Please feel free to comment and let us know your feedback. You feedback will keep us alive.

Thank you.