08-20-2007 7:18 PM
Hi,
I have along text of 1000 characters. I want to place this text into an internal table, whose structure is of 132 characters. And the text should be in Justified alignment and without any word truncations,
I mean..if the 132nd charcater is 'e' in a word 'before', then it should not truncate as 'b' in first line and 'efore' in second line.
Do we have any function module for this requirement
-Priya
08-20-2007 7:33 PM
You can use FM : SWA_STRING_SPLIT
See the sample code :
DATA: itab_d LIKE swastrtab OCCURS 0 WITH HEADER LINE.
data : d_message1 type string
d_message1 = ' give ur text'.
CALL FUNCTION 'SWA_STRING_SPLIT'
EXPORTING
input_string = d_message1
max_component_length = 132
TABLES
string_components = itab_d
EXCEPTIONS
max_component_length_invalid = 1
OTHERS = 2.
Thanks
Seshu
08-20-2007 7:42 PM
HI,
I have written a small program .. here i am spliting the string into 10 character lenth strings.. with out word truncation. you can change this to 132..
REPORT ztest1 .
DATA : lv_string(200) TYPE c.
DATA : BEGIN OF itab OCCURS 0,
word(20) TYPE c,
END OF itab.
DATA : BEGIN OF jtab OCCURS 0,
sentence(10) TYPE c,
END OF jtab.
DATA : lv_total TYPE i,
lv_word TYPE i.
DATA : lv_10reached TYPE i.
DATA : lv_10chars(10) TYPE c.
lv_string = 'Hello How are you doing today'.
SPLIT lv_string AT ' ' INTO TABLE itab.
LOOP AT itab.
lv_total = strlen( lv_10chars ).
lv_word = strlen( itab-word ).
lv_10reached = lv_total + lv_word.
IF lv_10reached >= 10.
jtab-sentence = lv_10chars.
APPEND jtab.
CLEAR : lv_total,
lv_word,
lv_10reached,
lv_10chars.
CONCATENATE lv_10chars itab-word INTO lv_10chars SEPARATED BY space.
ELSE.
CONCATENATE lv_10chars itab-word INTO lv_10chars SEPARATED BY space.
ENDIF.
ENDLOOP.
if not lv_10chars is initial.
jtab-sentence = lv_10chars.
APPEND jtab.
endif.
LOOP AT jtab.
WRITE / jtab-sentence.
ENDLOOP.
Thanks
Mahesh