Application Development 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: 

Split up the string with whole word

Former Member
0 Kudos

Friends,

I have a string with 150 charcters.

I want to split it up in 50-50-50 charcaters but the requirement is the word should not be broken.

So the 150 characters field can be adjusted.

and if there is no space in 150 characters then it should split exactly 50-50-50.

Is there any function module available for that?

Regards,

RH

4 REPLIES 4

Former Member
0 Kudos

Please search SE37 using 'wordwrap*'.

Rob

0 Kudos

Its fine...found one

SWA_STRING_SPLIT

Thanks !!

Former Member
0 Kudos

Thanks

kesavadas_thekkillath
Active Contributor
0 Kudos

Make the necessary changes,

Its only a logic.



DATA:len TYPE i,
     lv_index TYPE i,
     lv_offset TYPE i,
     lv_rev_index TYPE i,
     lv_rev_2 type i,
     lv_string TYPE string.


lv_string = 'VADVvsndcvbjvbvbvmbzc zdnfdb hzdfhjkahf sdbfbsdjkf sd f f jzdhfjk'.


len = STRLEN( lv_string ).
lv_offset = 50.
lv_index = 1.

DO.
    IF lv_string+lv_offset(lv_index) = ' '.
      WRITE / lv_string+lv_index(lv_offset).
      lv_index = lv_offset.
    ELSE.
      lv_rev_index = lv_offset - 2.
      DO.
        IF lv_string+lv_rev_index(1) = ' '.
          WRITE / lv_string+lv_offset(lv_rev_index).
          lv_offset = lv_rev_index.
          EXIT.
        ENDIF.
        lv_rev_index = lv_rev_index - 1.
      ENDDO.
    ENDIF.
    IF sy-index = len.
      EXIT.
    ENDIF.
ENDDO.