CLEAR (ABAP Keyword)

CLEAR (ABAP Keyword) introduction & details

CLEAR

Basic
form
CLEAR f.

 

Additions

1. … WITH g
2. … WITH
NULL

Effect
Resets the contents of f to its initial value.

For
predefined types (see DATA ), the following initial values are used:
Type C :
‘ … ‘ (blank character) Type N : ’00…0’ Type D : ‘00000000’ Type T :
‘000000’
Type I : 0 Type P : 0 Type F : 0.0E+00 Type X : 0
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.

Example

DATA: TEXT(10) VALUE ‘Hello’,
NUMBER TYPE I
VALUE 12345,
ROW(10) TYPE N VALUE ‘1234567890’,
BEGIN OF
PLAYER,
NAME(10) VALUE ‘John’,
TEL(8) TYPE N VALUE ‘08154711’,
MONEY
TYPE P VALUE 30000,
END OF PLAYER.

CLEAR: TEXT, NUMBER,
PLAYER.

The field contents are now as follows:

ROW =
‘1234567890’
TEXT = ‘ ‘
NUMBER = 0
PLAYER-NAME = ‘ ‘
PLAYER-TEL =
‘00000000’
PLAYER-MONEY = 0

Notes
When CLEAR references an internal
table itab with a header line, it only resets the sub-fields 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 . Here, a Note is still
required to explain how to manipulate tables with/without header
lines.
Within a logical expression , you can use f IS INITIAL to check that
the field f contains the initial value appropriate for its type.
Variables
are normally initialized according to their type, even if the specification of
an explicit initial value (addition ” … VALUE lit ” of the DATA statement) is
missing. For this reason, it is not necessary to initialize variables again with
CLEAR after defining them.

Addition 1
… WITH g

Effect
The
field f is filled with the value of the first byte of the field g
.

Addition 2
… WITH NULL

Effect
Fills the field with
hexadecimal zeros.

Note
You should use this addition with particular
care because the fields of most data types thus receive values which are really
invalid.

Note
Performance
CLEAR requires about 3 msn (standardized
microseconds) of runtime to process a field of type C with a length of 10 and
about 2 msn to process a field of the type I. To delete an internal table with
15 fields, it needs about 5 msn.

More References