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

clear work area refresh internal table

Former Member
0 Likes
7,265

Hi All,

Where should i claer work area & refresh internal table.

Inside the loop or outside the loop?



LOOP AT gt_ekbe INTO gwa_ekbe.
    gwa_final-belnr = gwa_ekbe-belnr.
    gwa_final-budat = gwa_ekbe-budat.
    gwa_final-ebeln = gwa_ekbe-ebeln.
    gwa_final-menge = gwa_ekbe-menge.
    APPEND gwa_final TO gt_final.
         ENDLOOP.

  LOOP AT gt_ekpo INTO gwa_ekpo.
    gwa_final-werks = gwa_ekpo-werks.
    gwa_final-matnr = gwa_ekpo-matnr.
    APPEND gwa_final TO gt_final.
         ENDLOOP.

  LOOP AT gt_marc INTO gwa_marc.
    gwa_final-prctr = gwa_marc-prctr.
    APPEND gwa_final TO gt_final.
       ENDLOOP.

9 REPLIES 9
Read only

Former Member
2,480

Hi oorvi,

You need to clear the work area inside the loop after every APPEND statement.

Internal table refresh is generally done outside the loop. not inside the loop.

Best Regards,

Ram,.

Read only

Former Member
0 Likes
2,480

Hi,

The normal practice is.

Clear wa is used before the loop starts or before the key endloop as follows

clear wa.

loop itab into wa.

--clear wa.

endloop.

never refresh Itab within a loop.

after the purpose of the Itab is over then you can refresh, that means once you are sure that you are no longer come back and use Itab then you can refresh it.

if you are doing repeatative select queries into the same itab then before the select query you can use refresh.

or if you are filling up the itab on certain condition before you reach that condition you can do that .

Cheers

Ram

Read only

0 Likes
2,480

i am clearing work area inside the loop.

and refreshing internal table outside the loop.

but iam not getting the output.

what is the reason?

Read only

0 Likes
2,480

Clearing the work area should be done after the APPEND statement inside the loop. Even then if you are not getting the output, debug and check where the problem lies.

Read only

0 Likes
2,480

Could you please execute the code in the debugger and check the value in the internal table in every pass to see the problem.

Pooja

Read only

0 Likes
2,480

Hi,

->Please check if your internal table is populated before it comes to the LOOP...ENDLOOP statements that you have written.

->Debug and check the sy-subrc value in case you are populating the internal table using a select query.

Read only

Former Member
0 Likes
2,480

Hi Oorvi,

Workareas are generally cleared inside the loop - endloop statements.

Clear the workareas in the beginning of the statement after the LOOP statement or at the end after appending the data before the ENDLOOP statement. This is done to clear the buffer during the next entry of the loop.

Internal tables are refreshed outside the LOOP statements. Once when the data in the internal tables are no longer required in the program, internal tables are refreshed.

This statement sets an internal table itab to its initial value, meaning that it deletes all rows of the internal table. The memory space required for the table is freed up to the initial memory size INITIAL SIZE. For itab, you must specify an internal table.

The syntax is : REFRESH itab.

Thanks,

Harini

Read only

Former Member
2,480

Hi,

Clearing the work are is done just afetr you append the wa to internal table , but refreshing is done where ever you think data is appended in the internal table comapletely.

so in your case

LOOP AT gt_ekbe INTO gwa_ekbe.
    gwa_final-belnr = gwa_ekbe-belnr.
    gwa_final-budat = gwa_ekbe-budat.
    gwa_final-ebeln = gwa_ekbe-ebeln.
    gwa_final-menge = gwa_ekbe-menge.
    APPEND gwa_final TO gt_final.
   clear gwa_fianl
         ENDLOOP.
refresh gt_final.

hope this will clear your confussion.

pooja

Read only

Former Member
0 Likes
2,480

Hi,

Please clear and refresh at the beginning of loop. And again place clear of work areas inside the loop.

Ex :

Refresh : GT_FINAL.

Clear : gwa_final, gwa_ekbe.

LOOP AT gt_ekbe INTO gwa_ekbe.

gwa_final-belnr = gwa_ekbe-belnr.

gwa_final-budat = gwa_ekbe-budat.

gwa_final-ebeln = gwa_ekbe-ebeln.

gwa_final-menge = gwa_ekbe-menge.

APPEND gwa_final TO gt_final.

Clear : gwa_final, gwa_ekbe.

ENDLOOP.

Hope this will be helpful to you