‎2008 May 05 11:19 AM
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.
‎2008 May 05 11:28 AM
well you need to code that with offset.
just make sure you only split when the last sign before the split is a /.
‎2008 May 05 11:28 AM
well you need to code that with offset.
just make sure you only split when the last sign before the split is a /.
‎2008 May 05 11:30 AM
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.
.............
‎2008 May 05 11:36 AM
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
‎2008 May 05 11:39 AM
I do not want it to split at every single occurence of '/'. That's why this is abit tricky.
‎2008 May 05 11:43 AM
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
‎2008 May 05 12:45 PM
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.