2006 Oct 13 5:25 PM
Hi friends,
I seem to have some confusion between clear and refresh. Do we use clear only for workareas and refresh only for internal tables?
Can you give me an example of how these clear and refresh works for an internal table with and with out header line?
Thank you,
Krishen
2006 Oct 13 5:32 PM
CLEAR works with any variable (not just internal table work areas). It will set it to initial values.
Rob
2006 Oct 13 5:26 PM
clear statement clears the header while refresh clears the body of Internal table ...
Check
http://help.sap.com/saphelp_nw2004s/helpdata/en/fc/eb384e358411d1829f0000e829fbfe/content.htm
Regards,
santosh
2006 Oct 13 5:30 PM
Hi,
CLEAR resets to its initial values..
1.
For structure it will clear all the fields in the structure..
EX:
DATA: S_MARA LIKE MARA.
CLEAR: S_MARA.
2. For internal tables if it is declared with header line then it clear the header line otherwise it will clear the whole internal table..
EX:
DATA: ITAB TYPE STANDARD TABLE OF MARA WITH HEADER LINE.
CLEAR: ITAB.. " THis will clear the header line..
DATA: ITAB TYPE STANDARD TABLE OF MARA.
CLEAR: ITAB.. " THis will clear the whole internal table..
3. Refresh clear the internal tables irrespective of with or without header line.
4. Clear can be used for variables, work areas and internal tables..
THanks,
Naren
2006 Oct 13 5:32 PM
CLEAR works with any variable (not just internal table work areas). It will set it to initial values.
Rob
2006 Oct 13 8:57 PM
CLEAR also works for internal tables. I don't think I've ever seen it used, but:
CLEAR itab[].
works.
Rob
2006 Oct 13 5:33 PM
Hi Krishen,
There are 2 types of clear statements we can use:
Clear ITAB. This Statement will clear the Internal Table Header content. To clear the Intertal Table Hearder as well Body we can use Clear ITAB [ ] statement.
Refresh will deletes the Internal Table content but still memory is not freed.
Regards,
Ferry Lianto
2006 Oct 13 5:34 PM
Check this sample code:
REPORT ypra_sample61.
TYPES: BEGIN OF ty_itab,
data1 TYPE char10,
data2 TYPE char10,
END OF ty_itab.
DATA: itab TYPE STANDARD TABLE OF ty_itab,
wa_itab TYPE ty_itab.
DATA: itab1 TYPE ty_itab OCCURS 0 WITH HEADER LINE,
wa_itab1 TYPE ty_itab.
wa_itab-data1 = '12'.
wa_itab-data2 = '112'.
APPEND wa_itab TO itab.
CLEAR: wa_itab, itab.
*Here the clear will clear both the header and as well as Body - Because
*it is declared as type standard table of ty_itab.
wa_itab1-data1 = '12'.
wa_itab1-data2 = '112'.
APPEND wa_itab1 TO itab1.
CLEAR: wa_itab1, itab1.
REFRESH: itab1.
*Here both the clear & refresh should be given to clear the workarea & *the internal table
Regards,
Prakash.
2006 Oct 13 8:45 PM
Hello Krishen
If you do not use header lines (for itabs) you will never ever run into trouble with CLEAR and REFRESH. While you can use CLEAR on any variable I prefer to use CLEAR for fields and workareas and REFRESH for itabs.
Regards
Uwe
2006 Oct 16 12:21 PM
1) <b>CLEAR</b> is used to clear a variable or a workarea... When you use it with internal table, it clears the HEADER of that internal table.
2) REFRESH is only used with Internal tables. It removes all the body content of that internal table, but not the HEADER of that internal table.
CLEAR itab.
Refresh itab.
When executing both these lines it will clear every thing from internal table ie... body content and header content.
hope this helps you.
~thomas.
2006 Oct 16 2:00 PM
There appears to be some confusion about this. Clear will clear the specified data area. If an internal table has a header line then the clear works on the header line. If however the data field is expressly stated as the table body then the clear has the same effect as the Refresh.
data: w_itab type standard table of bseg,
h_itab type standard table of bseg
with header line.
...
* This only clears the header line.
clear h_itab.
* Where as this clears the body (and is the same as a refresh)
clear h_itab[].
* Since this is only a body, the table is refreshed
clear w_itab.
For program clarity I prefer to use clear for work areas, and refresh for table bodies.
Clear: h_itab.
Refresh: h_itab, w_itab.
Do not forget the FREE command to recover memory after final use.
MattG.