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

Finding text in a data field

Former Member
0 Likes
512

Hi, How could I find the % character in a string? I need its position in the string. The string is a field of a table.

Hi, How could I find the % character in a string? I need its position in the string. The string is a field of a table.

2 REPLIES 2
Read only

Former Member
0 Likes
466

you can use the CP syntax.

if str cp '%'.

sy-fdpos would have the first occurance of %.

endif.

you can also use

search str for '%'. "newer versions of sap

sy-fdpos would have the first occurance of %.

find '%' in str. "newer versions of sap

Regards,

Ravi

Read only

Former Member
0 Likes
466

Hi Jacob,

here a short example with char and string.

DATA: ST TYPE STRING.

DATA: CH(250).

*

************************************************************************

*

START-OF-SELECTION.

*

ST = 'I am a String with an % Character'.

*

SEARCH ST FOR '%'.

*

WRITE: / SY-SUBRC, sy-fdpos.

*

CH = 'I am a Char with an % Character'.

*

SEARCH CH FOR '%'.

*

WRITE: / SY-SUBRC, sy-fdpos.

*

Regards, Dieter