SAP CLEAR ABAP Statements

Get Example source ABAP code based on a different SAP table
  


Standard SAP Help for CLEAR

CLEAR

Short Reference
• CLEAR ABAP Statement


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

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

What does it do? 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 table 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.



Latest notes: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.
• WITH CLEAR
• IN BYTE MODE CLEAR
• IN CHARACTER MODE CLEAR

ABAP Addition

What does it do? 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 dobj and val do not have the correct type and the correct length in a non- Unicode program, they are still handled appropriately regardless of the actual type. In Unicode programs, this produces a syntax error or raises a non-handleable exception.



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



Example ABAP Coding
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.



Runtime Exceptions
Non-catchable Exceptions
Reason for error:
Field val does not have length 1 for variant CLEAR fld WITH val IN BYTE MODE.
Runtime error:
CLEAR_VALUE_BYTEMODE_WRONG_LEN
Reason for error:
Field val does not have length 1 for variant CLEAR fld WITH val [IN CHARACTER MODE].
Runtime error:
CLEAR_VALUE_WRONG_LENGTH

Return to menu