Skip to content

ABAP Keyword Documentation →  ABAP - Reference →  Processing Internal Data →  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, dobj is assigned the type-specific initial value. In the case of dobj, this is a result position, which means either a variable or a writable expression ´can be specified.

  • Elementary data types are assigned initial values in accordance with the tables of predefined ABAP types.
  • Reference variables are assigned the null reference.
  • Structures are set to their initial values component by component.
  • All rows in an internal table are deleted. This frees up the memory space required for the table, except for the initial memory requirement (see INITIAL SIZE). The FREE statement is used to release the memory space occupied by the rows of internal tables.

The optional additions enable dobj to be filled with values other than the initial value.


Note

If dobj is an internal table with a header line, dobj[] must be specified to delete the rows, otherwise only the header line will be deleted.

Addition

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

Effect

If the WITH val addition is used and CHARACTER or BYTE MODE specified, all spaces in dobj 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.

If the MODE addition is not specified, the addition IN CHARACTER MODE applies. Depending on the addition, the data object dobj must be either character-like or byte-like. Depending on the addition, the operand val must be character-like or byte-like and have the length 1. If not, a syntax error occurs or an unhandleable exception is raised.


Notes

  • If the obsolete addition WITH NULL is used, all bytes of a flat data object can be replaced by hexadecimal 0 outside classes.
  • In obsolete non-Unicode programs, dobj and val are cast to the expected type regardless of the actual type.

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