Monday, 6 January 2014

Internal Tables in SAP ABAP

Internal Tables in SAP ABAP

Dealing with internal tables is one of the most important parts of working with ABAP. In-ternal tables have been hinted at briefly before, but not examined in any great depth. This chapter will do precisely that. If one is working in ABAP in any way at all, it is crucial to un-derstand internal tables, as almost every program will use them. You have to understand both the old method of using header lines, and the new method using separate work ar-eas. SAP has existed a long time, and while practices change, one will still often find old methods being used. When one is creating new programs, though, the newer method is always to be used.
Internal tables only ever exist when a program is running, so when the code is written, the internal table must be structured in such a way that the program can make use of it. You will find that internal tables operate in the same way as structures. The main difference being that Structures only have one line, while an internal table can have as many as re-quired.
Internal tables are used for many purposes in ABAP. They can be used to hold results of calculations to then use later in the program, hold records and data so that this can be accessed quickly rather than having to access this data from database tables, and a great number of other things. They are hugely versatile, as they can be defined using any num-ber of other defined structures, allowing, for example, many tables to be grouped to-gether and then placed into one internal table.
The basic form of these consists of a table body, which is all of the records within the ta-ble, and a header record in the case of the older-style internal table. In the case of the newer style of internal table, the header record is absent and replaced by a separate work area. The header line or work area is used when you read a record from the internal table, providing a place for this ‘current’ record to be placed which can then be accessed di-rectly. The header line or work area is also used and populated if you need to add a new record to the table, which is then transferred from the structure to the table body itself
Previously, the TABLES statement has been used to include a table which has been created in the ABAP dictionary in a program. Internal tables, on the other hand, have to be de-clared themselves. When this is done, you must also declare whether a header record or separate work area will be used.
When creating new programs with internal tables it is best practice to use separate work areas. Using a header record has a number of restrictions, for example, you are not able to create multi-dimensional tables. We will not be cover multi-dimensional tables at length here, but if you plan to go further with ABAP, they will become important.

There are some restrictions on the records which can be held in internal tables. The archi-tecture of an SAP system limits the size of internal tables to around 2GB. It is also impor-tant to bear in mind how powerful one’s SAP system is (the hardware and operating sys-tem). It is generally best practice to keep internal tables as small as possible, so as to avoid the system running slowly as it struggles to process enormous amounts of data.

No comments:

Post a Comment