Understanding ALV in SAP with IDA- 6

This is my final part of 6 part series on SAP HANA which explains the concept of SAP ABAP List Viewer with Integrated Data Access (SALV with IDA).
To provide the gist, 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. 

ALV with IDA example

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.


ALV with IDA example

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:

ALV with IDA example

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.

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

OUTPUT:


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

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'.

Consuming CDS view in ALV IDA

 OUTPUT:


Consuming CDS view in 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.

Setting parameters to ALV IDA

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(
EXPORTING
iv_table_name = 'SFLIGHT'
RECEIVING
ro_alv_gui_table_ida = lo_salv ).

* Instantiate Condition Factory
lo_cond_fact = lo_salv->condition_factory( ).
* Set the parameter value
lo_cond = lo_cond_fact->equals( name = 'CARRID' value = p_carrid ).

*Set the condition for data retrieval
lo_salv->set_select_options(
EXPORTING
* it_ranges =
io_condition = lo_cond ).
* Display ALV
lo_salv->fullscreen( )->display( ).



OUTPUT:

Setting parameters to ALV IDA

Setting parameters to ALV IDA

 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.

set select-options in ALV with IDA

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 method
    EXPORTING
iv_table_name = 'SFLIGHT'
    RECEIVING
ro_alv_gui_table_ida = lo_salv ).

CREATE OBJECT lo_range.     "creating the object

*Set the range
lo_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(
    EXPORTING
it_ranges = lt_ranges ).

* Display ALV
lo_salv->fullscreen( )->display( ).



OUTPUT:


set select-options in ALV with IDA

set select-options in ALV with IDA

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.


Set Title and Zebra pattern for SALV IDA
 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(
   EXPORTING
   iv_table_name = 'SFLIGHT'
* io_gui_container =
* io_calc_field_handler =
   RECEIVING
ro_alv_gui_table_ida = lo_salv
).

lo_salv->display_options( )->set_title( iv_title = 'Below is the flight information' ).   "Enable title to the ALV
lo_salv->display_options( )->enable_alternating_row_pattern( ).    "Enable Zebra pattern in ALV
lo_salv->fullscreen( )->display( ).
*CATCH cx_salv_ida_contract_violation.


OUTPUT:
Set Title and Zebra pattern for SALV 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.

To change the header text for fields in ALV IDA

 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(
EXPORTING
iv_table_name = 'SFLIGHT'
* io_gui_container =
* io_calc_field_handler =
RECEIVING
ro_alv_gui_table_ida = lo_salv
).

TRY.
lo_salv->field_catalog( )->set_field_header_texts( "to change the header text of the field
EXPORTING
iv_field_name = 'CARRID' "field name
iv_header_text = 'Airline Code number' "field header text
).

lo_salv->field_catalog( )->set_field_header_texts(
EXPORTING
iv_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:

To change the header text for fields in ALV IDA


Some important cheat codes to work on HANA smoothly.
Shortcut keys in SAP HANA

I hope the illustrations above help in better understanding the concept of 'SALV IDA'.

Post a Comment

0 Comments