Skip to Content

Problem with SPLIT with "multiple" separators

Hello gurus,

I'm dealing with a simple task on text strings.

Showing it with an example: please consider that:

tb_text_unroll is a table with many fields; the relevant fact is that TDLINE field has type "STRING".

itab_tdline is a table containing just a field, TDLINE, which is a CHAR of length 132.

Here's a sketch of code:

LOOP AT tb_text_unroll INTO wa_text_unroll.

REFRESH itab_tdline.

SPLIT wa_text_unroll-TDLINE AT CL_ABAP_CHAR_UTILITIES=>NEWLINE INTO TABLE itab_tdline.

....

CL_ABAP_CHAR_UTILITIES=>NEWLINE is a separator which is often represented in char strings ad a sharp (#).

The problem is this: if wa_text_unroll-TDLINE contains a string which is longer than 132 chars AND the # separator follows that 132nd position, the string isn't correctly splitted into the table.

In example, strings like

"This is a short example of text which will not be correctly splitted as the next separator occours only after the 132nd position, and this leads to the odd behaviour described above.#How can I solve it?#Thanks."

will be splitted in the following three rows of itab_tdline:

This is a short example of text which will not be correctly splitted as the next separator occours only after the 132nd

position, an

How can I solve it?

Thanks.

as you can see, a part of the string, from the 133rd position to the separator, is lost.

Is there a way to consider multiple separators on the SPLIT clause? Something like "split at NewLine OR if the string exceed 132 chars" ?

Of course there should be many workarounds, like doing a multiple split in sequence, anyway I'd like to know what's the best solution in your opinion.

Thanks in advance,

M.

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

1 Answer

  • Posted on Aug 01, 2012 at 08:56 PM

    Google -> convert string to char site:sap.com

    The first link from the top has a solution: http://scn.sap.com/thread/1489987

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.