‎2007 Jun 08 7:57 AM
Hello Experts,
When do we use a work area and how is it useful...in what situations shud we use it....difference between internal tables and work area...
Thanks in advance...
Cheers:Jim
‎2007 Jun 08 8:05 AM
Hi Jimmy
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
Reward all helpfull answers
Regards
Pavan
‎2007 Jun 08 8:00 AM
Hi Jimmy,
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,
Reward If Helpful.
‎2007 Jun 08 8:00 AM
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.
Reward points for useful Answers
Regards
Anji
‎2007 Jun 08 8:01 AM
Simple terminology,
Internal table- store multiple records
work area - It get one record at a time from internal table and we process them.
Processing is always based on work area and selection of data is done in internal table.
Reward points if useful.
Regards,
Atish
‎2007 Jun 08 8:01 AM
hi
good
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.
http://www.sap-img.com/abap/difference-between-work-area-and-header-line.htm
thanks
mrutyun^
‎2007 Jun 08 8:11 AM
In what circumstances do we use work area....sample code would help...when I have a internal table that has a header then i can do all the processing through that...where do we work area...
please explain...
‎2007 Jun 08 8:14 AM
yes Jim, you can use table with work area BUT not in ABAP OO and now a days after ECC 6 SAP becoming more and more towards ABAP OO.
So you need explicit work area there.
Regards,
Atish
‎2007 Jun 08 8:16 AM
Atish,How to we actually use it.....Do u have any sample code that makes understand it clearly...I am not able to get the fact that when we have the header in the internal table why do we need a work area...
Sorry for the trouble...but I have to understand this....
‎2007 Jun 08 8:21 AM
Hi Jimmy
here is ur 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.
Reward all helpfull answers
Regards
Pavan
‎2007 Jun 08 8:22 AM
hi Jimmy,
TYPES:
BEGIN OF t_bukrs,
bukrs LIKE t001-bukrs, "Company dode
butxt LIKE t001-butxt, "Name of company
END OF t_bukrs,
data gt_bukrs TYPE STANDARD TABLE OF t_bukrs. "table
data gs_bukrs TYPE t_bukrs." work area
select * from t001 into corresponding fields of table gt_bukrs.
loop at gt_bukrs into gs_bukrs.
write:/ gs_bukrs-bukrs.
endloop.
hope it is clear. Revert if still not clear.
Regards,
Atish
‎2007 Jun 08 8:39 AM
Hey Jimmy,
Do reward points to useful answers and close the threads
Regards,
Atish
‎2007 Jun 08 8:05 AM
Hi Jimmy
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
Reward all helpfull answers
Regards
Pavan
‎2007 Jun 08 8:40 AM