We are hiring and constantly growing! Have a look through our vacancies to find the right role for you!
Dynamic ASSIGN
4a. ASSIGN (f) TO <fs>.
4b. ASSIGN oref->(f) TO <fs>.
4c. ASSIGN (f1)=>(f2) TO <fs>.
4d. ASSIGN TABLE FIELD (f) TO
4e. ASSIGN LOCAL COPY OF MAIN TABLE FIELD (f) TO
4f. ASSIGN LOCAL COPY OF ... (f) TO <fs>.
Assigns a data object to a field symbol. When accessing reference variables, you can use the dynamic
ASSIGN to access dynamically the attributes of objects that are not known until runtime. For all variants, the return value is set as follows:
ASSIGN (f) TO <fs>.
The field whose name is stored in f is assigned to the field symbol. If this field cannot be found, the field symbol remains unchanged.
data WA_SPFLI type SPFLI.
field-symbols
field-symbols
data F1 type STRING.
data F2 type STRING.
F1 = 'WA_SPFLI'.
F2 = '
WA_SPFLI-CARRID = 'LH'.
assign (F1) to
if SY-SUBRC = 0.
assign (F2) to
if SY-SUBRC = 0.
write
endif.
endif.
In this example, the component carrid of the structure spfli is dynamically assigned to
the field symbol
class C1 definition.
public section.
data A1(16) type C value 'A1 in Class 1'.
methods M1.
endclass.
class C1 implementation.
method M1.
field-symbols <FS> type any.
data F type STRING.
F = 'A2'.
assign (F) to <FS>.
if SY-SUBRC = 0.
write <FS>.
endif.
endmethod.
endclass.
class C2 definition inheriting from C1.
public section.
data A2(16) type C value 'A2 in Class 2'.
endclass.
data O1 type ref to C1.
start-of-selection.
create object O1 type C2.
O1->M1( ).
This example program displays 'A2 in Class
2'. A reference variable of the static type C1 points to an object of the subclass C2.
In the method M1 of the superclass C1, the field F contains the value A2.
A2 is neither the name of a local data object, nor the name ofa statically visible attribute
of the class C1. Since there is no local field A2, the system implicitly uses the expression ME->A2 and finds the dynamically addressable attribute A2 of the subclass C2.
ASSIGN oref->(f) TO <fs>.
Dynamically accesses the attributes in objects. The field whose name is stored in the field f is used
as the name of the attribute when it is assigned to the field symbol. In principle, variant 4b is already
implicit in the previous variant, 4a, except that in variant 4b only the attribute name is declared dynamically, while the name of the object reference variable is declared statically.
For this reason, the same rules apply as in variant 4a, except that the search hierarchy is now simpler for those options pertaining to reference variables:
class C1 definition.
public section.
data A1(16) type C value 'A1 in Class 1'.
endclass.
class C2 definition inheriting from C1.
public section.
methods CONSTRUCTOR.
endclass.
class C2 implementation.
method CONSTRUCTOR.
A1 = 'A1 in Class 2'.
endmethod.
endclass.
field-symbols <FS> type any.
data OREF type ref to OBJECT.
data F type STRING.
start-of-selection.
F = 'A1'.
create object OREF type C1.
assign OREF->(F) to <FS>.
if SY-SUBRC = 0.
write / <FS>.
endif.
create object OREF type C2.
assign OREF->(F) to <FS>.
if SY-SUBRC = 0.
write / <FS>.
endif.
This example displays the value of the attribute A1 in the object of the class C1, then
does the same for the object of the class C2. The reference variable orefof the static
type object does not have any components of its own. However, dynamic access allows the system to access the attributes of the dynamic type.
ASSIGN (f1)=>(f2) TO <fs>.
Dynamically accesses the static attributes of classes. The fields whose names are stored in the fields
f1 and f2 are used as the name of the class and of the static attribute when the assignment
to the field symbol takes place. In principle, variant 4c is already implicit in variant 4a. However, in variant 4c, the name of the class and attribute can also be individually declared statically.
ASSIGN LOCAL COPY OF ... (f) TO <fs>.
Dynamic variant of the static statement: ASSIGN LOCAL COPY OF ... f TO
For more information on the exceptions that can be raised by the ASSIGN statement, see ASSIGN Exceptions.
Assigning Data Objects to Field Symbols.
Leave us your contact details and we will call you back. Fields marked with * are mandatory.
We offer holistic SAP solutions from a single source to shape digital change and develop new business areas.
Switzerland
Schaffhausen
Germany
Mannheim, Düsseldorf, Munich
USA
Haverhill
Greece
Thessaloniki