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

Manipulating Long Text Strings

Former Member
0 Likes
944

Hello,

I have a program which takes a string and creates a BW Document. The BW Document's contents is the contents of the string. I run into a problem if the string is greater than 1,022 characters because 1,022 is the max length of line in SDOKCNTASC. So, I am trying to add code which checks if the string is longer than 1,022. If so, then put the first 1,022 characters into line one of itab. Keep looping until the remainder of the string is less than 1,022. Then put that last piece of the string in the table. When I run my code below, only the first 1,022 characters end up in the doc. When I loop at itab, only one line comes out. I am absolutely positive that my initial string is greater than 1,022. In fact, it's exactly 1,355 characters. Can someone please review my code and tell me what I am doing wrong?

THANKS SOOO MUCH.

DATA: itab like SDOKCNTASC OCCURS 0 with header line.

orig_text_len = strlen( text ).

text_len = orig_text_len.

REFRESH ITAB.

iteration = 1.

need_to_inc = 0.

WHILE text_len > 1022.

i_text = text+0(1022).

SHIFT text BY 1022 PLACES.

CONDENSE text.

INSERT i_text INTO ITAB INDEX iteration.

WRITE: / 'i_text: ', i_text.

WRITE: / 'text: ', text.

text_len = strlen( text ).

WRITE: / 'text_len: ', text_len.

iteration = iteration + 1.

need_to_inc = 1.

ENDWHILE.

IF need_to_inc = 1.

iteration = iteration + 1.

ENDIF.

WRITE: / 'text: ', text.

INSERT text INTO ITAB INDEX iteration.

LOOP AT itab INTO wa.

WRITE: / 'wa: ', wa.

ENDLOOP.

WRITE: / 'orig_text_len: ', orig_text_len.

len = strlen( filename ) - 4.

REFRESH l_t_chavl.

l_s_chavl-chanm = p_objn.

l_s_chavl-chavl = filename+0(len).

l_s_content_info-mimetype = 'application/html'.

l_s_content_info-file_name = filename.

l_s_content_info-file_size = orig_text_len.

name = filename.

CLEAR l_t_return.

CALL FUNCTION 'RSOD_DOC_MAST_CHANGE'

EXPORTING

i_chanm = l_s_chavl-chanm

i_chavl = l_s_chavl-chavl

  • I_DOC_TYPE =

i_description = descr

i_name = name

  • I_LANGU = SY-LANGU

i_overwrite_mode = if_rsod_const=>mode_replace_phio

i_with_content = 'X'

i_s_content_info = l_s_content_info

  • I_WITH_URL =

  • I_URL =

  • I_COPY_URL_CONTENT =

IMPORTING

  • E_NAME =

e_s_return = l_t_return

TABLES

i_t_file_content_ascii = itab.

  • i_t_file_content_binary =.

IF l_t_return-type = 'E' OR

l_t_return-type = 'W' OR

l_t_return-type = 'A'.

  • error

WRITE: / '**Error: Unable to create BW Document. ', filename,

'failed in call to function RSOD_DOC_MAST_CHANGE'.

STOP.

ELSE.

  • successfuly loaded

WRITE: / filename, 'Successfully Loaded'.

ENDIF.

2 REPLIES 2
Read only

Former Member
0 Likes
527

this always happens... i post a question, then i play with the program some more and i end up solving my problem... let me test it out and if i need further help, i will post another topic.

Thanks.

Read only

0 Likes
527

Hi Audrey:

The problem is with the place where you have coded initialization and incrementation of counters that you are using. Do following 2 steps and you will be ok:

1. Inside the while loop of "WHILE text_len > 1022", remove the code "iteration = iteration + 1" and place it directly after the WHILE statement; i.e. make it the first statement within the WHILE loop.

2. Just outside the WHILE loop, initialize "iteration" variable to zero (and not 1).

This will solve your problem. What was happening is that while adding the last record to internal table, the program was skipping one record.

Hope it helps.

iteration = 0. <======== (set it to zero, and not 1)

need_to_inc = 0.

WHILE text_len > 1022.

iteration = iteration + 1. <===== add statement here

i_text = text+0(1022).

SHIFT text BY 1022 PLACES.

CONDENSE text.

INSERT i_text INTO itab INDEX iteration.

WRITE: / 'i_text: ', i_text.

WRITE: / 'text: ', text.

text_len = STRLEN( text ).

WRITE: / 'text_len: ', text_len.

need_to_inc = 1.

ENDWHILE.