Nov 16
ABAP Tricks

ABAP Tricks: Read Table With No Structure

Back several months ago while working on a client’s custom SAP solution to fix bugs and make additions, I came across the need to operate on a table with no actual structure. Take for example the following data declaration:

DATA: lt_array TYPE TABLE OF vbeln,
      lv_vbeln TYPE vbeln.

So you have an internal table of order numbers, right? How would you easily, let’s say, check that table for the existence of a particular order number?

If it’s a table type of a structure, it’s easy – Just loop into the structure and access its fields by putting a dash and the field name. However, because this is table of a raw data element, that won’t fly. And neither will something like this:

READ TABLE lt_array WITH KEY vbeln = '1000020014' TRANSPORTING NO FIELDS.

So, what do we do? How do we simply get the meat and potatoes of the table since that’s all we have? Well, after a lot of searching around on both the internet and SAP F1 help, I finally came across this hidden gem:

Pseudo Component TABLE_LINE with Internal Tables

In internal tables it is possible to address the complete table LINE in a key specification by using the pseudo component TABLE_LINE This is useful especially for tables whose LINE type has no structure.

The correct way to get at your table’s data using the same example above is:

READ TABLE lt_array WITH KEY table_line = '1000020014' TRANSPORTING NO FIELDS.

Pretty nifty, right? You can use this trick with pretty much any internal table operation. Reads, loops, etcetera. It was pretty astounding to me how simple of a solution it turned out to be, but it doesn’t seem to be that well known. Leave a comment below if you found this useful, know more tricks for it, or if you know of any other hidden pseudo components out there!

Sean Cloherty

About The Author

Sean is an application developer and solutions architect. Coming from a background as a web designer/developer and then jumping into SAP development, his specialty is merging the back end power of SAP with sleek and intuitive front end user experiences.

4 Comments

  1. Avatar
    Rafael
    January 19, 2017 at 6:35 am · Reply

    Great post! Very helpful!

    Thank you very much.

  2. Avatar
    wachbaik
    July 24, 2017 at 4:09 am · Reply

    Great Thanks,
    but I’m wondering how to loop on that table and read from another one with that vbeln.
    Example.

    Loop at lt_array.
    Read table xvbap assigning WITH key vbeln = lt_array-vbeln.
    write : -posnr .
    endloop.

    But when i do this I have an error :
    The data object has no structure and therefore no component called

  3. Avatar
    Larochka
    December 17, 2017 at 11:48 pm · Reply

    Nice! Thanks Sean 🙂

  4. Avatar
    Binh
    March 5, 2019 at 2:39 am · Reply

    It great ! Thanks !

Leave a reply

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