Field-symbol vs Workarea

Field-symbol vs Workarea

Internal table processing is essential part of any ABAP program. Generally, we use the explicit work area to process the internal table like appending & modifying records. We can reduce the time and improve the performance of the program by using the field-symbols.

When we use the LOOP construct with the explicit work area, system need to engage the resources to put the required record in the work area, process it and move it back to the table if the needed. This additional processing time could be saved by using the field-symbol. By using the field-symbols we can save this additional time and improve the performance. Field-symbols are similar to de-referenced pointers in C. While using the field-symbol, system uses the same memory allocated to that particular field in the record instead of moving it to work area and processing.

Video:

Code:

*&———————————————————————*
*& Report  ZPR_TEST_WA_VS_FS1
*&
*&———————————————————————*
*&
*&
*&———————————————————————*

REPORT  ZPR_TEST_WA_VS_FS1.

DATA GT_MSEG TYPE STANDARD TABLE OF MSEG.
DATA GS_MSEG LIKE LINE OF GT_MSEG.
DATAGW_FLAG TYPE FLAG,
GW_STA_TIME TYPE I,
GW_END_TIME TYPE I,
GW_DIFF_W TYPE I,
GW_DIFF_F LIKE GW_DIFF_W,
GW_SAVE LIKE GW_DIFF_W.
FIELD-SYMBOLS <GF_MSEG> LIKE LINE OF GT_MSEG.

SELECT
*
FROM MSEG
INTO TABLE GT_MSEG
UP TO 10000 ROWS.

“Processing with workarea – begin
GET RUN TIME FIELD GW_STA_TIME.
LOOP AT GT_MSEG INTO GS_MSEG.
IF SYTABIX 1.
ELSE.
GS_MSEGSGTXT ‘Test’.
MODIFY GT_MSEG FROM GS_MSEG.
ENDIF.
ENDLOOP.
GET RUN TIME FIELD GW_END_TIME.
GW_DIFF_W GW_END_TIME – GW_STA_TIME.
WRITE/(50‘Workarea – run time in micro seconds: ‘GW_DIFF_W.
“Processing with workarea – end

“Processing with field-symbol – begin
CLEARGW_STA_TIMEGW_END_TIME.
GET RUN TIME FIELD GW_STA_TIME.
LOOP AT GT_MSEG ASSIGNING <GF_MSEG>.
IF SYTABIX 1.
ELSE.
<GF_MSEG>SGTXT ‘Test’.
ENDIF.
ENDLOOP.
GET RUN TIME FIELD GW_END_TIME.
GW_DIFF_F GW_END_TIME – GW_STA_TIME.
WRITE/(50‘Field-symbol – run time in micro seconds: ‘GW_DIFF_F.
“Processing with field-symbol – end

GW_SAVE GW_DIFF_W – GW_DIFF_F.
WRITE/(50‘Total time saving – in micro seconds: ‘GW_SAVE.
WRITE‘Done 🙂 !!!’.

3 Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply