Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Memory reference of a Variable possible?

former_member214878
Active Participant
0 Kudos

Hello,

I am in middle of something where I need to get the value of a variable by referencing it.

For example -

Data: gv_var_val           type c length 1,

          gv_var_name      type c length 10.   

At run-time I will have gv_var_name = 'GV_VAR_VAL'. but I will need to get the value of a "GV_VAR_VAL" which might be 0/1/2/3......

I tried field-symbols but failed to manage it properly ....

can u please assist me a little?

Thanks,

Ravi Sonar.

1 ACCEPTED SOLUTION

raymond_giuseppi
Active Contributor
0 Kudos

Just use

DATA: gv_var_val  TYPE c LENGTH 1,
       gv_var_name TYPE c LENGTH 10.
FIELD-SYMBOLS <fs> TYPE ANY.
gv_var_val = 'A'.
gv_var_name = 'GV_VAR_VAL'.
ASSIGN (gv_var_name) TO <fs>.
WRITE: / <fs>.

Regards,

Raymond

6 REPLIES 6

FredericGirod
Active Contributor
0 Kudos

move 'GV_VAR_VAL' to w_field   (char 20).

assign (w_field) to <field>

and now <field> contain the value of GV_VAR_VAL.

regards

Fred

jayanthi_jayaraman
Active Contributor
0 Kudos

Hi,

As suggested, using assign statement with () will help you to get value.

Former Member
0 Kudos

Hi Ravindra,

Field symbols are the direct memory locations for the values of the field.These are just like pointers.

so by using field symbols you can achieve it.

Thanks & Regards,

Pavan.N

raymond_giuseppi
Active Contributor
0 Kudos

Just use

DATA: gv_var_val  TYPE c LENGTH 1,
       gv_var_name TYPE c LENGTH 10.
FIELD-SYMBOLS <fs> TYPE ANY.
gv_var_val = 'A'.
gv_var_name = 'GV_VAR_VAL'.
ASSIGN (gv_var_name) TO <fs>.
WRITE: / <fs>.

Regards,

Raymond

0 Kudos

Thanks Frederic, thanks Raymond.....

Was confused in Round Brackets

Solved....

former_member214878
Active Participant
0 Kudos

Another way of doing it


DATA: DREF      TYPE REF TO CHAR5,
          DATA       TYPE C LENGTH 5 VALUE 'TEXT1'.



   GET REFERENCE OF DATA INTO DREF.



   WRITE / DREF->*.