SAP ASSIGN MEM AREA DYNAMIC ACCESS ABAP Statements



Get Example source ABAP code based on a different SAP table
  



ASSIGN, dynamic_access
Short Reference

ABAP_SYNTAX
... ${ cref->(attr_name) $}
$| ${ iref->(attr_name) $}
$| ${ (clif_name)=>(attr_name) $}
$| ${ (clif_name)=>attr $}
$| ${ clif=>(attr_name) $} ...

ABAP_ALTERNATIVES:
1 ... cref->(attr_name)
2 ... iref->(attr_name)
3 ... (clif_name)=>(attr_name)
4 ... (clif_name)=>attr
5 ... clif=>(attr_name)

What does it do?
These variants for specifying the memory area mem_area of the statement ASSIGN dynamically are designed especially for dynamic access to attributes of classes or interfaces (Dynamic Access). The same syntax as alternatives 1 and 2 is also possible for components of structures.
In an inline declaration of the field symbol using FIELD-SYMBOL(<(><)>), its typing is performed with the generic type data.
In these variants, the statement ASSIGN sets the return code sy-subrc. If the assignment is successful, sy-subrc is set to 0. If the assignment is not successful, sy-subrc is set to 4. In these variants, no exception occurs in case of an unsuccessful assignment. If sy-subrc is set to 4, the state of the field symbol depends on the addition ELSE UNASSIGN:
If ELSE UNASSIGN is not specified, the field symbol keeps its previous state.
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.



Latest notes:

Field symbols to which instance attributes or parts of instance attributes are assigned have a memory-preserving effect on the associated object.
If ELSE UNASSIGN is not specified, it is not sufficient to evaluate the predicate expression <(><)> IS ASSIGNED but sy-subrc must be checked. If ELSE UNASSIGN is specified, the predicate expression as well as sy-subrc can be evaluated.
NON_V5_HINTS
ABAP_HINT_END

ABAP Alternative 1 ... cref->(attr_name)
BEGIN_SECTION ID ASSIGN-DYNAMIC-OREF

What does it do?
This form is possible for all visible attributes of objects. cref can be any class reference variable that points to an object that contains the attribute specified in a character-like field attr_name. The attribute is searched for first in the static type of cref and then in the dynamic type .
The attribute name does not have to be in uppercase letters. It can contain offsets/lengths, structure component selectors, object component selectors, and class component selectors, in order to assign parts of the attribute or referenced objects of the attribute.
Unlike all other operand positions, where an object reference that does not point to an object raises an exception, no exception occurs in the statement ASSIGN and sy-subrc is set to 4.
BEGIN_SECTION SAP_INTERNAL_HINT
The exception is either the uncatchable OBJECTS_OBJREF_NOT_ASSIGNED or the catchable CX_SY_ASSIGN_ILLEGAL_COMPONENT. The latter is raised for a dynamic target.
END_SECTION SAP_INTERNAL_HINT

ABAP_EXAMPLE_VX5
Dynamic assignment of an object attribute of an object to a field symbol. The assignment is made via an object reference variable of the static type of the root class object, which can point to any object.
ABEXA 00025
ABAP_EXAMPLE_END

ABAP_EXAMPLE_VX5
Behavior for an initial reference. No exception occurs but sy-subrc is set to 4 for dynamic access.
ABEXA 01599
ABAP_EXAMPLE_END
END_SECTION ID ASSIGN-DYNAMIC-OREF

ABAP Alternative 2 ... iref->(attr_name)
BEGIN_SECTION ID ASSIGN-DYNAMIC-OREF

What does it do?
This form may be used for all interface attributes of objects. iref can be any interface reference variable that points to an object that contains the interface attribute specified in a character-like field attr_name . The attribute is searched for only in the static type of iref.
The attribute name does not have to be in uppercase letters. It can contain offsets/lengths, structure component selectors, object component selectors, and class component selectors, in order to assign parts of the attribute or referenced objects of the attribute.
Unlike all other operand positions, where an object reference that does not point to an object raises an exception, no exception occurs in the statement ASSIGN and sy-subrc is set to 4.
BEGIN_SECTION SAP_INTERNAL_HINT
The exception is either the uncatchable OBJECTS_OBJREF_NOT_ASSIGNED or the catchable CX_SY_ASSIGN_ILLEGAL_COMPONENT. The latter is raised for a dynamic target.
END_SECTION SAP_INTERNAL_HINT

ABAP_EXAMPLE_VX5
Dynamic assignment of an object attribute to a field symbol. The assignment is made via an interface reference variable.
ABEXA 00026
ABAP_EXAMPLE_END
END_SECTION ID ASSIGN-DYNAMIC-OREF

ABAP Alternative 3 ... (clif_name)=>(attr_name)

ABAP Alternative 4 ... (clif_name)=>attr
BEGIN_SECTION ID ASSIGN-DYNAMIC-CLIF

What does it do?
These forms may be used for all visible static attributes. Classes and interfaces and also attributes can be specified dynamically in character-like fields clif_name or attr_name. The attribute attr can, however, also be specified directly. The system searches for the class or interface first and then the attribute.
The content of attr_name and clif_name does not have to be in uppercase letters. attr_name can contain offsets/lengths, structure component selectors, object component selectors, and class component selectors, in order to assign parts of the attribute or referenced objects of the attribute. Here, no offsets/lengths or object component selectors can be specified after a directly specified attribute attr.



Latest notes:

NON_V5_HINTS
If a class of another program is specified in clif_name using an absolute type name, this program is loaded into a new additional program group or into the current program group, depending on the program type, if it has not yet been loaded. If required, the program constructor is also executed in this case.
ABAP_HINT_END
END_SECTION ID ASSIGN-DYNAMIC-CLIF

ABAP Alternative 5 ... clif=>(attr_name)
BEGIN_SECTION ID ASSIGN-DYNAMIC-CREF

What does it do?
This form may be used for all visible static attributes. The class or interfaces is specified directly, and the attribute specified dynamically in a character-like field attr_name. The system searches for the attribute in the specified class or interface.
The content of attr_name does not have to be in uppercase letters. attr_name can contain offsets/lengths, structure component selectors, object component selectors, and class component selectors, in order to assign parts of the attribute or referenced objects of the attribute.

ABAP_EXAMPLE_VX5
Different dynamic assignments of a static class attribute to field symbols.
ABEXA 00027
ABAP_EXAMPLE_END
END_SECTION ID ASSIGN-DYNAMIC-CREF

Return to menu