2008 Feb 25 9:57 AM
Hi all,
I am new in ABAP.
anyone can explian me the below topics with coding examples.what is the use and where should we use.
1.free
2.refresh
3.clear
4.delete
Thanks and regards,
navneeth
2008 Feb 25 10:17 AM
Hi,
Please find the explanation below.
When you define a variable or a table in a program. And execute it the processor will allocate appropriate memory to the variable hope you know this.
Ex:
DATA : Variable(1) type c.
Then the processor will allocate memory(With memory ID Some say 412536) equal to size 1 character size.
Then if you assign a value for the above variable like
Variable = 'X'. the variable or memory id 412536 contains this 'X' value.
If you write:
1. FREE Variable.
The memory allocated is refreshed and freed. Means after this statement the memory to the variable is no more. It is freed from the program and can be used for some other program are purpose.
2. REFRESH i_tab.
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.
3. CLEAR variable .
it clears the memory of the variable i.e. variable will be empty.
4.DELETE variable or I_tab index i etc.
It deletes a specific value from a I_tab body based on condition.
Hope it is clear,
Thanks,
Surya
Hi all,
I am new in ABAP.
anyone can explian me the below topics with coding examples.what is the use and where should we use.
1.free
2.refresh
3.clear
4.delete
Thanks and regards,
navneeth
2008 Feb 25 10:03 AM
Hi,
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.
4.delete : delete the required records.
2008 Feb 25 10:04 AM
CLEAR
Syntax
CLEAR dobj [ {WITH val [IN {BYTE|CHARACTER} MODE] }
| {WITH NULL} ].
Extras:
1. ... WITH val [IN {BYTE|CHARACTER} MODE]
2. ... 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 [IN {BYTE|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.
Exceptions
Non-Catchable Exceptions
Cause: Field val does not have length 1 for variant CLEAR fld WITH val IN BYTE MODE.
Runtime Error: CLEAR_VALUE_BYTEMODE_WRONG_LEN
Cause: Field val does not have length 1 for variant CLEAR fld WITH val [IN CHARACTER MODE].
Runtime Error: CLEAR_VALUE_WRONG_LENGTH
REFRESH
Syntax
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.
Note
The statement REFRESH itab acts for all internal tables like CLEAR itab[]. If an internal table itab has a header line, then the table body and not the header line is initialized. If the internal table itab has no header line, REFRESH itab acts like CLEAR itab. Therefore, you should always use CLEAR instead of REFRESH.
Exceptions
Non-Catchable Exceptions
Cause: No more memory space available to create the table
Runtime Error: REFRESH_NO_SHORT_MEMORY
FREE
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.
DELETE
delete <itab> where <condition>
2008 Feb 25 10:05 AM
Hi Navneth,
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.
DELETE for Files
Deletes files on the application server
Syntax
DELETE DATASET <dsn>.
Deletes the file <dsn> from the file system of the application server.
DELETE for Database Table Entries
Deletes entries from database tables.
Syntax
DELETE FROM <dbtab> WHERE <cond>.
All of the lines in the database table that satisfy the conditions in the WHERE clause are deleted.
Syntax
DELETE <dbtab> FROM <wa>.
DELETE <dbtab> FROM TABLE <itab>.
This deletes the line that has the same primary key as the work area <wa>, or deletes all the lines in the database that have the same primary key as a line in the internal table <itab>. The work area <wa> or the lines of the internal table <itab> must have at least the same length as the work area of the database table.
DELETE for Cluster Databases
Deletes data clusters from cluster database tables.
Syntax
DELETE FROM DATABASE <dbtab>(<ar>) ID <key>.
Deletes the entire cluster in area <ar> with the name <key> from the cluster database table <dbtab>.
DELETE for the Cross-Transaction Application Buffer
Deletes data clusters from the cross-transaction application buffer.
Syntax
DELETE FROM SHARED BUFFER <dbtab>(<ar>) ID <key>.
Deletes the data cluster for the area <ar> with the name <key> stored in the cross-transaction application buffer for the table <dbtab>.
DELETE for Lines from an Internal Table
Deletes lines from internal tables of any type.
Syntax
DELETE TABLE <itab> FROM <wa>.
DELETE TABLE <itab> WITH TABLE KEY <k1> = <f 1>... <k n> = <f n>.
Deletes using the table key. All lines with the same key are deleted. The key values are taken either from a compatible work area <wa> or specified explicitly.
Syntax
DELETE <itab> WHERE <cond>.
Deletes using conditions. Deletes all table entries that satisfy the logical expression <cond>. The logical condition can consist of more than one comparison. In each comparison, the first operand must be a component of the line structure.
Syntax
DELETE ADJACENT DUPLICATE ENTRIES FROM <itab> [COMPARING... ].
Deletes adjacent duplicate entries, either by comparing the key fields or the comparison fields specified explicitly in the COMPARING addition.
DELETE for Lines from Index Tables
Deletes entries from index tables.
Syntax
DELETE <itab> [INDEX <idx>].
If you use the INDEX addition, the line with index <idx> is deleted from the table <itab>. Without the INDEX addition, you can only use the above statement within a LOOP. In this case, you delete the current line.
Syntax
DELETE <itab> [FROM <n1>] [TO <n 2>] [WHERE <cond>].
The system deletes all of the lines of <itab> whose index lies between <n 1 > and <n 2 > and who meet the conditions specified in the WHERE clause. If you do not specify a FROM addition, the system deletes lines from the first line onwards. If you do not specify a TO addition, the system deletes lines up to the last line. The logical condition can consist of more than one comparison. In each comparison, the first operand must be a component of the line structure.
FREE
Release space in memory.
Syntax
FREE <itab>.
FREE MEMORY ID(<key>).
FREE OBJECT <obj>.
This statement deletes an internal table, a data cluster in ABAP memory, or an external object in OLE2 Automation, depending on the variant of the statement used.
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>.
hope it will be useful.
Regards,
Priya.
2008 Feb 25 10:07 AM
Hi,
Refresh is used with an internal table usually to refresh the internal table ie, to make it initial.It is usually done at the beginning before using that internal table for the first time.
EQ. refresh t_itab.
Clear is used with a work area or variables.It is also used at the beginning ie before using it for the first time in the code and in the end and sometimes within the loop for every loop pass.
EQ. clear wa_itab.
clear w_matnr.
Delete is used to delete a particular row in table .
FREE f has the same effect as CLEAR f , namely that a Data object f is reset to the initial value corresponding to its type.
Unlike CLEAR, FREE also releases any resources taken up by the data object f. FREE can also release more resources than CLEAR for table work areas declared using the TABLES statement.
After FREE f, the data object f can be re-addressed at any time. The only condition is that you may need to re-allocate resources to the object.
Reward points if useful.
Regrads,
Sowmya.
2008 Feb 25 10:10 AM
Clear itab:Will clear header of internal table
Clear itab [ ] : Will clear body of table.
Refresh itab : Will remove contents of internal table.
Fee itab: Will de-allocate memory associated with internal table.
Delete: delete table itab index 3.
(Will delete record with index 3)
2008 Feb 25 10:14 AM
Hi,
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.
FREE
Releases memory space.
Syntax
FREE <itab>.
FREE MEMORY ID(<key>).
FREE OBJECT <obj>.
This statement deletes an internal table, a data cluster in ABAP memory, or an external object in OLE2 Automation, depending on the form of the statement used. It also releases the memory occupied by the object.
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.
Ex.
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.
Deleting Lines
To delete a single line of any internal table, use the DELETE statement. You can either use the table key to find and delete a single line using its key, delete a set of lines that meet a condition, or find and delete neighboring duplicate entries. If the table has a non-unique key and there are duplicate entries, the first entry is deleted.
Deleting a Line Using the Table Key
To use the table key of table <itab> as a search key, use one of the following statements:
DELETE TABLE <itab> FROM <wa>.
or
DELETE TABLE <itab> WITH TABLE KEY <k1> = <f1> ... <kn> = <fn>.
In the first case, <wa> must be a work area compatible with the line type of <itab>. The values of the key fields are taken from the corresponding components of the work area.
In the second case, you have to supply the values of each key field explicitly. If you do not know the name of one of the key fields until runtime, you can specify it as the content of a field <ni> using the form (<ni>) = <fi>. If the data types of <fi> are not compatible with the key fields, the system converts them.
The system searches for the relevant lines as follows:
Standard tables
Linear search, where the runtime is in linear relation to the number of table entries.
Sorted tables
Binary search, where the runtime is in logarithmic relation to the number of table entries.
Hashed tables
The entry is found using the hash algorithm of the internal table. The runtime is independent of the number of table entries.
If the system finds a line, it deletes it from the table and sets SY-SUBRC to zero. Otherwise, SYSUBRC is set to 4. If the table has a non-unique key and the system finds duplicate entries, it deletes the first entry.
Deleting Several Lines Using a Condition
To delete more than one line using a condition, use the following statement:
DELETE <itab> WHERE <cond>.
This processes all of the lines that meet the logical condition <cond>. The logical condition can consist of more than one comparison. In each comparison, the first operand must
be a component of the line structure. If the table lines are not structured, the first operand can also be the expression TABLE LINE. The comparison then applies to the entire line. If at least one line is deleted, the system sets SY-SUBRC to 0, otherwise to 4.
Deleting Adjacent Duplicate Entries
To delete adjacent duplicate entries use the following statement:
DELETE ADJACENT DUPLICATE ENTRIES FROM <itab>
[COMPARING <f1> <f2> ...
|ALL FIELDS].
The system deletes all adjacent duplicate entries from the internal table <itab>. Entries are duplicate if they fulfill one of the following compare criteria:
Without the COMPARING addition, the contents of the key fields of the table must be identical in both lines.
If you use the addition COMPARING <f1> <f2> ... the contents of the specified fields <f1> <f2> ... must be identical in both lines. You can also specify a field <fi> dynamically as
the contents of a field <ni> in the form (<ni>). If <ni> is empty when the statement is executed, it is ignored. You can restrict the search to partial fields by specifying offset and length.
If you use the addition COMPARING ALL FIELDS the contents of all fields of both lines must be identical.
You can use this statement to delete all duplicate entries from an internal table if the table is sorted by the specified compare criterion. If at least one line is deleted, the system sets SY-SUBRC to 0, otherwise to 4.
Examples
DATA: BEGIN OF LINE,
COL1 TYPE I,
COL2 TYPE I,
END OF LINE.
DATA ITAB LIKE HASHED TABLE OF LINE WITH UNIQUE KEY COL1.
DO 4 TIMES.
LINE-COL1 = SY-INDEX.
LINE-COL2 = SY-INDEX ** 2.
INSERT LINE INTO TABLE ITAB.
ENDDO.
LINE-COL1 = 1.
DELETE TABLE ITAB: FROM LINE,
WITH TABLE KEY COL1 = 3.
LOOP AT ITAB INTO LINE.
WRITE: / LINE-COL1, LINE-COL2.
ENDLOOP.
Regards,
Bhaskar
2008 Feb 25 10:17 AM
Hi,
Please find the explanation below.
When you define a variable or a table in a program. And execute it the processor will allocate appropriate memory to the variable hope you know this.
Ex:
DATA : Variable(1) type c.
Then the processor will allocate memory(With memory ID Some say 412536) equal to size 1 character size.
Then if you assign a value for the above variable like
Variable = 'X'. the variable or memory id 412536 contains this 'X' value.
If you write:
1. FREE Variable.
The memory allocated is refreshed and freed. Means after this statement the memory to the variable is no more. It is freed from the program and can be used for some other program are purpose.
2. REFRESH i_tab.
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.
3. CLEAR variable .
it clears the memory of the variable i.e. variable will be empty.
4.DELETE variable or I_tab index i etc.
It deletes a specific value from a I_tab body based on condition.
Hope it is clear,
Thanks,
Surya
2008 Feb 25 10:21 AM
Hi
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.
Delete:
http://www.sts.tu-harburg.de/teaching/sap_r3/ABAP4/delete02.htm
Cheers,
vasavi
2008 Feb 25 10:25 AM
hi,
1.Free : It will delete the records and free the memory allocated to the Internal table .
2.Refresh : It will delete the records but memory will be there.
3.Clear : It will remove ecords present only in header , internal table records will be there in internal table.
4.Delete : delete the required records but memory will be there.
Regards,
kavitha
2008 Feb 25 10:38 AM
Hi
DELETE:to delete a record or records from an internal table.
syntax;
delete itab index i.
ex:
delete itab index 3.
then it deletes that particular third record from the internal table.
CLEAR:this is to clear the header lines.
syntax:
clear <itab>.
clears the header record.
clear <itab>[ ].
it clears the body of the internal table.
REFRESH:it clears the header record and all records in the body of the internal table.
syntax:
refresh itab.
FREE:it deallocates the memory of an internal table.
syntax:
free itab.
2008 Feb 25 10:46 AM
Hi ,
FREE
Release space in memory.
Syntax
FREE <itab>.
FREE MEMORY ID(<key>).
FREE OBJECT <obj>.
This statement deletes an internal table, a data cluster in ABAP memory, or an external object in OLE2 Automation, depending on the variant of the statement used.
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
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.
DELETE for Files
Deletes files on the application server
Syntax
DELETE DATASET <dsn>.
Deletes the file <dsn> from the file system of the application server.
DELETE for Database Table Entries
Deletes entries from database tables.
Syntax
DELETE FROM <dbtab> WHERE <cond>.
All of the lines in the database table that satisfy the conditions in the WHERE clause are deleted.
Syntax
DELETE <dbtab> FROM <wa>.
DELETE <dbtab> FROM TABLE <itab>.
This deletes the line that has the same primary key as the work area <wa>, or deletes all the lines in the database that have the same primary key as a line in the internal table <itab>. The work area <wa> or the lines of the internal table <itab> must have at least the same length as the work area of the database table.
DELETE for Cluster Databases
Deletes data clusters from cluster database tables.
Syntax
DELETE FROM DATABASE <dbtab>(<ar>) ID <key>.
Deletes the entire cluster in area <ar> with the name <key> from the cluster database table <dbtab>.
DELETE for the Cross-Transaction Application Buffer
Deletes data clusters from the cross-transaction application buffer.
Syntax
DELETE FROM SHARED BUFFER <dbtab>(<ar>) ID <key>.
Deletes the data cluster for the area <ar> with the name <key> stored in the cross-transaction application buffer for the table <dbtab>.
DELETE for Lines from an Internal Table
Deletes lines from internal tables of any type.
Syntax
DELETE TABLE <itab> FROM <wa>.
DELETE TABLE <itab> WITH TABLE KEY <k1> = <f 1>... <k n> = <f n>.
Deletes using the table key. All lines with the same key are deleted. The key values are taken either from a compatible work area <wa> or specified explicitly.
Syntax
DELETE <itab> WHERE <cond>.
Deletes using conditions. Deletes all table entries that satisfy the logical expression <cond>. The logical condition can consist of more than one comparison. In each comparison, the first operand must be a component of the line structure.
Syntax
DELETE ADJACENT DUPLICATE ENTRIES FROM <itab> [COMPARING... ].
Deletes adjacent duplicate entries, either by comparing the key fields or the comparison fields specified explicitly in the COMPARING addition.
DELETE for Lines from Index Tables
Deletes entries from index tables.
Syntax
DELETE <itab> [INDEX <idx>].
If you use the INDEX addition, the line with index <idx> is deleted from the table <itab>. Without the INDEX addition, you can only use the above statement within a LOOP. In this case, you delete the current line.
Syntax
DELETE <itab> [FROM <n1>] [TO <n 2>] [WHERE <cond>].
The system deletes all of the lines of <itab> whose index lies between <n 1 > and <n 2 > and who meet the conditions specified in the WHERE clause. If you do not specify a FROM addition, the system deletes lines from the first line onwards. If you do not specify a TO addition, the system deletes lines up to the last line. The logical condition can consist of more than one comparison. In each comparison, the first operand must be a component of the line structure.
Regards,
Subashini.
2008 Feb 25 10:57 AM
hi,
Use the free statement to delete all rows from an internal table and free the associated memory.
The following is the syntax for the free statement.
free it.
Use the refresh statement to delete all rows from an internal but leave the memory allocated.
The following is the syntax for the refresh statement.
refresh it.
You can use the clear statement to do either of the following:
Delete all rows from an internal table and release the memory allocated
Clear the header line (set its component to blanks and zeros).
clear it Clears the header line Deletes all rows
clear it[] Deletes all rows Deletes all rows
Using the delete statement, you can delete one or more rows from an internal table.
reward if its useful
2008 Feb 25 11:02 AM
FREE : It will de-allocates the memory. the whole internal table was seleted with data.
DELETE : It will delete the particular record or range of records in the internal table.
CLEAR : It will removes the data in the internal table header area.
CLEAR[] : It will removes the data in the internal table body area.
REFRESH : It will removes the data in the internal table body area.
2008 May 06 7:04 AM
Hi,
This is documentation regarding free refresh clear and delete...
If you want to delete just internal table body then use refresh itab.
or
clear itab[].
And want to clear itab and deallocate the memory also then
Free itab.
or
if you just want to clear header line then
clear itab.
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 should use only internal table,clear - you can use variables,internal table ,work areas
FREE : it is deallocating meomry .. so this memory can be utilize by other program..
DELETE : it is to delete the selected records.... It wont free the memory....
Hope this will be useful.....
| User | Count |
|---|---|
| 3 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |