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

Spliting string every 132 characters.

Former Member
21,425

Hi

i have a string with dynamic length, i want to split this sting every 132 characters to a structure of type TLINE.

For a example if i have string in length 140 i will have 2 structure - one in lenght 132 and second in lenght 8.  

Is there a way to automaticly do that ?

Thanks Ami

14 REPLIES 14
Read only

Former Member
0 Likes
9,786

hello,

use the FM TR_SPLIT_TEXT

and for more..

http://scn.sap.com/thread/1592071

use this thread ..

Read only

0 Likes
9,786

I prefer helpful answer by Suhas over correct answer by Saslove in that thread.

Function module FORMAT_TEXTLINES does the job.

Read only

FredericGirod
Active Contributor
0 Likes
9,786

that looks very simple, no ?

describe my_field length lv_length.

DO.

  move my_field+lv_start(132) to ls_tline.

   lv_Start = lv_start + 132.

   if lv_start gt lv_length

     exit.

   endif.

   append ls_tline to lt_tline.

endif.

regards

Fred

Read only

0 Likes
9,786

PARAMETERS : my_field  TYPE string.
DATA       : lv_length TYPE i.
DATA       : lv_start  TYPE i.
DATA       : lv_temp   TYPE i.
DATA       : lt_tline  TYPE STANDARD TABLE OF text.
DATA       : ls_tline  TYPE text.


lv_length = STRLEN( my_field ).

DO.
   lv_temp = lv_start + 4.
   IF lv_temp LE lv_length.
     MOVE my_field+lv_start(3) TO ls_tline.
     lv_start = lv_start + 3.
     IF lv_start GT lv_length.
       EXIT.
     ENDIF.
     APPEND ls_tline TO lt_tline.
     WRITE : / ls_tline.
   ELSE.
     lv_temp = lv_temp - lv_length.
     MOVE my_field+lv_start(lv_temp) TO ls_tline.
     APPEND ls_tline TO lt_tline.
     WRITE : / ls_tline.
     EXIT.
   ENDIF.
ENDDO.

Read only

Former Member
0 Likes
9,786

Hi,

try this,

data : BEGIN OF struct,

           a(132),

           b(132),

        END OF struct.

struct =

'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' &

   'bbbbbbbb'.

    write : struct-a, struct-b.

Regards,

Praveen

Read only

Arun_Prabhu_K
Active Contributor
0 Likes
9,786

Hello Ami.

Refer this thread https://scn.sap.com/thread/883926

Regards.

Read only

Former Member
0 Likes
9,786

Hi,

Check this document here i am splitting PO text every 53 character's , check the logic .

    “ Note :  Number of Row Required for Long Text Display


              = Total length of long text / Number Character’s in one Row + 1

               Here I am taken 53 number of character in each row ,

               because in Material Master Long Text Area Display 53 Character without using Horizontal Bar . "

    DO LEN TIMES .

      MOVE '*' TO IT_LINES-TDFORMAT.

      MOVE  WA-LMAKTX+OFF(53) TO IT_LINES-TDLINE.

      SHIFT IT_LINES-TDLINE LEFT DELETING LEADING ' '.

      OFF = OFF + 53 .

      APPEND IT_LINES.

      CLEAR IT_LINES .

    ENDDO.


Regard's

Smruti

Read only

former_member183073
Active Participant
9,786

Hi,

FM "IDMX_DI_SPLIT_TEXT" can be used for splitting the text at 132 and it also takes care about the Line Feed or Spaces.

Read only

Former Member
9,786

Hi Ami,

Use function module 'RKD_WORD_WRAP'.

Example.

DATA :text(80),

      text1(30),

      text2(30),

      text3(30).

Text = 'ggsdgasgdspieorjewnkloierhgirhgjbgdfbgjkdfgbdjfhbvgjurbdgkjdfbgjdhvigtbdkjbhgdrd'.

CALL FUNCTION 'RKD_WORD_WRAP'

  EXPORTING

    textline                  = text

   DELIMITER                 = ' '

   OUTPUTLEN                 = 30 "Required length.

IMPORTING

   OUT_LINE1                 = text1

   OUT_LINE2                 = text2

   OUT_LINE3                 = text3

* TABLES

*   OUT_LINES                 =

* EXCEPTIONS

*   OUTPUTLEN_TOO_LARGE       = 1

*   OTHERS                    = 2

          .

IF sy-subrc <> 0.

* Implement suitable error handling here

ENDIF.



WRITE /: text1.

WRITE /: text2.

WRITE /: text3.

Regards,

Farid.

Read only

Former Member
9,786

Hi,

Use the function module RKD_WORD_WRAP or IDMX_DI_SPLIT_TEXT.

Regards,

Riju Thomas.

Read only

rosenberg_eitan
Active Contributor
0 Likes
9,786

Hi,

TEXT_SPLIT perhaps ?

Set parameter length to the length required.

Regards.


FORM test_03 .

  DATA: p_big_text TYPE line1000 .
  DATA: p_line TYPE string .

  p_big_text = '11111111112222222222333333333344444' .

  DATA: it_text TYPE TABLE OF string .

  WHILE p_big_text NE space.

    CALL FUNCTION 'TEXT_SPLIT'
      EXPORTING
        length = 10
        text   = p_big_text
      IMPORTING
        line   = p_line
        rest   = p_big_text.

    IF p_line IS NOT INITIAL .
      APPEND p_line TO it_text .
    ENDIF .

  ENDWHILE.

ENDFORM .                                 

Read only

Former Member
0 Likes
9,786

Hi ami bardogo,

         this code is mostly use can use full. can you check this code.

DATA : T_STRING TYPE STRING VALUE 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'.

   DATA: BEGIN OF GRAPHIC_TABLE OCCURS 0,

           LINE TYPE string,

         END OF GRAPHIC_TABLE.

DATA : T_INT TYPE I.

DATA : T_INT1 TYPE I.

DATA : T_INT4 TYPE I.

   DATA: L_GRAPHIC_OFFS TYPE I.

DATA : T_INT2 TYPE I.

PARAMETERS : T_INPUT TYPE I.

T_INT = STRLEN( T_STRING ).

T_INT1 = T_INT mod T_INPUT .

T_INT2 = T_INT div T_INPUT.

if t_int1 eq 0.

     L_GRAPHIC_OFFS = 0.

   do t_int2 TIMES.

        GRAPHIC_TABLE-LINE T_STRING+L_GRAPHIC_OFFS(T_INPUT).

     APPEND GRAPHIC_TABLE.

     L_GRAPHIC_OFFS = L_GRAPHIC_OFFS + T_INPUT.

     ENDDO.

   else.

*    t_int2 = t_int2 + 1.

   L_GRAPHIC_OFFS = 0.

   do t_int2 TIMES.

        GRAPHIC_TABLE-LINE T_STRING+L_GRAPHIC_OFFS(T_INPUT).

     APPEND GRAPHIC_TABLE.

     L_GRAPHIC_OFFS = L_GRAPHIC_OFFS + T_INPUT.

     CLEAR  GRAPHIC_TABLE.

     ENDDO.

T_INT4 = T_INT2 * T_INPUT.

      GRAPHIC_TABLE-LINE T_STRING+T_INT4(T_INT1).

     APPEND GRAPHIC_TABLE.

*    L_GRAPHIC_OFFS = L_GRAPHIC_OFFS + 132.

     CLEAR  GRAPHIC_TABLE.

   endif.

*WRITE : / T_INT1.

LOOP AT GRAPHIC_TABLE INTO GRAPHIC_TABLE.

   WRITE :/ GRAPHIC_TABLE-LINE.

   CLEAR : GRAPHIC_TABLE.

   ENDLOOP.


Read only

Former Member
0 Likes
9,786

Hi,

you can try with this abap example

PARAMETERS p_string TYPE string.

DATA: l_length TYPE i.
DATA: l_strlen TYPE i.
DATA: l_string TYPE string.
DATA: l_text TYPE tline-tdline.
DATA: lt_text TYPE STANDARD TABLE OF tline-tdline.

START-OF-SELECTION.

  l_string = p_string.
  l_strlen = strlen( p_string ).
  l_length = 0.
  WHILE l_strlen > l_length.
    l_text = l_string+l_length.
    l_length = l_length + 132.
    APPEND l_text TO lt_text.
  ENDWHILE.

Regards

Ivan

Read only

Former Member
0 Likes
9,786

Now please stop man.

there are so many reply for a small thing. Let reply. which is correct for him and useful..

.. Chandra...