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

String Operation not working Correctly

Former Member
0 Likes
1,025

I have one code where I have to Seprate a string in lines based on Pattern '#'.

EG: first line##second line##third line.

output should be :

first line

second line

third line

do.

SEARCH content for '#'.

    • find hash in content.

if sy-subrc = 4.

gfs_content-content = content.

APPEND gfs_content TO git_content.

clear gfs_content.

exit.

else.

gfs_content-content = content+0(sy-fdpos).

APPEND gfs_content TO git_content.

clear gfs_content.

loc_count = sy-fdpos + 2.

SHIFT content BY loc_count PLACES.

endif.

enddo.

when I am changing the content value in Debugger, this code is working fine. but when I am executing it directly without any change in value in debugger, Sy-subrc = 4 after SEARCH operation. Its not finding the "#" position.

What could be the possible reason.

5 REPLIES 5
Read only

Former Member
0 Likes
920

The SEARCH statement is obsolete, i´d try using the followup statement called FIND.

Hopefully this will work out like you need it.

Read only

0 Likes
920

With FIND statement also, I am facing same problem.

Read only

arseni_gallardo
Active Participant
0 Likes
920

I guess you are trying to find the newline character. If that's the case you should use CL_ABAP_CHAR_UTILITIES=>CR_LF instead of '#'.

By the way, may be this piece of code is more suitable for what you are trying to do:


SPLIT content AT CL_ABAP_CHAR_UTILITIES=>CR_LF INTO TABLE GFS_CONTENT.

Read only

0 Likes
920

@@Arseni thanks a lot.....it worked....excellent solution....

Edited by: abhi1185 on Sep 20, 2011 4:18 PM

Read only

0 Likes
920

<removed by moderator>

Moderator message: please leave this reminder to the moderators.

Edited by: Thomas Zloch on Sep 20, 2011 8:33 PM