2008 Feb 28 5:08 AM
Hi all,
Is there any precetations using the clear and refresh staments.Exactly where we are using the these statements?
Regards,
Srihitha
Hi all,
Is there any precetations using the clear and refresh staments.Exactly where we are using the these statements?
Regards,
Srihitha
2008 Feb 28 5:12 AM
Hi,
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,
Mrunal
Edited by: Mrunal Shyamkant Patki on Feb 28, 2008 10:51 AM
2008 Feb 28 5:18 AM
Hi Srihitha,
Clear Statement is used when we want to flush the data from the internal table if you want to use it ahead in the calculations.
it clears the memory of the variable i.e. variable will be empty.
Refresh is Used for table to clear all the entries from the internal table body. but sill memory allocation exist and you can use some other with in the program.
Thanks & Regards,
Dhruv Shah
2008 Feb 28 5:19 AM
Hi,
CLEAR : will use to clear the header line of internal as well as
database tables.
usage: When you are using internal table in LOOP you will clear
the header.
REFRESH : It will remove totla data in INTERNAL table.
When you are inserting data into same internal table
based on diff. conditions.That time you will use refresh.
Ex:
LOOP AT itab.
IF itab-field1 eq 'XX'.
MOVe data to ITAB2.
APPEND ITAB2.
do some functionality her.
ENDIF.
ENDLOOP.
REFRESH itab2.
LOOP AT itab3.
IF itab-field1 eq 'kk'.
MOVe data to ITAB2.
APPEND ITAB2.
do some functionality her.
ENDIF.
ENDLOOP.
2008 Feb 28 5:22 AM
Hi,
Clear -- to clear the data of the internal table header or work area to get another record to be inserted.
Clear[] -- to clear the body of the internal table completely
Refresh -- remove all the internal table data from header and body.
Regards,
kavitha.
2008 Feb 28 5:22 AM
Hi,
it may help u.
1.free : It will free the memory of the Internal table and delete the
records.
2.refresh : It will delete the records but memory will be there.
3.clear : It will clear the header of the internal table records will be
there in internal table.
****************************************************************************************
CLEAR itab.
The memory space required for the table is released, except for the initial memory requirement.
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 itself, not the header line, during initialization using CLEAR, you must place two square brackets ([]) after the table name.
CLEAR itab[].
To ensure that the table itself has been initialized, you can use the statement
REFRESH itab.
This always applies to the body of the table. With REFRESH, too, the initial memory requirement fort he table remains reserved. To release this memory space, use the statement
FREE itab.
You can use FREE to directly initialize an internal table and to release its entire memory space, including the initial memory requirement, without first using the REFRESH or CLEAR statements. Like REFRESH, FREEaccesses the table body, not the table work area. After a FREEstatement, the internal table still exists. 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.
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
REFRESH
Initializes an internal table.
Syntax
REFRESH <itab>.
Resets the internal table <itab> to its initial value, that is, deletes all of its lines.
Cheers,
vasavi.
kindly reward if helpful.
2008 Feb 28 5:22 AM
hi,
clear IT - if the internal table IT has header line it clears the header line.If it doesnt have a headerline it deletes all the rows.
clear IT [] - Deletes all the rows in both he cases.
REFRESH stmt is yswed to delete all th rows from an intenal table but leave the memory allocated.
Regards,
Arunsri
2008 Feb 28 5:23 AM
hi,
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,
pavan t.
2008 Feb 28 5:27 AM
Hi
Clear itab:Will clear header of internal table.
Clear itab [ ]:Will clear body of table.
Refresh itab:Will remove contents of internal table.
2008 Feb 28 5:28 AM
Hi,
CLEAR
Sets a variable to its initial value.
Syntax
CLEAR <f>.
The variable <f>, which can have any data type, is set to an initial value appropriate to its type.
REFRESH
Initializes an internal table.
Syntax
REFRESH <itab>.
Resets the internal table <itab> to its initial value, that is, deletes all of its lines.
REFRESH CONTROL
Initializes a control.
Syntax
REFRESH CONTROL <ctrl> FROM SCREEN <scr>.
The control <ctrl> defined in the CONTROLS statement is reset with the initial values specified for screen <scr>.
CLEAR statement is used to delete the contents of the header line of internal table.
REFRESH statement is used to delete the contents of the body area of internal table.
FREE statement is used to delete the internal table after the program is closed.
DELETE statement is used to delete some particular contents of the internal table.
ATA : BEGIN OF ITAB OCCURS 0,
STR(255),
END OF ITAB.
DATA ITAB1 LIKE KNA1 OCCURS 0 WITH HEADER LINE.
DATA JTAB LIKE BDCDATA OCCURS 0 WITH HEADER LINE.
CALL FUNCTION 'UPLOAD'
EXPORTING
FILENAME = 'C:\KARTHIK.TXT'
FILETYPE = 'ASC'
TABLES
DATA_TAB = ITAB.
LOOP AT ITAB.
SPLIT ITAB-STR AT ',' INTO ITAB1-KUNNR ITAB1-NAME1 ITAB1-ORT01
ITAB1-LAND1.
APPEND ITAB1.
ENDLOOP.
LOOP AT ITAB1.
PERFORM PROGINFO USING 'SAPMYCALLTRANSACTION' '400'.
PERFORM FLDINFO USING 'WA-KUNNR' ITAB1-KUNNR.
PERFORM FLDINFO USING 'WA-NAME1' ITAB1-NAME1.
PERFORM FLDINFO USING 'WA-ORT01' ITAB1-ORT01.
PERFORM FLDINFO USING 'WA-LAND1' ITAB1-LAND1.
CALL TRANSACTION 'YCALLTRANS' USING JTAB.
ENDLOOP.
FORM PROGINFO USING PROGNAME SCRNUM.
CLEAR JTAB.
REFRESH JTAB.
JTAB-PROGRAM = PROGNAME.
JTAB-DYNPRO = SCRNUM.
JTAB-DYNBEGIN = 'X'.
APPEND JTAB.
ENDFORM.
FORM FLDINFO USING FLDNAME FLDVALUE.
CLEAR JTAB.
JTAB-FNAM = FLDNAME.
JTAB-FVAL = FLDVALUE.
APPEND JTAB.
ENDFORM.
Regards,
Priya.
2008 Feb 28 5:31 AM
If in the program code,we are using the same ITAB more than once,then before using the ITAB use Refresh statement.
If we are using a Loop endloop,Clear ITAB will be used .
Loop at itab into wa.
wa1-name = wa-name.
append wa1 to itab1.
clear wa.
endloop.
we shud clear the WA in the loop,for the next set of values.
2008 Feb 28 5:37 AM
Hi,
clear
clear statement will clear the work area of internal table by default.if you specify the the table with it_itab[] now the clear statement will clear the body of internal table.
note : the memory allocated for that internal table remains same.
Refresh :
Refresh statement will clear the body of internal table by default.if you specify the statement refresh it_itab then system will refresh (clear) internal table body data.
note : here also the memory allocated for internal table remains same.
Free :
Free statement will clear the body of internal table by default.
note : here the memory allocate for internal table will collapse.
There will not be any memory alloted to that particular internal table.
regards,
swami.
| User | Count |
|---|---|
| 3 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |