Application Development and Automation 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: 
Read only

Memory reference of a Variable possible?

former_member214878
Active Participant
0 Likes
1,216

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
Read only

RaymondGiuseppi
Active Contributor
0 Likes
1,162

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
Read only

FredericGirod
Active Contributor
0 Likes
1,162

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

Read only

jayanthi_jayaraman
Active Contributor
0 Likes
1,162

Hi,

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

Read only

Former Member
0 Likes
1,162

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

Read only

RaymondGiuseppi
Active Contributor
0 Likes
1,163

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

Read only

0 Likes
1,162

Thanks Frederic, thanks Raymond.....

Was confused in Round Brackets

Solved....

Read only

former_member214878
Active Participant
0 Likes
1,162

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->*.