What is the difference between internal table and a work area and how do they work? Internal table is a temporary two dimensional memory structure similar to database table. We can store multiple records in the internal table and also using record pointers we can do the activities such as reading, appending, deleting, modifying etc. Whereas work area is a variable declared with the TYPE of an internal table or a database table. It can store only one record at a time. It is like a structure declaration in C. You can refer individual columns in the work area with the names. If you declare an internal table with "WITH HEADER LINE" clause the internal table itself acts as a work area. For example, your ITAB is a work area and ITAB[] is the internal table. If you are familiar with ORACLE PLSQL, work area is similar to %ROW_TYPE and internal is similar to TABLE TYPE. More info on using Internal table with and without header line: When you create an internal table object you can also declare a header line with the same name. You can use the header line as a work area when you process the internal table. The ABAP statements that you use with internal tables have short forms that you can use if your internal table has a header line. These statements automatically assume the header line as an implicit work area. The following table shows the statements that you must use for internal tables without a header line, and the equivalent statements that you can use for internal tables with a header line: Operations without header line
Operations for all Table Types INSERT <wa> INTO TABLE <itab>.
COLLECT <wa> INTO <itab>.
READ TABLE <itab> ... INTO <wa>.
MODIFY TABLE <itab> FROM <wa> ...
MODIFY <itab> FROM <wa> ...WHERE ...
DELETE TABLE <itab> FROM <wa>.
LOOP AT ITAB INTO <wa> ...
Operations for Index Tables APPEND <wa> TO <itab>.
INSERT <wa> INTO <itab> ...
MODIFY <itab> FROM <wa> ...
Using the header line as a work area means that you can use shorter statements; however, they are not necessarily easier to understand, since you cannot immediately recognize the origin and target of the assignment. Furthermore, the fact that the table and its header line have the same name can cause confusion in operations with entire internal tables. To avoid confusion, you should use internal tables with differently-named work areas. The following example shows two programs with the same function. One uses a header line, the other does not. With header line: TYPES: BEGIN OF LINE,
DATA ITAB TYPE HASHED TABLE OF LINE WITH UNIQUE KEY
DO 4 TIMES.
ITAB-COL1 = 2.
ITAB-COL2 = 100.
ITAB-COL1 = 4.
LOOP AT ITAB.
Without header line: TYPES: BEGIN OF LINE,
DATA: ITAB TYPE HASHED TABLE OF LINE WITH UNIQUE KEY COL1, WA LIKE LINE OF ITAB. DO 4 TIMES.
WA-COL1 = 2.
WA-COL2 = 100.
WA-COL1 = 4.
LOOP AT ITAB INTO WA.
The list, in both cases, appears as follows: 1 1 2 100 3 9 The statements in the program that does not use a header line are easier to understand. As a further measure, you could have a further work area just to specify the key of the internal table, but to which no other values from the table are assigned.
Read Also
ABAP Books List
Smart Forms
ABAP Menu:
Return to Index:-
(c) www.gotothings.com All material on this site is Copyright.
|