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

Comoparing Strings 'CO'

Former Member
0 Likes
3,575

Hi All,

Can you guys please take a look at this and let me know why this CO operation is not working.

DATA: _tparam(14) TYPE c.

DATA: lv_str(10) TYPE c.

lv_str = '1234567890'.

_tparam = '90'

CONDENSE _tparam NO-GAPS.

IF tparam CO lvstr.

l_var = _tparam.

ELSE.

l_var = 200.

ENDIF.

I did even check the sy-fdpos value, the returned value is correct but the statement in the if block is not getting executed. The else block part is getting executed which is really surprising. I checked the documentation in help.sap.com . But the behaviour I see here is interesting.

Thanks,

Varun

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
2,842

_tparam also contains spaces (it's declared (14)type c). You don't have a space in your legal characters string....

12 REPLIES 12
Read only

Former Member
0 Likes
2,843

_tparam also contains spaces (it's declared (14)type c). You don't have a space in your legal characters string....

Read only

0 Likes
2,842

Hi,

I do not agree with what you are saying, since I am assigning the value 90 only though the length is 14. Even then I am condensing the _tparam value saying no-gaps. I think that should take care of what you are saying.

Thanks,

Varun

Read only

0 Likes
2,842

Condensing will not reduce the size of variable _tparam to 10

Read the F1 help of Comparison operators for character-type operands.

Read only

0 Likes
2,842

I changed the code like this.

IF _tparam CO '1234567890'.

l_var = _tparam.

ELSE.

l_var = 200.

ENDIF.

Still it does not work. I tried the other options suggested by Keshav too. It did not work.

Thanks,

Varun

Read only

0 Likes
2,842

after your statements, _tparam contains '90 ' or 90 followed by 12 spaces. Your legal characters string does not contain a space! Therefore, _tparam does not contain only 1 or 2 or 3 or 4 or 5 or 6 or 7 or 8 or 9 or 0, does it?!! Change your legal characters to C11 and put a space on the front of the string of legal characters.

Read only

0 Likes
2,842

Do us a favor and add a space in your comparison string:

'0123456789 '

and try again.

Read only

0 Likes
2,842

Again i say change both the variables to type string. then use your old code

Read only

0 Likes
2,842

tparam has only '90' no spaces. Where as lvstr has 0,1,2,3,4,5,6,7,8,9.

Read only

0 Likes
2,842

Hi,

It worked when I included a space in the string.

IF _tparam CO '1234567890 '.

l_var = _tparam.

ELSE.

l_var = 200.

ENDIF.

Can you guys explain me why it worked when we included a space ??

Thanks,

Varun

Read only

0 Likes
2,842

Great, and FYI, I do usually try to take care about what I write in this forum, with an occasional notable failure.

Read only

0 Likes
2,842

Thank you all guys for the help.

Read only

kesavadas_thekkillath
Active Contributor
0 Likes
2,842

lv_str - char10. tparam - char14. This is the problem.

Change it as


DATA: _tparam(14) TYPE c.
DATA: lv_str(14) TYPE c.

or change both the variables to type string.