2

I am using the line_index function and would like to search for two values, not only for carrid but also for connid. Is it possible? If so, in what way?

Because right now, this works:

lv_index = line_index( lt[ carrid = 'LH' ] ).

But after adding the code [ connid = '2407' ] like this:

lv_index = line_index( lt[ carrid = 'LH' ][ connid = '2407' ] ).

I get a syntax error:

LT[ ] is not an internal table

Suncatcher
  • 10,355
  • 10
  • 52
  • 90
Abapito
  • 73
  • 7

2 Answers2

5

All fields (conditions) just one after the other inside one bracket:

lv_index = line_index( lt[ carrid = 'LH'
                           connid = '2407' ] ).
József Szikszai
  • 4,791
  • 3
  • 14
  • 24
0

I'd like to comment about the chaining of Table Expressions.

So the answer corresponding to the OP example is that a single Table Expression must be used (itab[...]) with as many components as needed, and not a chain of table expressions as was done (itab[...][...]).

lt[ carrid = 'LH' ][ connid = '2407' ] can never be valid (because connid = '2407' would imply that each line of LT is itself an internal table but carrid = 'LH' is contradictory as it means that each line of LT is a structure).

But other syntaxes of chained table expressions can be valid, like e.g. (provided that the internal tables are defined adequately)

itab[ 1 ][ comp1 = 'A' ]
itab[ comp1 = 'A' ][ 1 ]
itab[ comp1 = 'A' ]-itabx[ compx = 42 ]

Here is an example that you can play with:

TYPES: BEGIN OF ty_structure,
         connid TYPE c LENGTH 4,
       END OF ty_structure,
       ty_table TYPE STANDARD TABLE OF ty_structure WITH EMPTY KEY,
       BEGIN OF ty_structure_2,
         carrid TYPE c LENGTH 2,
         table  TYPE ty_table,
       END OF ty_structure_2,
       ty_table_2 TYPE STANDARD TABLE OF ty_structure_2 WITH EMPTY KEY,
       ty_table_3 TYPE STANDARD TABLE OF ty_table_2 WITH EMPTY KEY.

DATA(lt) = VALUE ty_table_3( ( VALUE #( ( carrid = 'LH' table = VALUE #( ( connid = '2407' ) ) ) ) ) ).

DATA(structure) = lt[ 1 ][ carrid = 'LH' ]-table[ connid = '2407' ].
Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
  • they can be chained like you figured, but not like OP `lt[ carrid = 'LH' ][ connid = '2407' ]`, this way it is like chaining structures of the same table, which makes no sense – Suncatcher Jul 14 '22 at 10:15
  • @Suncatcher Thanks. Answer rewritten to clarify (I hope). – Sandra Rossi Jul 14 '22 at 11:42