2009 Sep 18 12:20 PM
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.
2009 Sep 18 12:29 PM
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.
2009 Sep 18 12:29 PM
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.
2009 Sep 18 12:38 PM
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.
2009 Sep 18 12:50 PM
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.
2009 Sep 18 12:50 PM
2009 Sep 18 12:51 PM
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
2009 Sep 18 1:07 PM
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.
2009 Sep 18 12:36 PM
2009 Sep 18 12:37 PM
Hit F1 on any of these relational operators. You will get detailed explanation with examples on each of operators.
| User | Count |
|---|---|
| 3 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |