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

Split text dynamically

Former Member
0 Likes
943

Hi all,

I have a string containing N number of characters example:

A111/123/B4567/200/888

Let's say my field can only accomodate 10 characters and the rest have to be split to the next line (or flows to the next line in the case of a smartform).

However i do not want it to be split in an incomplete manner:

Eg:

A111/123/B4

567/200/888

Notice that "B4567" is split incorrectly.

I need it to be like (every '/' indicates a unique text section):

Eg:

A111/123/

B4567/200/

888

Anyone has any idea on how to accomplish this?

Thanks in advance.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
874

well you need to code that with offset.

just make sure you only split when the last sign before the split is a /.

6 REPLIES 6
Read only

Former Member
0 Likes
875

well you need to code that with offset.

just make sure you only split when the last sign before the split is a /.

Read only

Former Member
0 Likes
874

HI,

data: text(100) type c,

text_1(10) type c,

text_2(10) type c.

text2 = 'A111/123/B4'

text3 = '567/200/888'

concatenate text2 text3 to text.

text_1 = text(10).

text_2 = text(10)+10.

.............

Read only

Former Member
0 Likes
874

Try with the below code....

constants c_slash type c value '/'.

data v_act(250) type c.

data: begin of itab occurs 0,

line(250) type c,

end of itab.

v_act = 'A111/123/B4567/200/888'.

split v_act at c_slash into table itab.

loop at itab.

write: / itab-line.

endloop.

Regards,

Satya

Read only

0 Likes
874

I do not want it to split at every single occurence of '/'. That's why this is abit tricky.

Read only

0 Likes
874

split it at every single occurance of '/' into an internal table and then concatenate 1st and 2nd , 3rd and 4th... according to ur requirement.

reward if useful

Read only

Former Member
0 Likes
874

Try this sample code:

DATA: slen(5) TYPE c,

itab TYPE TABLE OF string WITH HEADER LINE,

itab1 TYPE TABLE OF string WITH HEADER LINE,

text TYPE string.

text = `A111/123/B4567/200/888/2386/842/8`.

SPLIT text AT '/' INTO TABLE itab.

LOOP AT itab.

IF sy-tabix = 1.

itab1 = itab.

ELSE.

CONCATENATE itab1 itab INTO itab1 SEPARATED BY '/'.

ENDIF.

slen = STRLEN( itab1 ).

IF slen >= 10.

IF itab1+10(1) = '/'.

APPEND itab1.

CLEAR itab1.

ELSE.

REPLACE ALL OCCURRENCES OF itab IN itab1 WITH space.

APPEND itab1.

CLEAR itab1.

itab1 = itab.

ENDIF.

ENDIF.

AT LAST.

APPEND itab1.

CLEAR itab1.

ENDAT.

ENDLOOP.

WRITE: /1 'String: ', text.

LOOP AT itab1.

WRITE :/1 itab1.

ENDLOOP.