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

how to use variable value as variable name

Former Member
0 Likes
979

Hi

I would like to know if is it possible to do something like follow: say I have a variable A with a value:

DATA A TYPE string VALUE 'VAR_X'.

What I need is to make a test on another variable of the program that is VAR_X. So the question is, how can I 'understand' value of A and use it as a variable name?

thank you

Gabriele

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
917

I know the functinality of field-symbols to make something similar.

DATA: l_string TYPE string.

  FIELD-SYMBOLS: <any> TYPE ANY.

  l_string = 'fieldname'.
  CONCATENATE 'strucname-' l_string INTO l_string.
  ASSIGN (l_string) TO <any>.

<any> contains now the value of strucname-fieldname. Maybe this is useful for you.

I do not know if this is just possible for structure or if it also works with simple variables.

Regards

EDIT: It works:

DATA: l_string TYPE string.
 
data: l_field type string value 'AAA'.
 FIELD-SYMBOLS: <any> type any.
 
l_string = 'l_field'.
ASSIGN (l_string) TO <any>.

write: <any>.

Output is 'AAA'.

Edited by: Maximilian Tews on Aug 1, 2011 3:25 PM

1 REPLY 1
Read only

Former Member
0 Likes
918

I know the functinality of field-symbols to make something similar.

DATA: l_string TYPE string.

  FIELD-SYMBOLS: <any> TYPE ANY.

  l_string = 'fieldname'.
  CONCATENATE 'strucname-' l_string INTO l_string.
  ASSIGN (l_string) TO <any>.

<any> contains now the value of strucname-fieldname. Maybe this is useful for you.

I do not know if this is just possible for structure or if it also works with simple variables.

Regards

EDIT: It works:

DATA: l_string TYPE string.
 
data: l_field type string value 'AAA'.
 FIELD-SYMBOLS: <any> type any.
 
l_string = 'l_field'.
ASSIGN (l_string) TO <any>.

write: <any>.

Output is 'AAA'.

Edited by: Maximilian Tews on Aug 1, 2011 3:25 PM