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

detect asterisk from parameter (user input)

Former Member
0 Likes
4,037

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

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
2,723

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

13 REPLIES 13
Read only

former_member209217
Active Contributor
0 Likes
2,723

Hi,

U can Do it using String Operations.

Try using CP (Contains Pattern ).

regards,

Lakshman.

Read only

sridhar_meesala
Active Contributor
0 Likes
2,723

Hi,

You can achieve it using

CP - Contains Pattern or

NP - Contains No Pattern

Thanks,

Sri.

Read only

Former Member
0 Likes
2,723

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?

Read only

0 Likes
2,723

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

Read only

0 Likes
2,723

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

Read only

Former Member
0 Likes
2,724

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

Read only

former_member585060
Active Contributor
0 Likes
2,723

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

Read only

Former Member
0 Likes
2,723

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

Read only

former_member386202
Active Contributor
0 Likes
2,723

Hi,

Use SEARCH Statement. Refer Following code

SEARCH p_text FOR '*'.

IF sy-subrc EQ 0.

ENDIF.

Ragards,

Prashant

Read only

Former Member
0 Likes
2,723

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

Read only

Former Member
0 Likes
2,723

This message was moderated.

Read only

Former Member
0 Likes
2,723

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.

Read only

Former Member
0 Likes
2,723

Hi everyone.

Thank you for responding. My program works great. Thanks more power