Application Development 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: 

difference between internal table and work area

Former Member
0 Kudos

Hello all,

Please give me as many as possible no of differences between work area and internal table?

regards,

Harish

1 ACCEPTED SOLUTION

Former Member

HI,

INTERNAL Table and it's background:

===================================

Internal table acts as a container which is used to store the record sets. That is used to store the data fetched from the database table.

So due to performance reason every time access to database would not be so good and decrease the performance. So you just select the data from the database and store it in the intermediate table. This table is called INTERNAL TABLE. So it's an replica of the database. The design foes like this,

PRESENTATION SERVER <> APPLICATION SERVER <>

DATABASE SERVER.

So everytime gain accessing to database results in high resource usage and bad permformance.

So always play around with internal tables. So obviously the whenever you access the data in the INTERNAL TABLE, the application server will be used.

WORK AREA:

==========

When ever you loop at the internal table, the current record should be stored in a temporary work place. That is called WORK AREA.

LOOP AT ITAB INTO WORKAREA.

ENDLOOP.

ITAB :An internal table

WORKAREA:An instance of internal table

Go thru the link below

reward if it helps..

regards,

Omkar.

Message was edited by:

Omkaram Yanamala

14 REPLIES 14

Former Member
0 Kudos

WORKAREA is a structure that can hold only one record at a time. It is a collection of fields. We use workarea as we cannot directly read from a table. In order to interact with a table we need workarea. When a Select Statement is executed on a table then the first record is read and put into the header of the table and from there put into the header or the workarea(of the same structure as that of the table)of the internal table and then transferred top the body of the internal table or directly displayed from the workarea.

Each row in a table is a record and each column is a field.

While adding or retrieving records to / from internal table we have to keep the record temporarily.

The area where this record is kept is called as work area for the internal table. The area must have the same structure as that of internal table. An internal table consists of a body and an optional header line.

Header line is a implicit work area for the internal table. It depends on how the internal table is declared that the itab will have the header line or not.

e.g.

data: begin of itab occurs 10,

ab type c,

cd type i,

end of itab. " this table will have the header line.

data: wa_itab like itab. " explicit work area for itab

data: itab1 like itab occurs 10. " table is without header line.

Thanks,

<b>Reward If Helpful.</b>

Former Member
0 Kudos

Hi,

Internal tables are used for storing records which are obtained as a result when we use select statement on database. internal tables are run time entities and doesn't occupy any memory. they are dynamic.

internal tables are of types.

1. internal tables with header line. [header and body]

2. internal tables with out header line. [only body]

Workarea is the concept which is mainly useful when working with internal tables with out header line.

at any point of time we can access only one record through header of a internal table. every thing should be done [inserting,modifying, reading ] through header only.

ex: data: itab like standard table of mara with header line.

for internal tables with out header line we will create a work area [explicit header] as type of table for storing data into internal table.

ex: data: itab like mara,

wa like mara.

Regards,

Priyanka.

Former Member
0 Kudos

Hi,

Internal table can have more than one entry.

but work area can hold at a time only one entry.

Thanks,CSR.

Former Member

sample program

TYPES : BEGIN OF ty_test,

code TYPE i,

name(10) TYPE c,

amount TYPE p DECIMALS 2,

END OF ty_test.

DATA : it_test TYPE STANDARD TABLE OF ty_test WITH HEADER LINE INITIAL SIZE 10.

DATA : wa TYPE ty_test,

chk1 TYPE c,

fldname(30), fldval(50).

*set pf-status 'PF01'.

*set titlebar 'PF01'.

*

INITIALIZATION.

it_test-code = 300.

it_test-name = 'Ramesh'.

it_test-amount = 5500.

APPEND it_test.

wa-code = 207.

wa-name = 'Prem'.

wa-amount = 5000.

APPEND wa TO it_test.

it_test-code = 117.

it_test-name = 'James Bond'.

it_test-amount = 9900.

INSERT it_test INDEX 3.

it_test-code = 217.

it_test-name = 'Sivaraman'.

it_test-amount = 9900.

INSERT it_test INDEX 3.

it_test-code = 201.

it_test-name = 'Saravanan'.

it_test-amount = 1000.

APPEND it_test.

it_test-code = 210.

it_test-name = 'Shanmugam'.

it_test-amount = 6000.

APPEND it_test.

WRITE : / 'Loop Display ( Appended rows ) :-'.

LOOP AT it_test.

WRITE : / chk1 AS CHECKBOX,

sy-tabix, sy-vline, it_test-code, it_test-name, it_test-amount.

HIDE : it_test-code, it_test-name.

ENDLOOP.

SKIP.

END-OF-SELECTION.

CLEAR : it_test-code, it_test-name.

WRITE : / 'this from end of selection'.

&----


*& Form DISP1

&----


  • text

----


FORM disp1.

WINDOW STARTING AT 15 10

ENDING AT 80 15.

DO.

CLEAR chk1.

READ LINE sy-index FIELD VALUE chk1.

IF sy-subrc NE 0.

EXIT.

ELSE.

CHECK chk1 NE space.

WRITE : / it_test-code, it_test-name.

MODIFY CURRENT LINE :

FIELD VALUE chk1 FROM ' '

FIELD FORMAT chk1 INPUT OFF.

ENDIF.

ENDDO.

ENDFORM. "DISP1

***line double click ****

AT LINE-SELECTION.

CHECK sy-lsind = 1.

WINDOW STARTING AT 5 4

ENDING AT 85 20.

WRITE: / 'THE USER DOUBLE-CLICKED A LINE IN THE REPORT'.

WRITE: / sy-lisel.

WRITE : / 'Sometime ',it_test-name, ' is good '.

WRITE : / 'Sometime ',it_test-name, ' is bad '.

WRITE : / 'Sometime ',it_test-name, ' is rich '.

WRITE : / 'Sometime ',it_test-name, ' is poor '.

WRITE : / 'Who knows, who is ',it_test-name, ' ? '.

WRITE : /, / 'we can also use this in SELECT statement'.

CLEAR : it_test-code, it_test-name.

.

IF SY-SUBRC <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

ULINE.

SKIP.

SKIP.

WRITE : / 'Below from Get Cursor Field...'.

GET CURSOR FIELD fldname VALUE fldval.

CONDENSE fldname.

CONDENSE fldval.

WRITE : / 'You have clicked ', fldname, ' & its value is ', fldval.

***function key press F6 ****

AT PF06.

PERFORM disp1.

*AT USER-COMMAND.

  • CASE SY-UCOMM.

  • WHEN 'STOP' OR 'CANCEL'.

  • LEAVE TO SCREEN 0.

  • WHEN 'TESTME'.

  • PERFORM DISP1.

  • ENDCASE.

<b>Reward all helpfull answers</b>

Regards

Former Member
0 Kudos

Hi,

A work area is nothing more than a structure which serves as a header line for an internal table. When you read an internal table(without header line) the line which you read must be moved somewhere, it is moved into a work area.

While adding or retrieving records to / from internal table we have to keep the record temporarily.

The area where this record is kept is called as work area for the internal table. The area must have the same structure as that of internal table. An internal table consists of a body and an optional header line.

Header line is a implicit work area for the internal table. It depends on how the internal table is declared that the itab will have the header line or not.

work areas r used for processing data from n into internal table. as work area is a structure which can hold only one record at a time i.e to be inserted into internal table populated from internal table.

work areas generally used for reusability purpose.

i.e a internal table with header line is only used for storing data from a single data base table where as internal table without header line can be used in other internal table. for this purpose we ll create a explicit work area for processing data.

e.g.

data: begin of itab occurs 10,

ab type c,

cd type i,

end of itab. " this table will have the header line.

data: wa_itab like itab. " explicit work area for itab

data: itab1 like itab occurs 10. " table is without header line.

The header line is a field string with the same structure as a row of the body, but it can only hold a single row.

It is a buffer used to hold each record before it is added or each record as it is retrieved from the internal table. It is the default work area for the internal table

Regards,

Padmam.

Former Member

HI,

INTERNAL Table and it's background:

===================================

Internal table acts as a container which is used to store the record sets. That is used to store the data fetched from the database table.

So due to performance reason every time access to database would not be so good and decrease the performance. So you just select the data from the database and store it in the intermediate table. This table is called INTERNAL TABLE. So it's an replica of the database. The design foes like this,

PRESENTATION SERVER <> APPLICATION SERVER <>

DATABASE SERVER.

So everytime gain accessing to database results in high resource usage and bad permformance.

So always play around with internal tables. So obviously the whenever you access the data in the INTERNAL TABLE, the application server will be used.

WORK AREA:

==========

When ever you loop at the internal table, the current record should be stored in a temporary work place. That is called WORK AREA.

LOOP AT ITAB INTO WORKAREA.

ENDLOOP.

ITAB :An internal table

WORKAREA:An instance of internal table

Go thru the link below

reward if it helps..

regards,

Omkar.

Message was edited by:

Omkaram Yanamala

Former Member
0 Kudos

The main differance between work area and IT is workarea can hold only one record and table can hold multiple records. So whenever you have to process IT you have to process in loop or using index.

Former Member
0 Kudos

hi,

Internal Table:

An internal table is a data object, in which you can keep several identically

structured data records at runtime (table variable). The number of data records is

restricted only by the capacity of specific system installations.

Example:

DATA itab1 TYPE TABLE OF scarr

Work Area:

For single record processing of an internal table, you usually need a work area for

which the structure variable has to be defined with the same type as the line type of the internal table.

Header:

The WITH HEADER LINE addition in the definition of the internal table gives you

the option of creating a table with header line. When this is done a work area (header line) that suits the table is created automatically so that the additional definition of the same is not necessary. This also simplifies the syntax of the table commands, as the system always refers to the automatically generated work area, which therefore no longer has to be specified explicitly.

DATA itab1 TYPE TABLE OF scarr WITH HEADER LINE.

DATA itab2 LIKE itab1.

itab1 = itab2 . Only operations with header lines

Body is the contents of the internal table

You can address the body of the table with itab[].

itab1[] = itab2[] . Operations with table bodies

Former Member
0 Kudos

Hi

Work area is used to hold a single record

When you declare a TABLE with TABLES : MARA statement

by default a work area of MARA is created and you can use a select single statement into MARA work area

Similarly with ITAB's if you delcare itab with header line, it creates a work area during run time first the record is fetched to header(work area) and is moved to body.

so every time the record comes to header and then moved to Itab body.

Workarea is the memory area on with you perform the required operation related to data. Every Internal table has a header that is work area of the internal table. As soon as you read a row in an internal table the particular record gets filled in the workarea and now you can make modifications to this data, then say update or append the same data to internal table.

if you have defined an internal table with out header line, then you have to separately declare a work area and use as per requirement.

check these links

http://help.sap.com/saphelp_nw2004s/helpdata/en/fc/eb30dd358411d1829f0000e829fbfe/content.htm

http://help.sap.com/saphelp_nw04/helpdata/en/fc/eb30dd358411d1829f0000e829fbfe/content.htm

<b>Sample code</b>

TYPES : BEGIN OF ty_test,
        code TYPE i,
        name(10) TYPE c,
        amount TYPE p DECIMALS 2,
       END OF ty_test.
 
DATA : it_test TYPE STANDARD TABLE OF ty_test WITH HEADER LINE INITIAL SIZE 10.
 
DATA : wa TYPE ty_test,
       chk1 TYPE c,
       fldname(30), fldval(50).
 
*set pf-status 'PF01'.
*set titlebar 'PF01'.
*
 
INITIALIZATION.
  it_test-code = 300.
  it_test-name = 'Ramesh'.
  it_test-amount = 5500.
  APPEND it_test.
 
  wa-code = 207.
  wa-name = 'Prem'.
  wa-amount = 5000.
  APPEND wa TO it_test.
 
  it_test-code = 117.
  it_test-name = 'James Bond'.
  it_test-amount = 9900.
  INSERT it_test INDEX 3.
 
  it_test-code = 217.
  it_test-name = 'Sivaraman'.
  it_test-amount = 9900.
  INSERT it_test INDEX 3.
 
  it_test-code = 201.
  it_test-name = 'Saravanan'.
  it_test-amount = 1000.
  APPEND it_test.
 
  it_test-code = 210.
  it_test-name = 'Shanmugam'.
  it_test-amount = 6000.
  APPEND it_test.
 
  WRITE : / 'Loop Display ( Appended rows ) :-'.
  LOOP AT it_test.
    WRITE : / chk1 AS CHECKBOX,
    sy-tabix, sy-vline, it_test-code, it_test-name, it_test-amount.
    HIDE : it_test-code, it_test-name.
  ENDLOOP.
  SKIP.
 
END-OF-SELECTION.
  CLEAR : it_test-code, it_test-name.
  WRITE : / 'this from end of selection'.
 
 
*&--------------------------------------------------------------------*
*&      Form  DISP1
*&--------------------------------------------------------------------*
*       text
*---------------------------------------------------------------------*
FORM disp1.
  WINDOW STARTING AT 15 10
         ENDING AT 80 15.
  DO.
    CLEAR chk1.
    READ LINE sy-index FIELD VALUE chk1.
    IF sy-subrc NE 0.
      EXIT.
    ELSE.
      CHECK chk1 NE space.
      WRITE : / it_test-code, it_test-name.
      MODIFY CURRENT LINE :
        FIELD VALUE chk1 FROM ' '
        FIELD FORMAT chk1 INPUT OFF.
    ENDIF.
  ENDDO.
ENDFORM.                                                    "DISP1
 
***line double click ****
AT LINE-SELECTION.
  CHECK sy-lsind = 1.
  WINDOW STARTING AT 5 4
         ENDING AT 85 20.
  WRITE: /  'THE USER DOUBLE-CLICKED A LINE IN THE REPORT'.
  WRITE: /  sy-lisel.
  WRITE : / 'Sometime ',it_test-name, ' is good '.
  WRITE : / 'Sometime ',it_test-name, ' is bad  '.
  WRITE : / 'Sometime ',it_test-name, ' is rich '.
  WRITE : / 'Sometime ',it_test-name, ' is poor '.
  WRITE : / 'Who knows, who is ',it_test-name, ' ? '.
  WRITE : /, / 'we can also use this in SELECT statement'.
  CLEAR : it_test-code, it_test-name.
 
        .
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
 
  ULINE.
  SKIP.
  SKIP.
  WRITE : / 'Below from Get Cursor Field...'.
  GET CURSOR FIELD fldname VALUE fldval.
  CONDENSE fldname.
  CONDENSE fldval.
  WRITE : / 'You have clicked ', fldname, ' & its value is ', fldval.
 
***function key press F6 ****
AT PF06.
  PERFORM disp1.
 
*AT USER-COMMAND.
*  CASE SY-UCOMM.
*    WHEN 'STOP' OR 'CANCEL'.
*      LEAVE TO SCREEN 0.
*    WHEN 'TESTME'.
*      PERFORM DISP1.
*  ENDCASE.


Reward all helpfull answers

Regards

Pavan

Former Member
0 Kudos

work area store single record.

internal table store multiple record

Former Member
0 Kudos

Just go through the following link:

http://erpgenie.com/abaptips/content/view/104/62/

reward if useful

anju

Former Member
0 Kudos

hi,

1. while populating the data to the internal table we will use workarea where in it populates single record .each time while populating the data we have to clear work area.as it can hold single record.

2. we can clear work area by using

clear wa.

we can clear internal table using

refresh itab.

Reward with points if helpful.

Former Member
0 Kudos

Header line:

Header line will occupy the space into memory. With header line records will come one by one into internal table and user will clear the header line.

Work Area:

Work area will not occupy the space into memory. With work area records will come one by one into internal table and no need to clear the Wa because it will auto clear.

Former Member
0 Kudos

HI ,

Internal Table can have more than one records .

However Work area will contain only single record .

Praveen