ASSIGN für FIELD-SYMBOLS

Aus SAP Hilfe:

Static ASSIGN

If you already know the name of the field that you want to assign to the field symbol when you write a program, use the static ASSIGN statement:

ASSIGN dobj TO <fs>.

When you assign the data object, the system checks whether the technical attributes of the data object dobj correspond to the type specifications for the field symbol <fs>. The field symbol adopts any generic attributes of dobj that are not contained in its own type specification. After the assignment, it points to this field in the memory.

REPORT demo_field_symbols_stat_ASSIGN. 
FIELD-SYMBOLS: <f1> TYPE ANY, <f2> TYPE i. 
DATA:text(20)  TYPE c VALUE 'Hello, how are you?',      
 num TYPE i VALUE 5,      
 BEGIN OF line1,        
 col1 TYPE f VALUE '1.1e+10',        
 col2 TYPE i VALUE '1234',      
 END OF line1,      
 line2 LIKE line1. 
ASSIGN text TO <f1>. 
ASSIGN num TO <f2>. 
DESCRIBE FIELD <f1> LENGTH <f2>. 
WRITE:/<f1>, 'has length', num. 
ASSIGN line1 TO <f1>. 
ASSIGN line2-col2 TO <f2>. 
MOVE <f1> TO line2. 
ASSIGN 'LINE2-COL2 =' TO <f1>. 
WRITE:/<f1>, <f2>. 

The list output is:

Hello, how are you? has length 20

LINE-COL2 = 1,234 (One Thousand Two Houndred Thirty Four)

The example declares two field symbols <f1> and <f2>. <f2> may only have fields of type I since it has been typed accordingly. <f1> and <f2> both point to different fields during the program.