‎2009 Jul 24 6:13 AM
Hi all,
How do you detect asterisks from an inputted parameter of type string?
The user is supposed to use asterisks on the left, right, or both sides of the word/s that they type in the parameter field.
Parameters: p_txt50 type string.
This is what i want to do:
If p_txt50 has asterisk to the right (ex. computer*)
[code goes here]
If p_txt50 has asterisk to the left (ex. *computer)
[code goes here]
If p_txt50 has asterisk on both sides (ex. *computer*)
[code goes here]
Thank you very much :)
Edited by: mrpena on Jul 24, 2009 7:14 AM
Edited by: mrpena on Jul 24, 2009 7:15 AM
‎2009 Jul 24 6:29 AM
Hi,
Try Like below;
Data : lv_len type i.
lv_len = strlen( p_txt50 ).
lv_len = lv_len - 1.
if p_txt50+0(1) EQ '*' AND p_txt50+lv_len(1) EQ '*'.
"Contains Asterik in both sides.
else if p_txt50+0(1) EQ '*' AND p_txt50+lv_len(1) NE '*'.
"Contains Asterik in front
else if p_txt50+0(1) NE '*' AND p_txt50+lv_len(1) EQ '*'.
"Contains Asterik in last
endif.Check this and revert back.
Regards
Karthik D
‎2009 Jul 24 6:17 AM
Hi,
U can Do it using String Operations.
Try using CP (Contains Pattern ).
regards,
Lakshman.
‎2009 Jul 24 6:22 AM
Hi,
You can achieve it using
CP - Contains Pattern or
NP - Contains No Pattern
Thanks,
Sri.
‎2009 Jul 24 6:25 AM
Thank you for the replies. I found the CP documentation, but I couldn't find how to use it properly.
Can you elaborate more (on the actual syntax) that I could use?
‎2009 Jul 24 6:29 AM
if p_text CP '*'. " This means ur parameter has any * then execute ur code
your code.
endif.
Here param is the parameter name in ur program.
Edited by: vijetasap on Jul 24, 2009 7:29 AM
‎2009 Jul 24 6:31 AM
Hi
DATA: f1(5) TYPE c VALUE 'aBcde',
f2(5) TYPE c VALUE '*b*'.
IF f1 CP f2 .
WRITE: / 'Value found, SY-FDPOS=', sy-fdpos.
ELSE.
WRITE: / 'Value not found, SY-FDPOS=', sy-fdpos.
ENDIF.Hope this clears the issue.
Thanks
Viquar Iqbal
‎2009 Jul 24 6:29 AM
Hi,
Try Like below;
Data : lv_len type i.
lv_len = strlen( p_txt50 ).
lv_len = lv_len - 1.
if p_txt50+0(1) EQ '*' AND p_txt50+lv_len(1) EQ '*'.
"Contains Asterik in both sides.
else if p_txt50+0(1) EQ '*' AND p_txt50+lv_len(1) NE '*'.
"Contains Asterik in front
else if p_txt50+0(1) NE '*' AND p_txt50+lv_len(1) EQ '*'.
"Contains Asterik in last
endif.Check this and revert back.
Regards
Karthik D
‎2009 Jul 24 6:30 AM
Hi,
Do as below
DATA : l TYPE i.
PARAMETERS : p_var50 TYPE string.
AT SELECTION-SCREEN ON p_var50.
l = STRLEN( p_var50 ).
l = l - 1.
START-OF-SELECTION.
IF p_var50+0(1) = '*' AND p_var50+l(1) = '*'.
WRITE : 'Both ends'.
ELSE.
IF p_var50+0(1) = '*'.
WRITE : 'Starting'.
ELSE.
IF p_var50+l(1) = '*'.
WRITE : 'End'.
ENDIF.
ENDIF.Regards
Bala Krishna
‎2009 Jul 24 6:30 AM
Also, you will have to use -
> strlen(variable) to check the string length..
and str1 = str2+2(5).
What you can do is...
1) to check whether the last char is '*', calculate string length, minus 1 from it(v1), and put in the statement..
str1 = str2+v1(v2) " where v2 = 1.
now check whether it's '*' or not in str1.
2) Use similar logic for
syntaxes for string manipulations..
Exactly as Kartik has suggested!
Regards,
Sumit Nene.
Edited by: Sumit Nene on Jul 24, 2009 7:32 AM
‎2009 Jul 24 6:31 AM
Hi,
Use SEARCH Statement. Refer Following code
SEARCH p_text FOR '*'.
IF sy-subrc EQ 0.
ENDIF.
Ragards,
Prashant
‎2009 Jul 24 6:32 AM
HI,
Declar two variables say var1 and var2. Now check if the first character of the entered string is * and the last character is * then process the code when fisrt and last characters are *, else check if only fist character is * or last character is *.
Following is s pseudo code
var1 = p_txt50(0)+1.
v_len = strlen( p_txt50 ).
v_len = v_len - 1.
var2 = p_txt50(v_len)+1.
if var1 = '' and var2 = '*'.
insert code for *computer*
elseif var1 = '*'.
insert code for *computer
elseif var2 = '*'.
insert code for computer*.
else
insert code for non of the abpve condition.
endif.
Hope this helps.
Regards,
Sachin
‎2009 Jul 24 6:34 AM
‎2009 Jul 24 6:42 AM
ok thanks for the replies. i'm now trying out the many codes and may take some time. i'll reply right back and tell what happens.
‎2009 Jul 24 9:49 AM
Hi everyone.
Thank you for responding. My program works great. Thanks more power