ABAP Keyword Documentation →  ABAP − Reference →  Processing Internal Data →  Internal Tables →  Expressions and Functions for Internal Tables →  Table Functions →  line_index - Index Function → 

Internal Tables, Index Function

The example demonstrates the table function line_index.

Source Code

REPORT.

CLASS demo DEFINITION.
  PUBLIC SECTION.
    CLASS-METHODS: class_constructor,
                   main.
  PRIVATE SECTION.
    CLASS-DATA
      flight_tab
        TYPE STANDARD TABLE OF spfli
        WITH EMPTY KEY
        WITH UNIQUE HASHED KEY id COMPONENTS carrid connid
        WITH NON-UNIQUE SORTED KEY cities COMPONENTS cityfrom cityto.
ENDCLASS.

CLASS demo IMPLEMENTATION.
  METHOD main.
    DATA idx TYPE TABLE OF i.

    idx = VALUE #(
          ( line_index( flight_tab[ carrid = 'UA'
                                    connid = '0941'
                                    ##primkey[id] ] ) )
          ( line_index( flight_tab[ KEY id
                                    carrid = 'UA'
                                    connid = '0941' ] ) )
          ( line_index( flight_tab[ KEY id
                                    carrid = 'xx'
                                    connid = 'yyyy' ] ) )
          ( line_index( flight_tab[ cityfrom = 'FRANKFURT'
                                    cityto   = 'NEW YORK'
                                    ##primkey[cities] ] ) )
          ( line_index( flight_tab[ KEY cities
                                    cityfrom = 'FRANKFURT'
                                    cityto   = 'NEW YORK'  ] ) )
          ( line_index( flight_tab[ KEY cities
                                    cityfrom = 'xxxxxxxx'
                                    cityto   = 'yyyyyyyy'  ] ) ) ).

    cl_demo_output=>display( idx ).
  ENDMETHOD.
  METHOD class_constructor.
    SELECT *
           FROM spfli
           INTO TABLE flight_tab
           ORDER BY carrid connid.
  ENDMETHOD.
ENDCLASS.

START-OF-SELECTION.
  demo=>main( ).

Description

Various row numbers in the same internal table as in used in Example of Specified Rows are read and inserted in an internal table, idx:

  1. The row number of a row in the primary table index found using a free search key.

  2. The number -1, since the secondary hash key id is used.

  3. The number 0, since no row is found (0 overrides -1).

  4. The row number of a row in the primary table index found using a different free search key.

  5. The row number of a row found in the associated secondary table index using the sorted table key cities.

  6. The number 0, since no row is found.