ASSIGN statement keyword in ABAP is used to assign the values to field symbols. A field symbol is just only a place holder with a symbolic name for other fields. It won’t contain any physical data, it just point to the area where the data is stored (Like pointer in C programming).
Different Syntax variation for the ASSIGN keyword
- ASSIGN f TO .
- ASSIGN (f) TO .
- ASSIGN TABLE FIELD (f) TO .
- ASSIGN LOCAL COPY OF MAIN TABLE FIELD (f) TO .
- ASSIGN COMPONENT idx OF STRUCTURE rec TO .
- ASSIGN COMPONENT name OF STRUCTURE rec TO
Here the first variation (ASSIGN f TO .) will store the contents of field f to the field symbol. In the second variation ( ASSIGN (f) TO .) the field symbol will be assigned with the field whose name is stored in the field f.
How to store structure components to a filed symbol
If we have structured data object <struct1> and <component1> is one of the subfield (component) of that structure. Now we can use following the statement to store that component in a Field Symbol <FS>
ASSIGN COMPONENT <component1> OF STRUCTURE <struct1> TO <FS>.
Normal using additions with ASSIGN
- TYPE typ
- DECIMALS dec
- LOCAL COPY OF
- SY-SUBRC = 0 (Successful)
- SY_SUBRC = 4 (failure)
Also Read : View Other ABAP Keywords & Syntax -> ABAP Transaction codes