ABAP SQL Indicator structure

0
19

An ABAP SQL Indicator structure is a sub-structure of indicators for the main structure with the same fields. Each field of indicator structure is of types X or C of length 1. It is defined with the addition WITH INDICATORS of the statement TYPES. Indicator structures are released with ABAP 7.55 (or) S/4HANA 2020.

BAPI Indicator Structure

First, let’s look at BAPI –  BAPI_SALESORDER_CREATEFROMDAT2 use to create sales orders in ECC (or) S/4HANA. We also use the same BAPI to update sales orders. 

The BAPI indicator structures ORDER_HEADER_INX and ORDER_ITEMS_INX have to fill with flags accordingly to the field which needs to update.

Indicator Structure

Similarly, with ABAP release 7.55 you can declare indicator structures along with the statement TYPES. This indicator structure is used in the ABAP SQL statement.

Syntax

Below is the syntax to define the indicator structure

TYPES lwa_sflight TYPE sflight WITH INDICATORS ind.

DATA it_sflight TYPE TABLE OF lwa_sflight WITH EMPTY KEY.

The addition WITH INDICATORS to the TYPES statement will define the indicator structure. The fields of indicator structure “ind” are the same as the fields of the main structure SFLIGHT and each field of length 1.

How to use ABAP SQL Indicator structure?

The main purpose of indicator structure is to be used as an ABAP SQL indicator and used during UPDATE statement.

TYPES lwa_sflight TYPE sflight WITH INDICATORS ind.

DATA it_sflight TYPE TABLE OF lwa_sflight WITH EMPTY KEY.

SELECT carrid, connid, fldate, price
   	FROM sflight
   	WHERE carrid = char`LH` AND
         	connid = numc`0400` AND
         	fldate = @sy-datum
   	INTO CORRESPONDING FIELDS OF TABLE @itab.
IF sy-subrc  = 0.
LOOP AT it_sflight ASSIGNING FIELD-SYMBOL(<wa>).
    <wa>-price *= '0.8'.
    <wa>-ind-price = 'X'.
  ENDLOOP.
  UPDATE sflight FROM TABLE @itab INDICATORS SET STRUCTURE ind.
ENDIF.

In the above example, 

  • Selected only a few fields that we need in the SELECT statement.
  • Ind is an indicator structure with all fields of SLFLIGHT of length 1.
  • The “Price” field is changed for all the records of the internal table
  • Flag the “Price” field in the indicator structure “ind”.

Here comes the interesting part, 

If we use the UPDATE statement without INDICATORS all other fields of the database table SFLIGHT will be initialized since their values are not selected in SELECT and the values are initial in the internal table.

With the addition of INDICATORS SET STRUCTURE ind, only the “Price” field will get updated. All other fields in the database table will not have any impact and remain the same. So basically the INDICATORS structure acts as flags to update the fields, which is similar to the BAPI update.

Conclusion

Congrats!! You have successfully learned about the ABAP SQL Indicator structure. If you liked it ❤️, please share it! Thanks! 🙏

Please feel free to comment and let us know your feedback. Subscribe for more updates.

Stay Connected