2013 Feb 18 9:11 AM
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)
- 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!
2013 Feb 18 12:06 PM
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.
2013 Feb 18 10:31 AM
Hello,
Use SHIFT z_content LEFT DELETING LEADING SPACE.
Thanks,
Abhijit
2013 Feb 18 10:52 AM
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.
2013 Feb 18 12:06 PM
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.
2013 Mar 15 12:39 PM
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