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

Relational operator to check multiple values in a constant variable

rnb86
Participant
0 Likes
4,374

Hi Experts,

i have a question on the relational operator. My scenario is

Constants c_var1(14) value 'A, AX,B,BX, G,GX'. -


> Is this declaration correct?

DATA VAR2(2) VALUE 'B'.

IF C_VAR1 CA VAR2.

WRITE:/ ' SUCCESS'.

ELSE.

WRITE:/ ' FAILURE'.

ENDIF.

I NEED TO VALIDATE THE VALUES DEFINED IN THE CONSTANT VARIABLE.

WHICH RELATIONAL OPERATOR IS THE CORRECT ONE FOR verifying?

is it CO,CN,CA,NA, CS,NS,CP,NP?

Thanks.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
2,213

Code :


CONSTANTS : c_test(10) TYPE c VALUE 'A,BX,C,DX'.
DATA : c_comp(2) TYPE c.

c_comp = 'BX'.

IF c_test CS c_comp.
  WRITE : 'Success'.
ELSE.
  WRITE : 'Failure'.
ENDIF.

You should use CS to find out if a string if present in any other string.

Hi Experts,

i have a question on the relational operator. My scenario is

Constants c_var1(14) value 'A, AX,B,BX, G,GX'. -


> Is this declaration correct?

DATA VAR2(2) VALUE 'B'.

IF C_VAR1 CA VAR2.

WRITE:/ ' SUCCESS'.

ELSE.

WRITE:/ ' FAILURE'.

ENDIF.

I NEED TO VALIDATE THE VALUES DEFINED IN THE CONSTANT VARIABLE.

WHICH RELATIONAL OPERATOR IS THE CORRECT ONE FOR verifying?

is it CO,CN,CA,NA, CS,NS,CP,NP?

Thanks.

8 REPLIES 8
Read only

Former Member
0 Likes
2,214

Code :


CONSTANTS : c_test(10) TYPE c VALUE 'A,BX,C,DX'.
DATA : c_comp(2) TYPE c.

c_comp = 'BX'.

IF c_test CS c_comp.
  WRITE : 'Success'.
ELSE.
  WRITE : 'Failure'.
ENDIF.

You should use CS to find out if a string if present in any other string.

Read only

0 Likes
2,212

Pramod,

you are correct. But the condition you mentioned in your code fails if the value of string is 'X'.

There are values A,AX,B,BX,G,GX for the constant.

if the char variable has a value just X, then the condition is satisfied. This should not happen.

We should not get the SUCCESS message for any other value execpt for A,AX,B,BX,G,GX.

Please let me know.

Read only

0 Likes
2,212

Hi,

Check this,


CONSTANTS : c_test(10) TYPE c VALUE 'A,BX,C,DX'.
DATA : c_comp(2) TYPE c.

c_comp = 'X'.

IF c_comp CO c_test.
  WRITE : 'Success'.
ELSE.
  WRITE : 'Failure'.
ENDIF.

Read only

0 Likes
2,212

use CS

Read only

0 Likes
2,212

Hi, RNB

Use the Logic Bellow it will work for you, it is working fine for Single X

CONSTANTS : c_test(12) TYPE c VALUE ',A,BX,C,DX,'.
DATA : c_comp(4) TYPE c.

c_comp = 'X'.
CONCATENATE ',' c_comp ',' into c_comp.
find FIRST OCCURRENCE OF c_comp in c_test.

IF sy-subrc = 0.
  WRITE : 'Success'.
ELSE.
  WRITE : 'Failure'.
ENDIF.

Faisal

Read only

0 Likes
2,212

Faisal / Pramod / Soumya / Vikranth,

Faisal's answer is perfect. Thanks Faisal. it is resolved now. CS works, but it will fails if the search is done using only X. this is not correct.

Thanks all for the replys.

Read only

Former Member
0 Likes
2,212

Deleted

Read only

Former Member
0 Likes
2,212

Hit F1 on any of these relational operators. You will get detailed explanation with examples on each of operators.