‎2009 Jan 09 12:46 PM
Hi,
I need to divide a text string in parts of a maximum of 79 chars, and can't cut words in two. Is there a function or something to do it?
Thanks!
‎2009 Jan 09 12:49 PM
‎2009 Jan 09 12:48 PM
is it that u need to only display any string in parts of 79 chars?
‎2009 Jan 09 12:49 PM
‎2009 Jan 09 1:11 PM
Try this:
TYPES: BEGIN OF ty_text,
line(79) TYPE c,
END OF ty_text.
DATA: v_text TYPE string,
v_text1 TYPE string,
v_count TYPE p DECIMALS 2,
v_length TYPE i,
v_after TYPE i,
v_sub TYPE i,
it_text TYPE STANDARD TABLE OF ty_text,
wa_text TYPE ty_text.
v_text = 'hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh'. " test charecters
v_length = STRLEN( v_text ).
v_count = CEIL( v_length / 79 ).
v_after = 0.
DO v_count TIMES.
CLEAR wa_text.
v_sub = v_length - v_after .
If v_sub is less than 78
IF v_sub LT 79 .
wa_text-line = v_text+v_after(v_sub).
APPEND wa_text TO it_text.
ELSE.
wa_text = v_text+v_after(79).
APPEND wa_text TO it_text.
v_after = v_after + 79.
ENDIF.
ENDDO.
it_text will hve the charecters divided into 79.
‎2009 Jan 09 1:21 PM
Hello Carles,
Are you trying to split a string, i mean, a variable of TYPE STRING?
You can have a look at the FM: FORMAT_TEXTLINES.
BR,
Suhas
PS: It will not work for variables of TYPE STRING.
‎2009 Jan 09 1:29 PM
hi,
Use this Fm in the
ISM_SPLIT_STRING
HR_ES_SPLIT_STRING_TO_4_CHAR50
‎2009 Jan 12 7:44 AM
Hi Carles,
Check the below code, it will split the strings each of 10 chars, but it will not split the words.
You can replace all '10' by '79' for your requirement.
Output of this code:
Original String: this is the example to splt the string based on no of chars !
Splitted Strings:
this is
the
example to
splt the
string
based on
no of
chars !DATA: w_txt TYPE string,
w_hold TYPE char10,
w_end,
w_exit.
DATA: w_len TYPE i,
w_do TYPE i VALUE 10,
w_mod TYPE i,
w_max TYPE i,
w_ind TYPE i,
w_one TYPE i,
w_two TYPE i,
w_val TYPE i VALUE 10,
w_cnt TYPE i VALUE 1.
DATA: BEGIN OF it_tab OCCURS 0,
txt TYPE char10,
END OF it_tab.
w_txt = 'this is the example to splt the string based on no of chars !'.
WRITE: / 'Original String: ', w_txt , /.
w_len = strlen( w_txt ).
WRITE: / 'Splitted Strings: '.
WHILE w_cnt < w_len.
w_do = 10.
w_ind = w_cnt - 1.
w_max = w_ind + 10.
IF w_max > w_len.
w_do = w_len - w_ind.
w_end = 'X'.
ENDIF.
" Below loop checks for the space at the end of the word
" If no move to the previous char otherwise it will split the word
DO.
IF NOT w_end EQ 'X'.
w_one = w_ind + w_do - 1.
w_two = w_one + 1.
ENDIF.
IF w_txt+w_one(1) CO ' ' OR
w_txt+w_two(1) CO ' ' OR
w_end EQ 'X'.
w_hold = w_txt+w_ind(w_do).
it_tab-txt = w_hold.
CONDENSE it_tab-txt.
APPEND it_tab.
EXIT.
ELSE.
SUBTRACT 1 FROM w_do.
ENDIF.
ENDDO.
ADD w_do TO w_cnt.
ENDWHILE.
LOOP AT it_tab.
WRITE: / it_tab-txt.
ENDLOOP.Hope this helps you.
Regards,
Manoj Kumar P
Edited by: Manoj Kumar on Jan 12, 2009 8:44 AM