"Transfer from http://blog.csdn.net/forever_crazy/article/details/6544830"
Requirements: Sometimes write a program, you need to assign a dynamic variable operation, when the field is a long time, if the regular method of assigning value will appear to be very redundant code, in fact, can be assigned by the indirect address of the variable.
EX1:
Data c1 type CHAR10.
Data c2 type Char10.
Field-symbols <fs> Type any.
C1 = ' C2 '. Note: The variable "C2" to be assigned at this point must be capitalized, because in the ABAP internal variable names are saved in uppercase format.
C2 = ' test1 '.
Assign (C1) to <fs>.
<fs> = ' test2 '.
The contents of the variable C2 are then ' test2 ' by ' test1 '.
This method is suitable for use when multiple variables are to be dynamically assigned.
Here's an example: Click the button to set the button text to ' Test '.
Data ok_code type Sy-ucomm.
Data l_but type Char10.
Field-symbols <fs> Type any.
Parameters
Pushbutton 2 (Ten) PB1 User-command PB1,
Pushbutton (Ten) Pb2 User-command PB2,
Pushbutton (Ten) pb3 User-command pb3,
Pushbutton (Ten) pb4 User-command pb4.
At Selection-screen.
Ok_code = Sy-ucomm.
L_but = Ok_code.
Assign (l_but) to <fs>.
<fs> = ' Test '.
This method reduces the need to judge each button and assigns values, reducing the redundancy of the code.
ABAP assigns a value to a dynamic variable