‎2020 Nov 09 9:34 AM
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
‎2020 Nov 09 10:39 AM
If gv_globaltext CS gv_text1 and gv_global_text NS gv_text2.
"Delete gv_globaltext
ENDIF.
‎2020 Nov 09 10:30 AM
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
‎2020 Nov 09 10:39 AM
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!
‎2020 Nov 09 10:39 AM
If gv_globaltext CS gv_text1 and gv_global_text NS gv_text2.
"Delete gv_globaltext
ENDIF.
‎2020 Nov 09 12:11 PM
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)
‎2020 Nov 09 6:18 PM
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.
‎2020 Nov 09 6:20 PM
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.