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

String split problem

Former Member
0 Likes
1,802

Hi,

I have got a strange problöem when splitting a string into lines of 255 characters.

I need to save a string, which contains source code, into lines of 255 characters to save it in the db.

I have done it like this:

DATA:   z_counter           TYPE i,

                z_length              TYPE i,

                z_content           TYPE string,

                z_line_content TYPE Z_LINE_CONTENT. (this has as domain TEXT255)

               

  1. DO.

    z_counter = z_counter + 1.

    z_length = strlen( z_content ).

    IF z_length > 255.

      z_line_content = z_content.

      SHIFT z_content LEFT BY 255 PLACES.

    ELSE.

      z_line_content = z_content.

      SHIFT z_content LEFT BY z_length PLACES.

    ENDIF.

    IF z_content IS INITIAL.

      BREAK.

    ENDIF.

ENDDO.

Strangly one time, it doesn't copy all the 255 characters to z_line_content, when there is a space sign. It is then just copying the data to the space sign. Any ideas why this happens?

Do you have any suggestions how to save that code in a table instead? Or any better way to split it? I need to be sure, that it is saved to the database like it is, because when I read it in a string again afterwards, it needs to be exactly the same.

I have seen, that I now could also use STRING in tables, but this couldn't be used for table maintenance then. Should I go for that instead?

I'm happy for all answers,

Thank you!

1 ACCEPTED SOLUTION
Read only

kesavadas_thekkillath
Active Contributor
0 Likes
1,491

I still cannot understand your question clearly. I feel that you need to respect the "space" when extracting 255 characters. In this case you can use the function RKD_WORD_WRAP passing OUTPUTLEN. = 255.

If you need to get the 255 characters without respecting the space, then the below logic will do

do 1000 times.

   concatenate lv_string sy-abcde  into lv_string.

enddo.

  len = strlen( lv_string ).

lv_offset_mx = 255.

lv_offset_mn = 0.

div = ceil( len / 255 ).

do div times.

   clear wa.

   wa = lv_string+lv_offset_mn(lv_offset_mx).

   append wa to itab.

   lv_offset_mn = 255.

enddo.

4 REPLIES 4
Read only

Abhijit74
Active Contributor
0 Likes
1,491

Hello,

Use SHIFT z_content LEFT DELETING LEADING SPACE.

Thanks,

Abhijit

Read only

Former Member
0 Likes
1,491

Hello Michael,

Please check this function module "G_SPLIT_LINE" , it is used to split string into exact 71 characters.Similarly you can create your Z function module for 255 characters. You need to do simple changes to existing FM. Then pass your string to this FM.

Regards,

Sudhir Kothavale.

Read only

kesavadas_thekkillath
Active Contributor
0 Likes
1,492

I still cannot understand your question clearly. I feel that you need to respect the "space" when extracting 255 characters. In this case you can use the function RKD_WORD_WRAP passing OUTPUTLEN. = 255.

If you need to get the 255 characters without respecting the space, then the below logic will do

do 1000 times.

   concatenate lv_string sy-abcde  into lv_string.

enddo.

  len = strlen( lv_string ).

lv_offset_mx = 255.

lv_offset_mn = 0.

div = ceil( len / 255 ).

do div times.

   clear wa.

   wa = lv_string+lv_offset_mn(lv_offset_mx).

   append wa to itab.

   lv_offset_mn = 255.

enddo.

Read only

Former Member
0 Likes
1,491

Hi,

just to inform you: I have changed the table field to a string field. I was trying around and still don't know  why I got this strange behaviour in some cases. The string field works fine for me.

Thank you & best regards,

Michael