Application Development and Automation Blog Posts
Learn and share on deeper, cross technology development topics such as integration and connectivity, automation, cloud extensibility, developing at scale, and security.
cancel
Showing results for 
Search instead for 
Did you mean: 
retired_member
Product and Topic Expert
Product and Topic Expert
97,703

The most important news for internal tables are the Table expressions that allow the same single line access as the READ TABLE statement. But soon after those were available, the question arised "What about the system fields?".

We all use the well known patterns

READ TABLE ... TRANSPORTING NO FIELDS.

IF sy-subrc = 0.

  ...

ENDIF.

READ TABLE ... TRANSPORTING NO FIELDS.

DATA(idx) = sy-tabix.

...

Since an expression should be free of side effects it especially should not influence any system field. So what about these patterns?

The answer comes in form of two new built-in functions.

Line existence

A new predicate function that returns true if a line exists:

IF line_exists( itab[ ... ] ).

...

ENDIF.

Where itab[ ... ] is a table expression that works here like READ TABLE ... TRANSPORTING NO FIELDS.

(Note that we have already some other predicate functions in ABAP: matches and the contains-variants in the context of string processing).

Line index

A new table function that returns the number of the line in the index used (primary or secondary index):

DATA(idx)= line_index( itab[ ... ] ).

Where itab[ ... ] is a table expression that works here like READ TABLE ... TRANSPORTING NO FIELDS. If no line is found, the value 0 is returned. For Hash-Tables or hashed secondary keys, always the value -1 is returned.

(Note that this is the second table function in ABAP. The other one is lines).

39 Comments
Labels in this area