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 from a field into another 2 fields

Former Member
0 Likes
905

hi forum,

say i have 1 field contains of 30 char.

now i need to split it into 2 fields with each 15 char.

when separate into 2 field, the word should not be broken.

say i have sentence like this "what a wonderful day". when split, field1 is "what a" whereas field2 is "wonderful day".

how to check the sentence with consideration of space as well so that can preserve the whole word when split.

thanks alot


3 REPLIES 3
Read only

former_member192854
Active Participant
0 Likes
820

Hi, you could use something which looks likes:

DATA lv_char30 TYPE char30.

DATA lt_splitted TYPE char30.

SPLIT AT lv_char30 INTO TABLE lt_splitted AT space.

Now you have all words in a separate entry in lt_splitted. From here you can create logic to check the length of the word and start concatenating it into two separate fields.

Good luck!

Sander

Read only

Former Member
0 Likes
820

You might like to check this post:

which mentions a function module 'RKD_WORD_WRAP' to do the work... the FM has a limit of three lines out I think.

Jonathan

Read only

Former Member
0 Likes
820

Use FM RKD_WORD_WRAP. It preserves the word, and splits the string based on the size given in the importing parameter and exports output to the table.

data : input type string.

DATA: lines(132) OCCURS 0 WITH HEADER LINE.


  CALL FUNCTION 'RKD_WORD_WRAP'
         EXPORTING
           textline                  = input
          OUTPUTLEN                 = 10
        TABLES
          OUT_LINES                 = lines.