You are on page 1of 7

we can declare internal table with header line and without header line.

internal table with header line. data: begin of itab occurs 0, num type i, name(23), ........, ........, end of itab. internal table without header line. types: begin of itab, num type i, name(23), ........, ........, end of itab. data: itab1 type itab occurs 0. ===================================================== Internal table is declared by many ways: (A) Data : BEGIN OF IT_TAB occurs 10, RNO(4) TYPE N, SNAM(45) TYPE C, END OF IT_TAB. (B) TYPES : BEGIN OF tT_TAB, RNO(4) TYPE N, SNAM(45) TYPE C, END OF tT_TAB. DATA : tT_TAB TYPE STANDARD TBLE OF tT_TAB with header line. (C) TYPES : BEGIN OF tT_TAB, RNO(4) TYPE N, SNAM(45) TYPE C, END OF tT_TAB. DATA : iT_TAB TYPE STANDARD OF tT_TAB.

(D)DATA : BEGIN OF IT_TAB, RNO(4) TYPE N, SNAM(45) TYPE C, END oF IT_TAB. DATA : wa_TAB LIKE LINE OF IT_TAB, wa_TAB TYPE OF IT_TAB 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 with header line Operations for all Table Types INSERT <wa> INTO TABLE <itab>. INSERT TABLE ITAB. COLLECT <wa> INTO <itab>. COLLECT <itab>. READ TABLE <itab> ... INTO <wa>. READ TABLE <itab> ... MODIFY TABLE <itab> FROM <wa> ... MODIFY TABLE <itab> ... MODIFY <itab> FROM <wa> ...WHERE ... MODIFY <itab> ... WHERE ... DELETE TABLE <itab> FROM <wa>. DELETE TABLE <itab>. LOOP AT ITAB INTO <wa> ... LOOP AT ITAB ... Operations for Index Tables APPEND <wa> TO <itab>. APPEND <itab>. INSERT <wa> INTO <itab> ... INSERT <itab> ... MODIFY <itab> FROM <wa> ... MODIFY <itab> ... 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, COL1 TYPE I, COL2 TYPE I, END OF LINE. DATA ITAB TYPE HASHED TABLE OF LINE WITH UNIQUE KEY COL1 WITH HEADER LINE. DO 4 TIMES. ITAB-COL1 = SY-INDEX. ITAB-COL2 = SY-INDEX ** 2. INSERT TABLE ITAB. ENDDO. ITAB-COL1 = 2. READ TABLE ITAB FROM ITAB. ITAB-COL2 = 100. MODIFY TABLE ITAB. ITAB-COL1 = 4. DELETE TABLE ITAB. LOOP AT ITAB. WRITE: / ITAB-COL1, ITAB-COL2. ENDLOOP. Without header line: TYPES: BEGIN OF LINE, COL1 TYPE I, COL2 TYPE I, END OF LINE. DATA: ITAB TYPE HASHED TABLE OF LINE WITH UNIQUE KEY COL1, WA LIKE LINE OF ITAB.

DO 4 TIMES. WA-COL1 = SY-INDEX. WA-COL2 = SY-INDEX ** 2. INSERT WA INTO TABLE ITAB. ENDDO. WA-COL1 = 2. READ TABLE ITAB FROM WA INTO WA. WA-COL2 = 100. MODIFY TABLE ITAB FROM WA. WA-COL1 = 4. DELETE TABLE ITAB FROM WA. LOOP AT ITAB INTO WA. WRITE: / WA-COL1, WA-COL2. ENDLOOP. The list, in both cases, appears as follows: 11 2 100 39 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.

data: begin of makttab, matnr like makt-matnr, spras like makt-spras, end of makttab.

data itab4 like makttab occurs 0 .

data: wa like line of itab4.

select matnr spras from makt into table itab4.

Loop at itab4 into wa. Write:/ wa-matnr , wa-spras. End of itab.

When we create work area from internal table always use like line of. U can also use given below sode.

data: begin of makttab, matnr like makt-matnr, spras like makt-spras, end of makttab.

data itab4 like makttab occurs 0 with header line.

select matnr spras from makt into table itab4.

Loop at itab4. Write:/ itab4-matnr , itab4-spras. End of itab.

You might also like