Skip to Content

ABAP Best Pratice for getting data from multiple internal tables

Hello,

I'm looking for the best practice to get data from multiple tables into an internal table. I'll give a simple example in which there is a selection screen where a user can put in a purchase document and wants to get some header data from table EKKO ( fields ebeln and lifnr), and some data at the item level with table EKPO (field werks). I've seen threads before discussing using joins, loops to append this data into a third internal table, but these seem to come with really bad performance and I'm just not sure what the best approach is. If someone could provide an answer with actually code and explaination that would be very helpful.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • Best Answer
    Feb 27, 2017 at 11:09 AM

    Since you can define internal tables as HASHED or SORT, and to have key and secondary key access, there should not be any performance issues.

    https://blogs.sap.com/2014/03/18/first-real-use-of-secondary-indexes-on-an-internal-table/

    (Oh, and if anyone comes along and says "use parallel cursor technique", they're using old techniques that are no longer really necessary.

    Add comment
    10|10000 characters needed characters exceeded

  • Feb 27, 2017 at 06:27 PM

    +1 to Matt. First of all: use the right terminology. EKKO/EKPO are transparent tables. Internal tables exist in memory to hold the data while the program runs. Not sure if the word "table" is causing confusion here, but SAP is notorious for this, so get used to it.

    You've mentioned reading many posts but they seem to be on the different subjects. Reading data from DB (e.g. transparent tables) into internal tables is one thing. Reading/manipulating internal tables in the program is another. In ABAP Help, you'll also find the respective commands described in two different sections.

    As Matt said, general best practice is to get DB do what it does best and to use the appropriate types for the internal tables (you'll do well if you look up Matt's blogs on SCN through his profile). If there is still confusion then you might want to go to the example section in ABAP Editor and get a new ABAP for Beginners book from SAP Press. Of course, great way to learn is also just to try different things in a test system.

    Add comment
    10|10000 characters needed characters exceeded