SAP ASSIGN ELSE UNASSIGN ABAP Statements



Get Example source ABAP code based on a different SAP table
  


• ELSE UNASSIGN ASSIGN

ASSIGN, ELSE UNASSIGN
Short Reference

ABAP_SYNTAX
... ELSE UNASSIGN ...

What does it do?
This addition to the statement ASSIGN unassigns the field symbol if the assignment is not successful. The addition can be specified for the following variants of the ASSIGN statement:
dynamic assignments
assignments of dynamic components
dynamic access
ABAP Alternative 3@3@>assignment of a table expression
These variants set sy-subrc. If the assignment is not successful, and sy-subrc is set to 4 or 8, then:
If ELSE UNASSIGN is specified, no memory area is assigned to the field symbol. The field symbol has the state unassigned after the ASSIGN statement.
If ELSE UNASSIGN is not specified, the field symbol keeps its previous state.



Latest notes:

For the static variant of the ASSIGN statement, the addition ELSE UNASSIGN is implicitly set and cannot be used explicitly.
Using the addition for the variants listed above harmonizes their behavior with the behavior of the static variant.
Setting a field symbol to unassigned in case of an unsuccessful assignment prevents unintentional use of a previous assignment.
Using the addition allows the success of the assignment to be checked using the predicate IS ASSIGNED as well as checking sy-subrc.
The assignment variants for constructor expressions ABAP Alternative 1@1@>NEW ABAP Alternative 2@2@> CASE are either successful or lead to an exception and the addition ELSE UNASSIGN is not possible.
If the addition is specified, but the assignment is interrupted by an exception and sy-subrc is not set, the field symbol keeps its previous state.
The addition is not possible for obsolete variants of the ASSIGN statement.
NON_V5_HINTS
ABAP_HINT_END

ABAP_EXAMPLE_VX5
After a successful assignment, the next assignment is not successful because of a wrong dynamic specification. sy-subrc is set to 4 and the field symbol that was assigned before is unassigned.
ABEXA 01602
ABAP_EXAMPLE_END

Return to menu