Сheck internal table ABAP for the presence of a record with LINE_EXISTS ABAP in new ABAP syntax. Checking the existence of a record in an internal table is a common task in ABAP programs. I create simple example how it was in old ABAP syntax and in new syntax ABAP.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
SELECT carrid, connid, fldate, price INTO TABLE @DATA(lt_sflight) FROM sflight WHERE seatsmax_b > 18. " OLD syntax ABAP READ TABLE lt_sflight TRANSPORTING NO FIELDS WITH KEY carrid = 'AA'. IF sy-subrc = 0. BREAK-POINT. ENDIF. " NEW syntax ABAP IF line_exists( lt_sflight[ carrid = 'AA' ] ). BREAK-POINT. ENDIF. |
When we found or not found rows in internal table ABAP with LINE_EXISTS value variable sy-sybrc and sy-tabix don’t change. Not the same like for READ TABLE!

Examples using LINE_EXISTS ABAP
- With one field and NOT, for example, we check line not exists in this internal table ABAP
1 2 3 |
IF NOT line_exists( lt_sflight[ connid = '0017'] ). BREAK-POINT. ENDIF. |
- With two and more fields and you also can create KEY for lt_sflight if it would be better for performance
1 2 3 |
IF line_exists( lt_sflight[ carrid = 'AA' connid = '0017'] ). BREAK-POINT. ENDIF. |
- With concatenate ABAP in condition
1 2 3 4 |
DATA(lv_connid_id) = 17. IF line_exists( lt_sflight[ connid = |00{ lv_connid_id }| ] ). BREAK-POINT. ENDIF. |
- Add lidding zeros in ABAP before using LINE_EXISTS
1 2 3 4 |
DATA(lv_connid) = 17 . IF line_exists( lt_sflight[ connid = |{ CONV s_conn_id( lv_connid ) ALPHA = IN }| ] ). BREAK-POINT. ENDIF. |
- Using in real work for check errors in internal table log ABAP
1 2 3 4 5 |
IF line_exists( lt_res[ type = 'E' ] ). "Show message in SAP CRM lr_msg_service->add_bapi_messages( it_bapi_messages = lt_res iv_show_only_once = abap_true ). "Or show simple MESSAGE.... ENDIF. |
- Check, for example, buttons internal table SAP and etc.
1 2 3 |
IF NOT line_exists( gt_button[ type = 'NAV_FORWARD' ] ). me->add_button( iv_icon = 'NAV_FORWARD' iv_otr_text_alias = '' iv_event = 'navigate' ). ENDIF. |
Performance LINE_EXISTS ABAP
You need to use LINE_EXISTS correct and think about performance. If table too big and you need to use LINE_EXISTS a lot of times will think about KEY for this internal table. For example this code ABAP with using HASHED TABLE with KEY.
1 2 3 4 5 6 7 8 9 10 11 12 |
DATA lt_sflight TYPE HASHED TABLE OF sflight WITH UNIQUE KEY carrid connid. SELECT carrid, connid, fldate, price INTO TABLE @flight_tab FROM sflight. IF line_exists( flight_tab[ carrid = 'AA' connid = '0017' fldate = '20241015' ] ). BREAK-POINT. ENDIF. |
Usage LINE_EXISTS additions
- Using LINE_EXISTS with empty table. If internal table ABAP empty we get result ABAP_FALSE and for example in this code BREAK-POINT will not be executed.
1 2 3 4 |
DATA: lt_sflight TYPE STANDARD TABLE OF sflight. IF line_exists( lt_sflight[ carrid = 'AA' ] ). BREAK-POINT. ENDIF. |
and you not need check table before LINE_EXISTS like this:
1 2 3 4 |
DATA: lt_sflight TYPE STANDARD TABLE OF sflight. IF lt_sflight IS NOT INITIAL AND line_exists( lt_sflight[ carrid = 'AA' ] ). BREAK-POINT. ENDIF. |