Skip to content

ABAP Keyword Documentation →  ABAP − Reference →  Processing Internal Data →  Assignments →  Initializations 

CLEAR

Quick 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-dependent 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 built-in ABAP types.
  • Enumerated variables are assigned to initial values in accordance with the elementary base type.
  • 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 statement FREE 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.


Notes

  • If dobj is an internal table with a header line, dobj[] must be specified to delete the rows, otherwise only the header line is deleted.
  • In the case of CLEAR, the initial memory requirements of an internal table are not released, which can have a positive effect on performance when inserting new rows in the internal table. The statement FREE is required only if it is as much memory as possible really needs to be released.

Example

After initialization with CLEAR, the internal table itab no longer contains any rows.

DATA itab TYPE STANDARD TABLE OF i WITH EMPTY KEY. 

itab = VALUE #( FOR i = 1 UNTIL i > 10 ( i ) ). 
ASSERT lines( itab ) = 10. 

CLEAR itab. 
ASSERT lines( itab ) = 0. 

Addition

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

Effect

If the addition WITH val is used and CHARACTER or BYTE MODE specified, all places 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 this is not the case, a syntax error occurs or a non-handleable exception is raised.


Note

If the obsolete addition WITH NULL is used, all bytes of a flat data object can be replaced by hexadecimal 0 outside classes.


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. 

cl_demo_output=>display( hexstring ). 

Exceptions

Non-Handleable 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