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

Compare Variable value in a Variable

Former Member
0 Likes
1,510

Hi,

I have Variable V2 populated into another Variable V1(not value, directly the variable name).

Now I have to check the value of Variable V2.

In my case the value in V2 can be 'X' or space.

So how to check the value of V2.

Is there anything like IF value(V1) = 'X' comparison.

Data is dynamically populated into V1 i.e., it can have 'V2', 'V3'...etc

Thanks & Regards,

Adithya M

1 ACCEPTED SOLUTION
Read only

Florian
SAP Champion
SAP Champion
0 Likes
933

Hi Adithya,

your problem can be solved by using the assigning statement.

See this link to the help-site:

Assigning Components of Structures to a Field Symbol (SAP Library - ABAP Programming (BC-ABA))

Here is the copy-paste coding from the site:

DATA: BEGIN OF LINE,
        COL1 TYPE I VALUE '11',
        COL2 TYPE I VALUE '22',
        COL3 TYPE I VALUE '33',
      END OF LINE.

DATA COMP(5) VALUE 'COL3'.

FIELD-SYMBOLS: <F1>, <F2>, <F3>.

ASSIGN LINE TO <F1>.
ASSIGN COMP TO <F2>.

DO 3 TIMES.
  ASSIGN COMPONENT SY-INDEX OF STRUCTURE <F1> TO <F3>.
  WRITE <F3>.
ENDDO.

ASSIGN COMPONENT <F2> OF STRUCTURE <F1> TO <F3>.
WRITE / <F3>.


The output is:

11         22         33

33

Have fun

~Florian

2 REPLIES 2
Read only

Florian
SAP Champion
SAP Champion
0 Likes
934

Hi Adithya,

your problem can be solved by using the assigning statement.

See this link to the help-site:

Assigning Components of Structures to a Field Symbol (SAP Library - ABAP Programming (BC-ABA))

Here is the copy-paste coding from the site:

DATA: BEGIN OF LINE,
        COL1 TYPE I VALUE '11',
        COL2 TYPE I VALUE '22',
        COL3 TYPE I VALUE '33',
      END OF LINE.

DATA COMP(5) VALUE 'COL3'.

FIELD-SYMBOLS: <F1>, <F2>, <F3>.

ASSIGN LINE TO <F1>.
ASSIGN COMP TO <F2>.

DO 3 TIMES.
  ASSIGN COMPONENT SY-INDEX OF STRUCTURE <F1> TO <F3>.
  WRITE <F3>.
ENDDO.

ASSIGN COMPONENT <F2> OF STRUCTURE <F1> TO <F3>.
WRITE / <F3>.


The output is:

11         22         33

33

Have fun

~Florian

Read only

Former Member
0 Likes
933

Thank you Florian.

It got resolved by the below way,

If V1 & V2 are variables

FIELD-SYMBOLS: <FS> TYPE any.

V2 = 'X'

V1 = 'V2'.

ASSIGN (V1) TO <FS>.

If <FS> is ASSIGNED then <FS> will be having its value as 'X'.