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

Contains String

Former Member
0 Likes
801

I have a problem where value 1 contains 'ABCDEDFEGH' and valu2 contanis 'ABCDE'. I am using the CS operator but its not working.

IF value1 CS value2.

THEN do processing

I am actually looking for a string BESPAK in a string containg 'BESPAK PLC / KINGS' - but it doesn't work see the below exmaples

lv_len = STRLEN( ls_cust-customer ).

lv_string = ls_cust-customer(lv_len).

lv_string2 = gs_cust-customer.

THIS FAILS?????

IF lv_string2 CS lv_string.

gs_cust-customer = ls_cust-customer.

COLLECT gs_cust INTO gt_cust.

ENDIF.

THIS WORKS

IF 'BESPAK PLC' CS 'BESPAK'..

WRITE: 'Yeah'.

ENDIF.

THIS WORKS

IF gs_cust-customer CS 'BESPAK'.

COLLECT gs_cust INTO gt_cust.

ENDIF.

Edited by: showthousand on Mar 16, 2011 6:23 PM

5 REPLIES 5
Read only

Former Member
0 Likes
759

Hi

Please check in debugg the values of lv_string2 and lv_string.

You must have the values lv_string2 = 'BESPAK' and lv_string = 'BESPAK PLC'. That means it is working fine since lv_string2 does not have whole string 'BESPAK PLC' .

Reverse your condition it will work.

Regards

Sachin

Edited by: sachin G patil on Mar 17, 2011 8:49 AM

Read only

Former Member
0 Likes
759

change your statement like this, it will definitely work.

IF lv_string CS lv_string2 .

gs_cust-customer = ls_cust-customer.

COLLECT gs_cust INTO gt_cust.

ENDIF.

Read only

Former Member
0 Likes
759

Hi

Reverse your condition.

because lv_string2 is smaller than lv_string.

hence lv_string2 is a part of lv_string.

we need to check whether lv_string contains the values similar to lv_string2.

so your statement should be like:

if lv_string CS lv_string2.

do processing.

endif.

Thanks

LG

Read only

former_member183804
Active Contributor
0 Likes
759

Are your variables typed the same or is one STRING and the other C<nn>? This can cause subtle errors especially with the logic of trailing blanks.

Read only

Clemenss
Active Contributor
0 Likes
759

Hi showthousand,

format code as code, give us the values you use and explaion what works and what does not work.

Thank you.

Regards,

Clemens