Thursday, January 7, 2010

CLEAR vs. REFRESH vs. FREE

I almost forgot what does these 3 used for, basically they are used to initialize internal table.
  1. CLEAR => Initialize the content and remain the allocated initial memory space, BUT,
    • because SAP allows using internal table(itab) with header line (enable you refer to structure and internal table with the same name). CLEAR itab will only clear the header line not the table body. => clear the content of the structure.
    • To clear the table content, you need to use CLEAR itab[]. 
    • IF you declared it without header line (for instance, DATA lt_itab TYPE STANDARD TABLE OF ever) CLEAR itab will clear the table content.
  2. REFRESH => similar as CLEAR, but REFRESH always refer to internal table content (table body). Thus, REFRESH itab = CLEAR itab[].
  3. FREE => similar to REFRESH, always refer to internal table content, but it does one more thing, it release the initial memory space allocated for the table body (table header is still exists). When you try to fill in value to internal table again, new memory space will be allocated for the table body.
In Conclusion,
 
C1/Case 1: DATA: itab TYPE STANDARD TABLE OF ever.
C2/Case 2: DATA: itab TYPE ever OCCURS 0 WITH HEADER LINE.

How to Initialize table content
Refer to Work Area / Structure
Refer to Table Content / Table Body
Release
Table Header Memory Space
Release Table Body Memory Space
CLEAR
C1: CLEAR itab
C2: CLEAR itab[]
C1:
C2: CLEAR itab.
C1:
C2: CLEAR itab[]


REFRESH
REFRESH itab




FREE
FREE itab






Summarized from: Initializing Internal Tables.

    4 comments:

    1. Great.
      Thanks a lot.

      ReplyDelete
    2. Very good and comprehensive abstract!

      Thank you.

      ReplyDelete
    3. The information provided here is of great use as I got to learn new things. Keep blogging.
      SAP ABAP TRAINING IN HYDERABAD

      ReplyDelete
    4. Great Post. The information provided is of great use as I got to learn new things. Keep Blogging.
      SAP ABAP TRAINING IN HYDERABAD

      ReplyDelete