11-10-2006 12:54 PM
Hi ,
Can anyone give me the difference between WORK AREA and INTERNAL TABLE with small example showing its uses in reports?
Thx and Regds
bapibobby
11-10-2006 12:56 PM
hi,
Work areas are used with internal tables. For example if you have an internal table defined like this.
data: itab type table of mara.
This internal table can hold many rows of data, right? SO say you need to read this data. Well you will need to LOOP or READ the internal table, since this internal table has no header line(please to put the read data), you need to have a work area to put the data into.
<b>data: wa like line of itab.</b>
Loop at itab <b>into wa</b>.
..
endloop.
Now if you defined the internal table with a header line, there is no reason to have the work area and you can just do the same like this.
data: itab type table of mara <b>with header line</b>.
Loop at itab.
..
endloop.
It is now best practice to use work areas instead of header lines because in ABAP OO, header lines are not allowed.
Check the below link to know more work area n internal tables.
http://help.sap.com/saphelp_47x200/helpdata/en/fc/eb36a1358411d1829f0000e829fbfe/content.htm
<b><i>DECALRATION OF INTERNAL TABLE</i></b>
*&---------------------------------------------------------------------*
*& Report ZTYPES *
*& *
*&---------------------------------------------------------------------*
REPORT ZTYPES .
* Table declaration (old method)
DATA: BEGIN OF tab_ekpo OCCURS 0, "itab with header line
ebeln TYPE ekpo-ebeln,
ebelp TYPE ekpo-ebelp,
END OF tab_ekpo.
*Table declaration (new method) "USE THIS WAY!!!
TYPES: BEGIN OF t_ekpo,
ebeln TYPE ekpo-ebeln,
ebelp TYPE ekpo-ebelp,
END OF t_ekpo.
DATA: it_ekpo TYPE STANDARD TABLE OF t_ekpo INITIAL SIZE 0, "itab
wa_ekpo TYPE t_ekpo. "work area (header line)
* Build internal table and work area from existing internal table
DATA: it_datatab LIKE tab_ekpo OCCURS 0, "old method
wa_datatab LIKE LINE OF tab_ekpo.
* Build internal table and work area from existing internal table,
* adding additional fields
TYPES: BEGIN OF t_repdata.
INCLUDE STRUCTURE tab_ekpo. "could include EKKO table itself!!
TYPES: bukrs TYPE ekpo-werks,
bstyp TYPE ekpo-bukrs.
TYPES: END OF t_repdata.
DATA: it_repdata TYPE STANDARD TABLE OF t_repdata INITIAL SIZE 0, "itab
wa_repdata TYPE t_repdata. "work area (header line)
rgds
Anver