Skip to content

ABAP Keyword Documentation →  ABAP - Reference →  Assignments →  Initializations 

CLEAR

Short Reference

Other versions: 7.31 | 7.40 | 7.54

Syntax


CLEAR dobj [ {WITH val [IN {CHARACTER|BYTE} MODE] } 
           | {WITH NULL} ].

Addition

... WITH val [IN {CHARACTER|BYTE} MODE]

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 INITIAL SIZE). 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

... WITH val [IN {CHARACTER BYTE} MODE]

Effect

If you use the WITH val addition and specify CHARACTER or BYTE MODE, all spaces are replaced either with the first character or the first byte in val. In val a functional operand position is involved. If dobj is of the type string or xstring, the string is processed in its current length.

When the MODEaddition is not specified, the IN CHARACTER MODE addition applies. Depending on the addition, the operand dobj must be either character-type or byte-type and the data object val must be either character-type or byte-type and have the length 1. 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.


Note

An obsolete addition WITH NULL can also be used outside of classes to replace all bytes in a flat data object with hexadecimal 0.


Example

The byte string hexstring as assigned a specific byte value over the entire current length.

DATA: hexstring TYPE xstring, 
      hex       TYPE x LENGTH 1 VALUE 'FF'. 
... 
hexstring = '00000000'. 
... 
CLEAR hexstring WITH hex IN BYTE MODE. 

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