Get Example source ABAP code based on a different SAP table
ARTICLE
Syntax Revisions for Field Symbols ABAP Code Snippet ARTICLE
Cannot Use Field Symbols As Class Components You cannot declare field symbols as components of classes in the declaration part of the class definition. However, you can create local field symbols within methods.
In the declaration part of the class, the following statement causes an error message::
FIELD-SYMBOLS ...
Correct syntax:
DATA ... TYPE REF TO ... or ALIASES ...
Cause:
The only components allowed in classes are attributes, methods, and events. Field symbols are symbolic names for other fields. They work by means of value semantics. Their role as pointers is now performed in ABAP Objects by reference variables. Their role as symbolic names has now been replaced by aliases. ABAP Code Snippet ABAP Code Snippet ARTICLE
No field symbols without type assignment In ABAP Objects the addition TYPE in the statement FIELD-SYMBOLS is mandatory.
Error message in ABAP Objects if the following syntax is used:
FIELD-SYMBOLS <(><<)>fs>.
Correct syntax:
FIELD-SYMBOLS <(><<)>fs> TYPE ANY.
Reason:
Like method interface parameters, field symbols must always have explicit type assignments. ABAP Code Snippet ABAP Code Snippet ARTICLE
No obsolete castings with ASSIGN In ABAP Objects you are not allowed to use the additions TYPE and DECIMALS for assigning data objects to field symbols using ASSIGN.
Error message in ABAP Objects if the following syntax is used:
ASSIGN f TO <(><<)>fs> TYPE ... [DECIMALS ...].
Correct syntax:
ASSIGN f TO <(><<)>fs> CASTING TYPE|LIKE ...
Reason:
The TYPE and DECIMALS additions have been replaced by the addition CASTING [TYPE|LIKE]. Unlike the TYPE addition, CASTING supports any data type. ABAP Code Snippet ABAP Code Snippet ARTICLE
No Obsolete Casting in FIELD-SYMBOLS In ABAP Objects the STRUCTURE addition is not allowed in the FIELD-SYMBOLS statement.
In ABAP Objects, the following statement causes an error message:
FIELD-SYMBOLS <(><<)>fs> STRUCTURE struc DEFAULT f.
Correct syntax:
FIELD-SYMBOLS <(><<)>fs> TYPE|LIKE struc.
ASSIGN f TO <(><<)>fs> CASTING.
Reason:
Field symbols defined with the STRUCTURE addition are a mixture of field symbols whose type is defined and a tool for casting on data types defined in the ABAP Dictionary or locally in the program. The types of field symbols are defined with the TYPE addition of the FIELD-SYMBOLS statement and the CASTING addition of the ASSIGN statement can be used for the casting. ABAP Code Snippet ABAP Code Snippet ARTICLE
No local copies using ASSIGN In ABAP Objects it is not possible to use field symbols in procedures to work with copies of other data.
Error message in ABAP Objects if the following syntax is used:
ASSIGN LOCAL COPY OF INITIAL f TO <(><<)>fs>.
ASSIGN LOCAL COPY OF f TO <(><<)>fs>.
Correct syntax:
DATA dref TYPE REF TO data. CREATE DATA dref LIKE f. ASSIGN dref->* TO <(><<)>fs>.
DATA dref TYPE REF TO data. CREATE DATA dref LIKE f. ASSIGN dref->* TO <(><<)>fs>. <(><<)>fs> = f.
Reason:
Due to the introduction of the general data references concept, the addition LOCAL COPY of the statement ASSIGN is obsolete. The value of f can be copied using the assigment <(><)> = f after ASSIGN. ABAP Code Snippet ABAP Code Snippet ARTICLE
No search limitations with dynamic ASSIGN The search limited to table work areas of the main program in connection with the dynamic ASSIGN statement is no longer used in ABAP Objects.
Error message in ABAP Objects in the following case:
ASSIGN TABLE FIELD (<(><)>) TO <(><)>.
Correct syntax:
ASSIGN (<(><)>) TO <(><)>.
Cause:
Table work areas are not supported in classes. ABAP Code Snippet