What’s New In ABAP – Series 01, Episode 05 – Internal Table Functions.

Nagendra Babu
Authored by

Internal Table Functions:

In the last episode 04 we have talked about table expressions to avoid ‘READ’ statements. If you observe that we were not doing any sy-subrc check, since they are not allowed with table expressions. We have line exists, line index functions which are pretty handy to avoid read statements.

What if there is a situation where you need to find out the if a line is present in itab or if you want to get know the index of the present line in itab?. If you go back to old syntax we can do as follows.

 

next episode Strings  one me! or series home page.

1. To find existence of line ( prior to ABAP 7.40 )

READ TABLE .... TRANSPORTING NO FIELDS.
IF sy-subrc EQ 0.
..
ENDIF.

2. To find index of the existence of line ( prior to ABAP 7.40 )

READ TABLE .... TRANSPORTING NO FIELDS.
IF sy-subrc EQ 0.
DATA(lv_index) = sy-tabix.
ENDIF.

As you can see ‘sy-subrc’ check is important here. So ABAP 7.40 + come up with internal table functions to avoid sy-subrc check while using internal table expressions.

1. Predicate Function:

The new predicate function ‘line_exists( table expression )’ returns true if a line exist that you are looking for. Here the table expression is READ statement with TRANSPORTING NO FIELDS.

To find existence of line ( with ABAP 7.40 )

IF line_exists( itab[ ... ] ).
...
ENDIF.

There are some other predicate function in strings too we can see in this episode strings on me!

2. Line Index

This is a new table function which returns the line number of the existing line. If no line found the return value will be ‘0’ and for hash tables ‘-1’ is returned.

To find index of the existence of line ( with ABAP 7.40 )

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

next episode Strings  one me! or series home page.