Application Development 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: 

How to use "FIND FIRST OCURRENCE...." with a very long text

Former Member
0 Kudos

When I store a certain text in variable p_texto -> FIND FIRST OCURRENCE is ok; sy-subrc = 0.

When Instead of assigning a text I read a long text from an excel into p_texto variable ->

FIND FIRST OCURRENCE is not working; sy-subrc = 4.

DATA: p_texto(5000).

DATA: posicion TYPE match_result.

p_texto = 'HI THIS IS THE FIRST LINE#AND THIS ONE THE SECOND LINE'.

FIND FIRST OCCURRENCE OF '#' IN p_texto RESULTS posicion.

How could I manage this problem?

Thank you very much in advance.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi Jarizkuren ,

in your text, string "#" is the rapresentation of characters that cannot be displayed in sap.

Probably you should search for

CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB

CL_ABAP_CHAR_UTILITIES=>NEWLINE

CL_ABAP_CHAR_UTILITIES=>CR_LF

regards

Andrea

7 REPLIES 7

Former Member
0 Kudos

Hi Jarizkuren ,

in your text, string "#" is the rapresentation of characters that cannot be displayed in sap.

Probably you should search for

CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB

CL_ABAP_CHAR_UTILITIES=>NEWLINE

CL_ABAP_CHAR_UTILITIES=>CR_LF

regards

Andrea

0 Kudos

That´s not my question. My doubt is why it works when I write a short text but it does´nt work when using a very long text.

0 Kudos

It works if you search for "LINE"??

0 Kudos

do you mean if I execute this code?

p_texto = 'HI THIS IS THE FIRST LINE#AND THIS ONE THE SECOND LINE'.

FIND FIRST OCCURRENCE OF 'LINE' IN p_texto RESULTS posicion.

Yes, sy-subrc = 0. -> It´s working properly.

0 Kudos

As I told you before, the problem is not the length of the line.

The problem is that you see in your variable "#", but it is not "#". It could be a carriage return, a tabulator or other character that doesn't know how to display.

In my opinion you should search for cl_abap_char_utilities=>newline.

Regards

Andrea

0 Kudos

Hi!!

Thank´s. I have tried with cl_abap_char_utilities=>newline.

and now it´s working.

Thanks a lot.

Former Member
0 Kudos

HI Jari,

I think you can try using FIND FIRST OCCURANCE......IN BYTE MODE instead of default character mode.

And for this, the pattern you are searching and the data object from you want to search has to be Byte-Like.

Thanks,

Anishek Kumar