Function Module To Split a Long Text into Smaller Segments

The function module ‘RKD_WORD_WRAP’ can be used to split a long text into smaller segments of specific length. The smaller segments will be available in an internal table.

Code:

*Types:
TYPES:
BEGIN OF gxs_text_split,
text_split(5) TYPE c,
END OF gxs_text_split.

*Internal Tables:
DATA:
lt_text_split TYPE STANDARD TABLE OF gxs_text_split.

*Variables:
DATA:
lv_text_full(45) TYPE c.

lv_text_full = \'The quick brown fox jumps over the lazy dog.\'.

*The following function module will split the text above into
*5 characters.
CALL FUNCTION \'RKD_WORD_WRAP\'
EXPORTING
textline = lv_text_full \" Variable which will be splitted.
outputlen = 5 \" Split into segments of 5 characters.
TABLES
out_lines = lt_text_split \" Internal table containing lines, each line will contains 5 characters max.
EXCEPTIONS
outputlen_too_large = 1
OTHERS = 2.

 

The output of the spitted texts in the internal table ‘LT_TEXT_SPLIT’:

\"\"