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

Characters operator

Former Member
0 Likes
1,561

Hello experts,

I want to put in IF statement a condition where I have to verify if there are 2 strings (gv_text1='PRODUCT' and gv_text2='PRODUCT2') in another string (gv_globaltext). So to delete gv_globaltext only if it contains string gv_text1 i.e. 'PRODUCT'

I want to do this dinamically and not write the 2 string explicitly like 'Product' and 'Product2'

I did the following :

If gv_globaltext CS gv_text2.
"SKIP
ELSEIF gv_globaltext CS gv_text1.
"Delete gv_globaltext
endif.

But it deletes at the end both gv_text1 and gv_text2, because both contains the word 'PRODUCT' at the beginin.

Can you please help me to solve this.

Thanks in advance

1 ACCEPTED SOLUTION
Read only

matt
Active Contributor
1,495
If gv_globaltext CS gv_text1 and gv_global_text NS gv_text2.
  "Delete gv_globaltext
ENDIF.
6 REPLIES 6
Read only

Former Member
0 Likes
1,495

Hi Satish,

Sorry my bad, I didn't explain it very well. Actually, the strings are like:

'xxxProduct209112020' Product2 + date

'xxxProduct09112020' Product + date xxxx are numbers

So they are not exact

Read only

former_member1716
Active Contributor
0 Likes
1,495

Hello essaouira,

I just checked with below test code, it works fine for me. Can you check and correct me if my understanding is wrong.

DATA: gv1 TYPE string VALUE 'PRODUCT',
      gv2 TYPE string VALUE 'PRODUCT2',
      gv3 TYPE string VALUE 'aDKHSkjxnkjproductkjdakj'.

IF  gv3 CS gv2.
  WRITE: 1.
ELSEIF gv3 CS gv1.
  WRITE: 2.
ENDIF.

Regards!

Read only

matt
Active Contributor
1,496
If gv_globaltext CS gv_text1 and gv_global_text NS gv_text2.
  "Delete gv_globaltext
ENDIF.
Read only

Former Member
0 Likes
1,495

Thank you matthew.billingham it works. and just one more question please. Suppose if we want the inverse (delete gs_text2 only) how can we do it please? (because with the same code it's not working)

Read only

matt
Active Contributor
0 Likes
1,495

You really need to read the documentation of what CS and NS mean. It is trivially obvious why, with gv_text2 = 'PRODUCT2' and gv_text1 = 'PRODUCT',

If gv_globaltext CS gv_text2 and gv_global_text NS gv_text1.
  "Delete gv_globaltext
ENDIF.<br>

doesn't work.

Maybe a quick look at how boolean operations like AND work would be of value also. I'm not going to assist further: I was happy to help with some syntax, but as far as I'm concerned this site doesn't exist to teach basic programming. Programming by guessing is never going to work - you have to understand what you are doing and why.

Read only

Pankaj_Gupta
Product and Topic Expert
Product and Topic Expert
0 Likes
1,495

If you want to delete the GV_GLOBAL_TEXT if it contains GV_TEXT2 and not GV_TEXT1, then it is not possible as in your example, GV_TEXT2 itself contain GV_TEXT1.