Understanding ALV in SAP with IDA

Richa Solanki
9 min readJul 4, 2020

--

At a high level, ALV IDA helps tables that contain bulk of data to be displayed on the UI with some GUI container.

Prerequisite: One should have a fundamental knowledge of ‘SAP ABAP’.

Let’s dive deep to understand the powerful tool called ALV IDA.

From this blog, you’ll learn:

1. What is ALV in SAP with IDA?
2. Creating a simple ALV with IDA
3. Creating ALV with IDA for displaying ’N’ rows
4. How to consume CDS view in ALV with IDA?
5. How to set parameters to ALV in SAP with IDA?
6. How to set select-options to the ALV in SAP with IDA?
7. Set Title and Zebra pattern for ALV in SAP with IDA
8. Set field Catalog for SALV IDA fields.
9. Shortcut keys

So let’s begin.

What is ALV in SAP with IDA?

The classical ALV (ABAP List Viewer) which we studied in SAP ABAP has more functionalities in the application layer. We write select queries to fetch the data from the database to the application layer. All the filtering, calculations and aggregations take place in the application layer, and finally, the data is stored in the internal table to be displayed as an output in the GUI container. Since the bulk of data is transferred to the application layer making it a slow process, ALV with IDA came into the picture.

In SALV with IDA (Integrated Data Access), once the aggregation, filtering, the grouping is done in the HANA database, only the resulted select query is been transferred to the application layer. This reduces the load on the application layer.

To get started with ALV with IDA, we need to go through the class’CL_SALV_GUI_TABLE_IDA’.

This class has 3 static methods namely:

  1. CREATE: Create ALV with Integrated Data Access (IDA)
  2. CREATE_FOR_CDS_VIEW: Create ALV with IDA for Core Data Services (CDS)
  3. DB_CAPABILITIES: Capabilities supported by current DB.

Further, the interface ‘IF_SALV_GUI_TABLE_IDA’ has the following instance methods that we use for various purposes.

  1. SET_SELECT_OPTIONS: Set selections for database access.
  2. FIELD_CATALOG: Display attributes of table fields.
  3. FULLSCREEN: Activate fullscreen mode.
  4. DISPLAY_OPTIONS: Handling of display options
  5. TOOLBAR: Change ALV Toolbar
  6. CONDITION_FACTORY: Service for creation of complex conditions
  7. SET_MAXIMUM_NUMBER_OF_ROWS: Restrict the number of rows selected from DB.

To create a simple ALV with IDA

Let’s create a simple ALV with IDA which will display the records of the ‘VBAK’ table (Sales Document table).

Navigate to the ABAP perspective and create an ABAP Program by providing Name and Description.

Now click on the Next button and select the appropriate transport request. Here I have fetched the data from the VBAK table without writing a select query.

NOTE: fullscreen( ) method has a parameter called RO_FULLSCREEN whose associated type is IF_SALV_GUI_FULLSCREEN_IDA. There are 3 instance methods inside this interface namely DISPLAY( ), SET_PF_STATUS( ), EXIT( ).

NOTE: Hit ctrl+space to get the list of methods, classes, and hit shift+enter to select the option.

In the above code snippet, lo_alv is the object of interface IF_SALV_GUI_TABLE_IDA.

OUTPUT:

NOTE: ALV with IDA can be created from the ABAP perspective on the HANA studio or from the SAP GUI system.

To create an ALV with IDA by restricting the maximum number of rows

In ABAP, we have the feature in the select query called ‘UPTO N ROWS’, which fetches the n rows from the database. Similarly, we will create an ALV with IDA which will be having the restriction on the number of rows. As we have mentioned method SET_MAXIMUM_NUMBER_OF_ROWS earlier in our interface, we will be using the same in our below code.

Here I am fetching the data from the VBAK table which will have the maximum rows as 5.

OUTPUT:

How to consume CDS view in ALV IDA?

We will be displaying the CDS view (ZRDS_CDS_JOIN) which we created earlier in the SALV IDA container. Use the method ‘CREATE_FOR_CDS_VIEW’.

OUTPUT:

How to set parameters to ALV IDA?

To start with the parameters, you should get familiar with the interface ‘IF_SALV_IDA_CONDITION_FACTORY’. This is an interface meant for conditions.

There are some instance methods in this class.

  1. EQUALS
  2. NOT_EQUALS
  3. LESS_THAN
  4. LESS_OR_EQUAL
  5. GREATER_THAN
  6. GREATER_OR_EQUAL
  7. BETWEEN
  8. NOT_BETWEEN
  9. IS_NULL
  10. IS_NOT_NULL

Let’s get started by fetching ‘SFLIGHT’ data based on some parameter.

Below are the steps which you must follow to retrieve data.

  1. Declare the parameter for a particular field.
  2. Instantiate condition factory.
  3. Set the parameter value.
  4. Set the conditions for data retrieval.

Here I have used a parameter for the field ‘carrid’ to fetch the data from ‘SFLIGHT’ table.

LOGIC:

*& — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — -**& Report zrds_alv_ida_parameter*& — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — -**&*& — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — -*REPORT zrds_alv_ida_parameter.PARAMETERS: p_carrid TYPE s_carr_id.DATA: lo_salv TYPE REF TO if_salv_gui_table_ida,lo_cond_fact TYPE REF TO if_salv_ida_condition_factory,lo_cond TYPE REF TO if_salv_ida_condition.cl_salv_gui_table_ida=>create(EXPORTINGiv_table_name = ‘SFLIGHT’RECEIVINGro_alv_gui_table_ida = lo_salv ).* Instantiate Condition Factorylo_cond_fact = lo_salv->condition_factory( ).* Set the parameter valuelo_cond = lo_cond_fact->equals( name = ‘CARRID’ value = p_carrid ).*Set the condition for data retrievallo_salv->set_select_options(EXPORTING* it_ranges =io_condition = lo_cond ).* Display ALVlo_salv->fullscreen( )->display( ).

OUTPUT:

How to set select-options in ALV with IDA?

To start with select-options, you should get familiar with the class ‘CL_SALV_RANGE_TAB_COLLECTOR’. This is the class for collecting range tables for multiple fields.

There are 2 instance methods in this class.

  1. ADD_RANGES_FOR_NAME
  2. GET_COLLECTED_RANGES

Let’s get started by fetching ‘SFLIGHT’ data based on some select-options.

Below are the steps which you must follow to retrieve data.

  1. Declare the select-options for a particular field.
  2. Create and add a range table for the particular select-option.
  3. Get the ranges of the select-options into one table.
  4. Set the select options to the ALV with IDA.

Here I have used select-options for the field ‘carrid’ to fetch the data from ‘SFLIGHT’ table.

LOGIC:

*& — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — -**& Report zrds_alv_select_options*& — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — -**&*& — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — -*REPORT zrds_alv_select_options.DATA: lv_carrid TYPE s_carr_id.SELECT-OPTIONS: s_carrid FOR lv_carrid.DATA: lo_salv TYPE REF TO if_salv_gui_table_ida,lo_range TYPE REF TO cl_salv_range_tab_collector.cl_salv_gui_table_ida=>create( “static methodEXPORTINGiv_table_name = ‘SFLIGHT’RECEIVINGro_alv_gui_table_ida = lo_salv ).CREATE OBJECT lo_range. “creating the object*Set the rangelo_range->add_ranges_for_name( iv_name = ‘CARRID’ it_ranges = s_carrid[] ).lo_range->get_collected_ranges( IMPORTING et_named_ranges = DATA(lt_ranges) ).lo_salv->set_select_options(EXPORTINGit_ranges = lt_ranges ).* Display ALVlo_salv->fullscreen( )->display( ).

OUTPUT:

Set Title and Zebra pattern for SALV IDA

As we have listed above, interface ‘IF_SALV_GUI_TABLE_IDA’ has an instance method ‘DISPLAY_OPTIONS’, that can be used to set ALV title and zebra pattern.

The method DISPLAY_OPTIONS returns an object of type IF_SALV_GUI_TABLE_DISPLAY_OPT which has few methods.

  1. SET_TITLE
  2. ENABLE_ALTERNATING_ROW_PATTERN
  3. ENABLE_DOUBLE_CLICK
  4. SET_FOCUS
  5. SET_EMPTY_TABLE _TEXT

Below is the code snippet for the ALV title and row pattern.

LOGIC:

*& — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — -**& Report zrds_alv_ida_feature*& — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — -**&*& — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — -*REPORT zrds_alv_ida_feature.data: lo_salv TYPE REF TO IF_SALV_GUI_TABLE_IDA.cl_salv_gui_table_ida=>create(EXPORTINGiv_table_name = ‘SFLIGHT’* io_gui_container =* io_calc_field_handler =RECEIVINGro_alv_gui_table_ida = lo_salv).lo_salv->display_options( )->set_title( iv_title = ‘Below is the flight information’ ). “Enable title to the ALVlo_salv->display_options( )->enable_alternating_row_pattern( ). “Enable Zebra pattern in ALVlo_salv->fullscreen( )->display( ).*CATCH cx_salv_ida_contract_violation.

OUTPUT:

How to change the header text for fields in ALV IDA?

To start with the field catalog, you should get familiar with the interface ‘IF_SALV_GUI_TABLE_IDA’. This interface has an instance method ‘FIELD_CATALOG( )’ . The returning parameter of this method is of type ‘IF_SALV_GUI_FIELD_CATALOG_IDA’. This interface has some instance methods which are as follows:

  1. SET_FIELD_HEADER_TEXTS
  2. DISABLE_SORT
  3. DISABLE_AGGREGATION
  4. DISABLE_FILTER
  5. DISABLE_OPTIONS

Let’s get started by changing the header fields of ‘SFLIGHT’ table.

LOGIC:

*& — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — -**& Report zrds_field_catalog_1*& — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — -**&*& — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — -*REPORT zrds_field_catalog_1.DATA: lo_salv TYPE REF TO if_salv_gui_table_ida.cl_salv_gui_table_ida=>create(EXPORTINGiv_table_name = ‘SFLIGHT’* io_gui_container =* io_calc_field_handler =RECEIVINGro_alv_gui_table_ida = lo_salv).TRY.lo_salv->field_catalog( )->set_field_header_texts( “to change the header text of the fieldEXPORTINGiv_field_name = ‘CARRID’ “field nameiv_header_text = ‘Airline Code number’ “field header text).lo_salv->field_catalog( )->set_field_header_texts(EXPORTINGiv_field_name = ‘FLDATE’iv_header_text = ‘DATE OF FLIGHT’* iv_tooltip_text =* iv_tooltip_text_long =).CATCH cx_salv_ida_unknown_name.ENDTRY.lo_salv->fullscreen( )->display( ).

OUTPUT:

Some important cheat codes to work on HANA smoothly.

I hope the illustrations above on ALV in SAP with IDA help in better understanding.

--

--