2007 Dec 26 9:59 AM
Hi all
I have an internal table ITAB with header line.
(1) Clear ITAB
(2) Clear ITAB[]
(3) Refresh ITAB
(4) Refresh ITAB[]
(5) Free ITAB
(6) Free ITAB[]
Please explain all .& what is the difference b/w (1) and (3) also (2) and (4).
Thanks.
2007 Dec 26 10:01 AM
Hi,
if u use [] with clear free and refresh then contents of header line also gets deleted
clear -- to clear the data of the internal table header
clear[] -- to clear the body of the internal table
refresh -- clears the internal table data from header and body
free -- deletes the data of the internal table and also deletes the memory area allocated to the internal table
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.
To reset a variable var to the appropriate initial value for its type, use the statement
CLEAR var.
This statement has different effects for different data types:
キ Elementary ABAP types
The CLEAR statement sets the value of elementary variables to their initial value (see the keyword documentation) not to the start value, which is set using the VALUE parameter of the DATA statement.
キ References
The CLEAR statement resets a reference variable to its initial value, that is, so that it does not point to an object.
キ Structures
The CLEAR statement resets the individual components of a structure to their respective initial values.
キ Internal tables
The CLEAR statement deletes the entire contents of an internal table (see also Initializing Internal Tables).
You cannot use the CLEAR statement to reset a constant.
REPORT demo_data_clear.
DATA number TYPE i VALUE '10'.
WRITE number.
CLEAR number.
WRITE / number.
The output appears as follows:
10
0
The CLEAR statement resets the contents of the field number from 10 to its initial value 0.
Free - It deletes all the rows and free the associated memory i.e. free itab.
refresh - It deletes all the rows but memory remains allocated i.e. refresh itab.
Clear - It deletes all the rows and leave the memory allocated but clear the header line i.e. clear itab.To clear the Intertal Table Hearder as well Body we can use Clear ITAB [ ] statement.
chk this also
http://help.sap.com/saphelp_nw2004s/helpdata/en/fc/eb384e358411d1829f0000e829fbfe/frameset.htm
yntax
CLEAR dobj [ {WITH val CHARACTER} MODE }
| {WITH NULL} ].
Effect
Without the optional additions, the data object dobj is assigned the type-specific initial value. The following applies:
The initial values are assigned to elementary data types according to the table of built-in ABAP types.
Reference variables are assigned null references.
Structures are set to their initial values component by component.
All rows in an internal table are deleted. All the memory required for the table, except for the initial memory requirement, is released (see Declaring Internal Tables). The FREE statement is used to release the memory space occupied by the rows of internal tables.
The optional additions allow you to fill the spaces of a data object with other values than the initial value.
Note
If dobj is an internal table with a header line, you must specify dobj[] to delete the rows, otherwise only the header line will be deleted.
Addition 1
... WITH val CHARACTER} MODE
Effect
If you use the WITH val addition and specify BYTE or CHARACTER MODE, all spaces are replaced either with the first byte or the first character in val. If dobj is of the type string or xstring (as of Release 6.10), the string is processed in its current length.
The IN BYTE and CHARACTER MODE additions can be used as of Release 6.10 (see also Processing Byte Strings and Character Strings ). Without specification and before Release 6.10 the IN CHARACTER MODE addition applies. Depending on the addition, the data object dobj must be either byte-type or character-type and the data object val must be either byte-type or character type and have the length 1. Before Release 6.10, dobj and val must be flat. If dobj and val do not have the correct type and correct length in a non- Unicode program, they are still handled as if they do, independently of the actual type. In Unicode programs, this will cause a Syntax error or an exception that cannot be handled.
Example
The byte string hexstring as assigned a specific byte value over the entire current length.
DATA: hexstring TYPE xstring,
hex(1) TYPE x VALUE 'FF'.
...
hexstring = '00000000'.
...
CLEAR hexstring WITH hex IN BYTE MODE.
Addition 2
... WITH NULL
Effect
This addition, which is not allowed in ABAP Objects, replaces all bytes of dobj with the value hexadecimal 0. In this case, the data object dobj must be flat.
Note
The WITH NULL addition should only be used for byte-type data objects and therefore be replaced with the CLEAR WITH val addition, which - in this context - at least ensures a higher level of security in Unicode programs.
Syntax
FREE dobj.
Effect
The FREE statement has the same effect as the CLEAR
statement for any data objects except internal tables.
For internal tables, FREE has the same effect as the REFRESH statement. It releases the entire memory area occupied by the table rows. If dobj is a structure with table-like components, the memory of each table-like component is released.
Note
If dobj is an internal table with a header line , FREE has the same effect as REFRESH on the table body, and not the header line.
FORMAT RESET.
This addition sets all formatting settings for which the corresponding addition is not specified in the same FORMAT statement to the state OFF, apart from the setting of the FRAMES addition, which is set to ON. For settings whose addition is also specified, the RESET addition has no effect,
But if you need regarding REFRESH
REFRESH itab.
Effect
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.
To delete all rows and free the entire memory space occupied by rows, you can use the statement FREE.
Regards
Edited by: p498863 on Dec 26, 2007 11:03 AM
2007 Dec 26 10:01 AM
Hi,
if u use [] with clear free and refresh then contents of header line also gets deleted
clear -- to clear the data of the internal table header
clear[] -- to clear the body of the internal table
refresh -- clears the internal table data from header and body
free -- deletes the data of the internal table and also deletes the memory area allocated to the internal table
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.
To reset a variable var to the appropriate initial value for its type, use the statement
CLEAR var.
This statement has different effects for different data types:
キ Elementary ABAP types
The CLEAR statement sets the value of elementary variables to their initial value (see the keyword documentation) not to the start value, which is set using the VALUE parameter of the DATA statement.
キ References
The CLEAR statement resets a reference variable to its initial value, that is, so that it does not point to an object.
キ Structures
The CLEAR statement resets the individual components of a structure to their respective initial values.
キ Internal tables
The CLEAR statement deletes the entire contents of an internal table (see also Initializing Internal Tables).
You cannot use the CLEAR statement to reset a constant.
REPORT demo_data_clear.
DATA number TYPE i VALUE '10'.
WRITE number.
CLEAR number.
WRITE / number.
The output appears as follows:
10
0
The CLEAR statement resets the contents of the field number from 10 to its initial value 0.
Free - It deletes all the rows and free the associated memory i.e. free itab.
refresh - It deletes all the rows but memory remains allocated i.e. refresh itab.
Clear - It deletes all the rows and leave the memory allocated but clear the header line i.e. clear itab.To clear the Intertal Table Hearder as well Body we can use Clear ITAB [ ] statement.
chk this also
http://help.sap.com/saphelp_nw2004s/helpdata/en/fc/eb384e358411d1829f0000e829fbfe/frameset.htm
yntax
CLEAR dobj [ {WITH val CHARACTER} MODE }
| {WITH NULL} ].
Effect
Without the optional additions, the data object dobj is assigned the type-specific initial value. The following applies:
The initial values are assigned to elementary data types according to the table of built-in ABAP types.
Reference variables are assigned null references.
Structures are set to their initial values component by component.
All rows in an internal table are deleted. All the memory required for the table, except for the initial memory requirement, is released (see Declaring Internal Tables). The FREE statement is used to release the memory space occupied by the rows of internal tables.
The optional additions allow you to fill the spaces of a data object with other values than the initial value.
Note
If dobj is an internal table with a header line, you must specify dobj[] to delete the rows, otherwise only the header line will be deleted.
Addition 1
... WITH val CHARACTER} MODE
Effect
If you use the WITH val addition and specify BYTE or CHARACTER MODE, all spaces are replaced either with the first byte or the first character in val. If dobj is of the type string or xstring (as of Release 6.10), the string is processed in its current length.
The IN BYTE and CHARACTER MODE additions can be used as of Release 6.10 (see also Processing Byte Strings and Character Strings ). Without specification and before Release 6.10 the IN CHARACTER MODE addition applies. Depending on the addition, the data object dobj must be either byte-type or character-type and the data object val must be either byte-type or character type and have the length 1. Before Release 6.10, dobj and val must be flat. If dobj and val do not have the correct type and correct length in a non- Unicode program, they are still handled as if they do, independently of the actual type. In Unicode programs, this will cause a Syntax error or an exception that cannot be handled.
Example
The byte string hexstring as assigned a specific byte value over the entire current length.
DATA: hexstring TYPE xstring,
hex(1) TYPE x VALUE 'FF'.
...
hexstring = '00000000'.
...
CLEAR hexstring WITH hex IN BYTE MODE.
Addition 2
... WITH NULL
Effect
This addition, which is not allowed in ABAP Objects, replaces all bytes of dobj with the value hexadecimal 0. In this case, the data object dobj must be flat.
Note
The WITH NULL addition should only be used for byte-type data objects and therefore be replaced with the CLEAR WITH val addition, which - in this context - at least ensures a higher level of security in Unicode programs.
Syntax
FREE dobj.
Effect
The FREE statement has the same effect as the CLEAR
statement for any data objects except internal tables.
For internal tables, FREE has the same effect as the REFRESH statement. It releases the entire memory area occupied by the table rows. If dobj is a structure with table-like components, the memory of each table-like component is released.
Note
If dobj is an internal table with a header line , FREE has the same effect as REFRESH on the table body, and not the header line.
FORMAT RESET.
This addition sets all formatting settings for which the corresponding addition is not specified in the same FORMAT statement to the state OFF, apart from the setting of the FRAMES addition, which is set to ON. For settings whose addition is also specified, the RESET addition has no effect,
But if you need regarding REFRESH
REFRESH itab.
Effect
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.
To delete all rows and free the entire memory space occupied by rows, you can use the statement FREE.
Regards
Edited by: p498863 on Dec 26, 2007 11:03 AM
2007 Dec 26 10:04 AM
HI,
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 --> The internal table itab is reset to its initial state, i.e. all table entries are deleted.
The header entry of a table with a header line remains unchanged. It can be reset to its initial value using CLEAR.
FREE itab can be used to free up the memory allocated to the table.
THX
2007 Dec 26 10:05 AM
Hi,
Statement 1 would clear work area of your table if your internal table is with header line else statement one would also clear all the records of your internal table.
Statement 2 >> Clears/deletes all the records of your itab.
Statement 3 and 4 >> Clears/deletes all the records of your itab.
Note :
The header entry of a table with a header line can be reset to its initial value using CLEAR.
FREE itab can be used to free up the memory allocated to the table.
Please reward if useful.
Regards,
lalit
2007 Dec 26 10:06 AM
Hi,
Clear itab-------> this is used to clear workarea ,
Clear itab[]------> This is used to clear the table body ..
Refresh -
> to refresh the workarea memory.
Refresh[]----
> To refresh the table memory area...
regards,
Sana.
Reward points is helpful....
2007 Dec 26 12:06 PM
Hi,
CLEAR <internal table>
1. Initialises the header line.
2. Internal table lines remain unchanged.
REFRESH <internal table>
1. Deletes all table lines.
2. Storage space is not released.
3. Paging is released.
4.Header line remains unchanged.
FREE <internal table>
1. Deletes all table lines.
2. Storage space is released
3.Header line remains unchanged
Reward Points,if useful.
Regards,
Manoj Kumar