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) }
| { (class_name)=>(attr_name) }
| { (class_name)=>attr }
| { class=>(attr_name) } ... .

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

What does it do? These alternatives to specifying the memory area mem_area of the statement ASSIGN dynamically are designed especially for dynamic access to attributes of classes (Dynamic Access).

In an inline declaration of the field symbol using FIELD-SYMBOL(<(><<)>fs>), its typing is performed with the generic type data.

In these variants, the ASSIGN statement sets the return code sy-subrc. If the assignment is successful, sy-subrc is set to 0; if not, it is set to 4. If the assignment is not successful, the field symbol keeps its previous state. It is therefore not enough just to evaluate the predicate expression <(><<)>fs> IS ASSIGNED; sy-subrc needs to be checked as well.



Latest notes:Field symbols to which instance attributes (or parts of
instance attributes) are assigned have a memory-preserving affect on the associated object.

ABAP Alternative 1 ... cref->(attr_name)

What does it do? This form may be used for all visible attributes of objects. cref can be any class reference variable pointing to an object which contains the attribute specified in a character-like field attr_name. The system searches for the attribute first in the static type of cref and then in the dynamic type.

The attribute name does not need to be specified 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).

ABAP Alternative 2 ... iref->(attr_name)

What does it do? This form may be used for all visible interface attributes of objects. iref can be any interface reference variable pointing to an object which contains the interface attributes specified in a character-like field attr_name. The search for this method takes place only in the static type of iref.

The attribute name does not need to be specified 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).

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

ABAP Alternative 4 ... (class_name)=>attr

ABAP Alternative 5 ... class=>(attr_name)

What does it do? These forms may be used for all visible static attributes. Both the class and the attribute can be specified dynamically. It is also possible to specify the attribute attr and the class class directly.

If the alternatives with dynamically specified class (class_name) are used, the system first searches for the class and then for the attribute. If the static specification class is used, the system searches for the attribute in the existing class.

The content of attr_name and class_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, to assign parts of attributes or referenced objects of attributes. If the class name is specified dynamically and the attribute directly, no offsets/lengths or object component selectors can be specified behind the attribute.



Latest notes:If, in class_name, a class of another program is
specified 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 not already loaded). If required, the program constructor is also executed.



Example ABAP Coding
Dynamic access to an attribute of an object using a
field symbol. CLASS c1 DEFINITION.
PUBLIC SECTION.
METHODS m1 IMPORTING oref TYPE REF TO object
attr TYPE string.
ENDCLASS.

CLASS c1 IMPLEMENTATION.
METHOD m1.
FIELD-SYMBOLS <(><<)>attr> TYPE ANY.
ASSIGN oref->(attr) TO <(><<)>attr>.
cl_demo_output=>display_data( <(><<)>attr> ).
ENDMETHOD.
ENDCLASS.

Return to menu