‎2006 May 19 12:04 PM
What is the exact difference among clear , refresh and free.
‎2006 May 19 12:06 PM
hii
clear itab - clears only header line
refresh itab- clears body of the internal table
Free itab - clears a internal table from memory
it deletes the internal table from the memory itself
<b>CLEAR ITAB[] does the same thing as REFRESH ITAB.</b>
You can use FREE to initialize an internal table and release its memory space without first using the REFRESH or CLEAR statement.
Like REFRESH, FREE works on the table body, not on the table work area.
After a FREE statement, you can address the internal table again. It still occupies the amount of memory required for its header (currently 256 bytes). When you refill the table, the system has to allocate new memory space to the lines.
it is better practice to use the FREE ITAB command whenever possible as it will maximise system resources.
If you free the memory allocated to this internal table, the memory could be allocated to another program or another data object in the same program.
chk this link
<b>http://help.sap.com/saphelp_nw04/helpdata/en/fc/eb384e358411d1829f0000e829fbfe/content.htm</b>
Regards
Naresh
‎2006 May 19 12:08 PM
HI,
CLEAR ITAB
When CLEAR itab references an internal table itab with a header line, it only resets the subfields in the header entry to their initial values (as mentioned above). The individual table entries remain unchanged.
To delete the entire internal table together with all its entries, you can use CLEAR itab[] or REFRESH itab.
REFRESH itab.
Effect
The internal table itab is reset to its initial state, i.e. all table entries are deleted.
Der Return Code SY-SUBRC is undefined.
Notes
The header entry of a table with a header line remains unchanged. It can be reset to its initial value using CLEAR.
FREE ITAB
FREE itab can be used to free up the memory allocated to the table.
Note
Performance:
The runtime required to reset an internal table depends on the amount of memory previously occupied by that table.
Resetting a small internal table takes around 15 msn (standard microseconds). Resetting a 200 KB table takes around 400 msn, and a 1 MB table, around 3000 msn.
If the internal table has an index or a hash table (because it was edited using INSERT, DELETE, SORT or COLLECT), the runtime increases slightly, since the index or hash table has to be released as well as the table itself.
Variant 2
REFRESH itab FROM TABLE dbtab.
Note
This variant is no longer maintained and should no longer be used (see also obsolete key words). Please use the SELECT ... INTO TABLE statement instead.
Effect
The internal table itab is deleted and it is then filled with the contents of the database table dbtab.
A generic argument can be used to specify a restriction to a particular part of the database table when filling (LOOP AT dbtab, READ TABLE dbtab).
The table dbtab must be declared in the program using TABLES.
Der Return Code SY-SUBRC is undefined.
Example
Delete an internal table MESSAGES, then fill the table with all messages from the table T100 with language key 'D' and ID 'RF'.
TABLES T100.
DATA MESSAGES TYPE TABLE OF T100 WITH HEADER LINE
MESSAGES-TEXT = 'Delete me'.
APPEND MESSAGES.
T100-SPRSL = 'E'.
T100-ARBGB = 'RF'.
REFRESH MESSAGES FROM TABLE T100.
Variant 3
REFRESH itab FROM SELECT-OPTIONS.
Note
This variant is no longer supported (see also obsolete key words). The equivalent functionality is now available in the function module RS_REFRESH_FROM_SELECTOPTIONS.
Effect
Deletes the internal table itab and then transfers the database selections and the selection parameters together with the values entered by the user.
HOPE THIS HELPS,
PRIYA.
‎2006 May 19 12:08 PM
CLEAR --> Clears only header of internaltable
REFRESH --> Clears the body of internal ltable
FREE --> clears internal table from memory
Message was edited by: Chandrasekhar Jagarlamudi
‎2006 May 19 12:09 PM
CLEAR -- CLEARS THE CONTENTS OF HEADER OF ITAB
REFRESH -- IN CASE OF REAL TIME WHEN THE DATA GETS UPLOADED INTO DATABASE FREQUENTLY REFRESH AGAIN FILLS THE ITAB
FREE -- FREES THE MEMORY ALLOCATED FOR THE ITAB
‎2006 May 19 12:09 PM
Hi,
Clear will delete the contents of an line/structure/variable.
Refresh will delete the contents/records in the internal table.
Free will delete the contents of an internal table, as well as deleting the memory usage of the internal table.
If this is useful, award ponts pls..
Regards,
Bharadwaj
‎2006 May 19 12:11 PM
Clear : Used to clear the variables, Work Areas and structure contents
Refresh : Used to clear the contents of internal tables
Free : Deallocates the memory held by internal tables, global variables etc.
‎2006 May 19 12:11 PM
Hi
<b>Clear:</b>
If f is a field string, each component field is reset to its initial value. If it is an internal table without a header line, the entire table is deleted together with all its entries. If, however, f is an internal table with a header line, only the sub-fields in the table header entry are reset to their initial values.
<b>Free:</b>
If f is an internal table with header line (where the name f in a sense has two meanings) the statement FREE f refers to the body of the table, and the statement CLEAR f refers to the header line.
<b>Refresh:</b>
The internal table itab is reset to its initial state, i.e. all table entries are deleted.
<i>Hope This Info Helps YOU.</i>
Regards,
Raghav
‎2006 May 19 12:12 PM
hi,
clear is used to clear the variable, header and also you can use it to refresh the table.
clear var.
clear itab.
clear itab[].
refresh is used to refrsh the contents of internal table
refresh itab.
free
it is used to free the object or variable, or itabs.
free var.
free itab.
regards
vijay
‎2006 May 19 12:13 PM
Hi balakrishna,
1. To get a taste of it,
just copy paste in new program.
2. Just see the table ITAB in debugging mode,
at various break-points.
3.
report abc.
*----
data : itab like table of t001 with header line.
*----
select * from t001 into table itab.
read table itab index 1.
*----
break-point.
clear itab. "===== header line gets cleared
break-point.
clear itab[]. "====== same as refresh itab
refresh itab.
break-point.
free itab. "====== memory is freed
break-point.
regards,
amit m.
‎2006 May 19 12:42 PM
Hi Balakrishn,
Like all data objects, you can initialize internal tables with the
CLEAR <itab>.
statement. This statement restores an internal table to the state it was in immediately after you declared it. This means that the table contains no lines. However, the memory already occupied by the memory up until you cleared it remains allocated to the table.
If you are using internal tables with header lines, remember that the header line and the body of the table have the same name. If you want to address the body of the table in a comparison, you must place two brackets ([ ]) after the table name.
CLEAR <itab>[].
To ensure that the table itself has been initialized, you can use the
REFRESH <itab>.
statement. This always applies to the body of the table. As with the CLEAR statement, the memory used by the table before you initialized it remains allocated. To release the memory space, use the statement
FREE <itab>.
You can use FREE to initialize an internal table and release its memory space without first using the REFRESH or CLEAR statement. Like REFRESH, FREE works on the table body, not on the table work area. After a FREE statement, you can address the internal table again. It still occupies the amount of memory required for its header (currently 256 bytes). When you refill the table, the system has to allocate new memory space to the lines.
DATA: BEGIN OF LINE,
COL1,
COL2,
END OF LINE.
DATA ITAB LIKE TABLE OF LINE.
LINE-COL1 = 'A'. LINE-COL2 = 'B'.
APPEND LINE TO ITAB.
REFRESH ITAB.
IF ITAB IS INITIAL.
WRITE 'ITAB is empty'.
FREE ITAB.
ENDIF.
The output is:
ITAB is empty.
In this program, an internal table ITAB is filled and then initialized with REFRESH. The IF statement uses the expression ITAB IS INITIAL to find out whether ITAB is empty. If so, the memory is released.
regards,
keerthi.