‎2009 Oct 12 11:49 AM
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.
‎2009 Oct 12 11:53 AM
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,.
‎2009 Oct 12 11:59 AM
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
‎2009 Oct 12 12:45 PM
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?
‎2009 Oct 12 12:47 PM
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.
‎2009 Oct 12 12:50 PM
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
‎2009 Oct 12 12:52 PM
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.
‎2009 Oct 12 12:14 PM
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
‎2009 Oct 12 12:21 PM
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
‎2009 Oct 12 1:13 PM
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