ABAP - Keyword Documentation →  ABAP - Programming Language →  Declarations →  Declaration Statements →  Data Types →  TYPES → 
Mail Feedback

TYPES, INDICATORS

Short Reference

Syntax

TYPES dtype TYPE struct WITH INDICATORS ind [{TYPE type}
                                          | {AS BITFIELD}].


Additions:

1. ... TYPE type

2. ... AS BITFIELD

Effect

Derivation of a structured data type with an indicator structure with the name ind. For struct, an existing local or global structured type must be specified. For ind, a name must be specified that follows the naming conventions.

This variant of the statement TYPES defines a structured data type that has the same components as the structured type struct specified behind TYPE, as well as an additional last component named ind as an indicator structure. The last component ind is one of the following:

Hints

Example

The structured type ind_struct has the same components with the same types as struct plus an additional substructure named ind. The substructure ind has the same components col1 to col11 as struct but all of them have type x of length 1.

TYPES:
  BEGIN OF struct,
    col1  TYPE i,
    col2  TYPE i,
    col3  TYPE i,
    col4  TYPE i,
    col5  TYPE i,
    col6  TYPE i,
    col7  TYPE i,
    col8  TYPE i,
    col9  TYPE REF TO i,
    BEGIN OF col10,
      col1 TYPE i,
      col2 TYPE i,
    END OF col10,
    col11 TYPE TABLE OF demo_struc WITH EMPTY KEY,
  END OF struct.

TYPES ind_struct TYPE struct WITH INDICATORS ind.

DATA ind_struct TYPE ind_struct.

cl_demo_output=>display( ind_struct ).

Example

An internal table that has a line structure with an indicator structure is partly filled with today's flight data for a given flight connection from the DDIC database table SFLIGHT. In the internal table, the price is reduced by 80 %. The modified table is used to update the respective date in the database table. While the lines that are to be updated are selected by the content of key fields in the internal table, the column to be updated is indicated by marking the column PRICE of the indicator structure. Without using the INDICATORS addition of the UPDATE statement, all other non-key columns of the database table would be initialized since their values are initial in the internal table.

TYPES wa TYPE sflight WITH INDICATORS ind.

DATA itab TYPE TABLE OF wa WITH EMPTY KEY.

SELECT carrid, connid, fldate, price
       FROM sflight
       WHERE carrid = char`LH` AND
             connid = numc`0400` AND
             fldate = @( cl_demo_date_time=>get_user_date( ) )
       INTO CORRESPONDING FIELDS OF TABLE @itab.

IF sy-subrc  = 0.

  LOOP AT itab ASSIGNING FIELD-SYMBOL(<wa>).
    <wa>-price *= '0.8'.
    <wa>-ind-price = '01'.
  ENDLOOP.

  UPDATE sflight FROM TABLE @itab INDICATORS SET STRUCTURE ind.

ENDIF.

Addition 1  

... TYPE type

Effect

Definition of the data type of each component of an actual indicator structure ind. The same applies to type as to TYPES ... TYPE abap_type and TYPES ... TYPE. Each non-generic local or global data type that is visible at the current position can be specified. The generic built-in ABAP types c, n, p, and x can also be specified and their standard length is used implicitly then,.

Hint

For ABAP SQL indicators, only the types c and x of length 1 are relevant.

Example

The structured type ind_struct has the same components with the same types as struct plus an additional substructure named ind. The substructure ind has the same components col1 to col11 as struct but all of them have type itab that is a table type with line type i.

TYPES:
  BEGIN OF struct,
    col1 TYPE i,
    col2 TYPE i,
    col3 TYPE i,
    col4 TYPE i,
    col5 TYPE i,
    col6 TYPE i,
    col7 TYPE i,
    col8 TYPE i,
    col9 TYPE REF TO i,
    BEGIN OF col10,
      col1 TYPE i,
      col2 TYPE i,
    END OF col10,
    col11 TYPE TABLE OF demo_struc WITH EMPTY KEY,
  END OF struct.

TYPES itab type TABLE OF i WITH EMPTY KEY.
TYPES ind_struct TYPE struct WITH INDICATORS ind TYPE itab.

DATA ind_struct TYPE ind_struct.

cl_demo_output=>display( ind_struct ).

Example

See examples for UPDATE ... FROM ... INDICATORS.

Addition 2  

... AS BITFIELD

Effect

Defines ind as a condensed indicator structure that is a byte field of type x. The length of the byte field is calculated from the number of components n in struct as with ( n + 7 ) DIV 8.

Hints

Example

The structured type ind_struct has the same components with the same types as struct plus an additional component ind of type x with length 2. The first 11 bits of that byte field can serve as indicators for the components col1 to col11 of struct.

TYPES:
  BEGIN OF struct,
    col1  TYPE i,
    col2  TYPE i,
    col3  TYPE i,
    col4  TYPE i,
    col5  TYPE i,
    col6  TYPE i,
    col7  TYPE i,
    col8  TYPE i,
    col9  TYPE REF TO i,
    BEGIN OF col10,
      col1 TYPE i,
      col2 TYPE i,
    END OF col10,
    col11 TYPE TABLE OF demo_struc WITH EMPTY KEY,
  END OF struct.

TYPES ind_struct TYPE struct WITH INDICATORS ind AS BITFIELD.

DATA ind_struct TYPE ind_struct.

cl_demo_output=>display( ind_struct ).

Example

The structure wa_ind has a condensed indicator structure null_ind that is used as a null indicator in a SELECT statement. It has length of 6 and thus consists of 48 bits that cover the 44 fields of database table DEMO_EXPRESSIONS used for declaring wa_ind. The three columns num1, fltp1, and char1 of the result set of the SELECT statement contain the null value because the WHEN conditions of the CASE expressions are false and no ELSE is specified. Since the addition INTO CORRESPONDING is used, the positions of the bits of the null indicator correspond to the positions of the components of the target area that correspond to the columns of the result set. Accordingly, the third, the tenth and the sixteenth bit of the byte field wa_ind-null_ind have the value 1. While its hexadecimal value 204100000000 is not too informative, the GET BIT statement can be used to extract the positions of the columns that contain the null value.

DELETE FROM demo_expressions.
INSERT demo_expressions FROM @( VALUE #( id = 'X' num1 = 1 ) ).

TYPES demo_ind TYPE demo_expressions
  WITH INDICATORS null_ind AS BITFIELD.

DATA wa_ind TYPE demo_ind.

SELECT SINGLE
  FROM demo_expressions
  FIELDS
    CAST( CASE WHEN num1 = 0 THEN 0 END AS INT4 ) AS num1,
    CAST( CASE WHEN num1 = 0 THEN 0 END AS FLTP ) AS fltp1,
    CAST( CASE WHEN num1 = 0 THEN 0 END AS CHAR ) AS char1
  INTO CORRESPONDING FIELDS OF @wa_ind
       INDICATORS NULL BITFIELD null_ind.

DATA binary_ind TYPE string.
DATA null_columns TYPE TABLE OF i WITH EMPTY KEY.
WHILE sy-index <= xstrlen( wa_ind-null_ind ) * 8.
  GET BIT sy-index OF wa_ind-null_ind INTO FINAL(bit).
  binary_ind &&= bit.
  IF bit = 1.
    APPEND sy-index TO null_columns.
  ENDIF.
ENDWHILE.

cl_demo_output=>new(
)->write( wa_ind
)->write( wa_ind-null_ind
)->write( binary_ind
)->write( null_columns
)->display( ).