ABAP – S/4 – If Line_exists

Home / SAP / ABAP Coding / ABAP – S/4 – If Line_exists

Here’s another new one I discovered.  How often you do write a few lines of code to check if something exists?  For example, a common thing I do is look for an entry in a table?  If it’s there, I need to do something, if not, I move on. For example:

read table Lt_test transporting no lines with key key1 = val1 key2 = val2.

if sy-subrc = 0.



Well, in S/4, that has been condensed.

if line_exists( lt_test[key1 = val1 key2 = val2]).



you get to skip the read statement.  Now, if you need the contents, this might not help as much, since you would need to extract that line anyway, but if you are purely looking for the existence, then it’s a lot cleaner.

Thanks for reading,

As always, thanks for reading and don't forget to check out our SAP Service Management Products at my other company JaveLLin Solutions,

One thought on “ABAP – S/4 – If Line_exists

  1. I would like to mention that some, if not all of your posts related to “S/4HANA” ABAP-statements and syntax, actually apply for non-HANA Systems as well.
    From ABAP NW7.4 onwards, you’ll have all of these, even on a SAP ECC System.
    So it actually depends on you ABAP-Kernel version, rather than being on (S/4)HANA …
    Other resources on this topic are summarized in the Blog https://blogs.sap.com/2016/03/02/old-and-new-abap-syntax-overview-sheet/

Leave a Reply

Your email address will not be published. Required fields are marked *