ABAPASSIGN_MEM_AREA_DYNAMIC_ACCESS - ASSIGN MEM AREA DYNAMIC ACCESS
Vendor Master (General Section) BAL Application Log DocumentationThis documentation is copyright by SAP AG.
ASSIGN - dynamic_access
Syntax
... { cref->(attr_name) }
| { iref->(attr_name) }
| { (class_name)=>(attr_name) }
| { (class_name)=>attr }
| { class=>(attr_name) } ... .
Alternatives:
1. ... cref->(attr_name)
2. ... iref->(attr_name)
3. ... (class_name)=>(attr_name)
4. ... (class_name)=>attr
5. ... class=>(attr_name)
Effect
These alternatives of dynamically specifying the memory area mem_areaof the statement ASSIGN are especially designed for dynamic access to attributes of classes (Dynamic Access).
In these variants, the statement ASSIGN sets the return value sy-subrc. If the assignmentis successful, sy-subrc is set to 0, otherwise to 4. If the assignment is not successful, thefield symbol retains its previous state. The evaluation of the logical expression <fs>IS ASSIGNED is therefore not sufficient: it needs to be sy-subrc checked.
Alternative 1
... cref->(attr_name)
Effect
This form may be used for all visible attributes of objects. cref can be anyclass reference variable pointing to an object that contains the attribute specified in a character-like field attr_name. The system searches for the attribute first in thestatic type and then in thedynamic type of cref.
The attribute name does not have to be specified in uppercase. It can contain offset/length specifications,and selectors for structure components, object components, and class components to assign parts or referenced objects of the attribute.
Alternative 2
... iref->(attr_name)
Effect
This form may be used for all visible interface attributes of objects. iref can be anyinterfacereference variable pointing to an object that contains the interface attributes specified in a character-like field attr_name. The system searches for the method only in thestatic type of iref.
The attribute name does not have to be specified in uppercase. It can contain offset/length specifications,and selectors for structure components, object components, and class components to assign parts or referenced objects of the attribute.
Alternative 3
... (class_name)=>(attr_name)
Alternative 4
... (class_name)=>attr
Alternative 5
... class=>(attr_name)
Effect
These forms may be used for all visible static attributes. You can specify both the class and the attribute dynamically. It is also possible to specify the attribute attr and the class class directly.
If you use the alternatives with dynamic class specification (class_name), the system first searchesfor the class and then the attribute. If you use the static specification class, the system searches for the attribute in the existing class.
The contents of attr_name and class_name do not have to be specified in uppercase. attr_namecontain offset/length specifications, and selectors for structure components, object components, andclass components to assign parts or referenced objects of the attribute. If you specify the class namedynamically and the attribute directly, you cannot make any offset/length specifications after the attribute, and cannot specify an object component selector.
Note
If a class of a different program is specified in class_name using anabsolute type name, then it is loaded, depending on the program type, to a newadditional program group or in the currentprogram group, if it was not yet loaded. Theprogram constructor may also be executed when this is done.
Example
Dynamic access to an attribute of an object (dynamic access) 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>.
WRITE <attr> ...
ENDMETHOD.
ENDCLASS.
PERFORM Short Reference Vendor Master (General Section)
This documentation is copyright by SAP AG.
Length: 6952 Date: 20120518 Time: 192710 triton ( 244 ms )






