ALV with IDA(ALVonHANA)-12

alv-ida

Calculated fields in ALV

 

 

Imagine we want to add few columns in the ALV those which are not part of the table fields. In such a case ALV with IDA provides IF_SALV_IDA_CALC_FIELD_HANDLER can be used. In this demo will add two more calculated columns to the ALV.

The class CL_SALV_GUI_TABLE_IDA – CREATE method can import the reference of the class that implements the interface IF_SALV_IDA_CALC_FIELD_HANDLER.

1

The interface IF_SALV_IDA_CALC_FIELD_HANDLER provides few methods that helps to add columns & calculate the value for each row of these columns.

Method GET_CALC_FIELD_STRUCTURE can be used to pass the field name to be used as calculated fields.

Method GET_REQUESTED_FIELDS can be used to decide which all column names needed to calculate the values of the calculated columns.

Method CALCULATE_LINE can be used to calculate the value of the calculated columns for each row.

2


Create a class and implement the interface.

3

In the TYPES section create a type.

2016-09-23_10-30-14

Add the fields. Here we added two fields to be used as calculated fields.

5

Create an attribute( structure) by referring to the types.

6

Now we have to implement the methods.

7

In the method  GET_CALC_FIELD_STRUCTURE  just use the structure so that it enables which all additional fields are going to be used.

8

In the method GET_REQUESTED_FIELDS , just inset all those fields which are going to be used to calculate the value of the additional calculated fields.

9

In the method CALCULATE_LINE which is going to be called for each row in the alv, calculate the value of the additional fields. Other methods of the class just activate.

10

Create a program and use the above class.

Code:


DATAlr_salv TYPE REF TO if_salv_gui_table_ida,
             lo_calc_fld TYPE REF TO zcl_flight_calc_field.
CREATE OBJECT lo_calc_fld.
cl_salv_gui_table_ida=>create(
  EXPORTING
    iv_table_name       =  ‘SFLIGHT’
    io_calc_field_handler lo_calc_fld
  RECEIVING
    ro_alv_gui_table_ida lr_salv ).

  DATA(lr_fcatlr_salv->field_catalog).
* Prepare the field catalog for two calculated fields
  lr_fcat->set_field_header_texts(
    EXPORTING
      iv_field_name   =  ‘FLIGHT_NAME’
      iv_header_text  ‘Flight Name’
      iv_tooltip_text ‘Name of the flight’ ).

    lr_fcat->set_field_header_texts(
    EXPORTING
      iv_field_name   =  ‘FREE_SEATS’
      iv_header_text  ‘Free Seats’
      iv_tooltip_text ‘Available Seats’ ).

* Display ALV
lr_salv->fullscreen)->display).


11

Output:

12


 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s