Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

work area and internal table

Former Member
0 Likes
1,199

hi friends,

Please let me know when do we use work area and when do we use internal table.

Thanks in advance

Tina Wilson

1 ACCEPTED SOLUTION
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
649

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.

Regards,

Rich Heilman

4 REPLIES 4
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
650

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.

Regards,

Rich Heilman

Read only

Former Member
0 Likes
649

Hi,

When you have only record (assuming select single * from mara int wa_mara where matnr = 'adfasdf') you can use the work area.

When you have multiple records you can use internal table. (ex. select * from mara into t_mara where erdat = sy-datum).

Please let me know if it works.

Thanks,

Naren

Read only

Former Member
0 Likes
649

Work area to pick single record.

Data: wa_eanl type eanl.

Select single * from eanl into wa_eanl.

Internal table to store lot of record.

data: i_eanl type eanl occurs 0 with header line.

Select * from eanl into table i_eanl.

Regards,

Prakash.

Read only

Former Member
0 Likes
649

Hi,

In ABAP Object oriented programming, internal tables with header lines are not allowed. To add , delete or change the records in an internal table, a work area is used. THis work area will have the same structure as the internal table. Technically speaking work area is a line of an internal table.

Check the below link to know more work area n internal tables.

http://help.sap.com/saphelp_47x200/helpdata/en/fc/eb36a1358411d1829f0000e829fbfe/content.htm

Regards,

Vamsi