‎2006 Aug 11 2:09 PM
Hi Experts,
I have a string v_str.
The below logic works only if the total.no of characters in v_str is even number.if total.no of characters in v_str is odd number or prime number it is giving short dump.
See this code:
data: v_str type string.
DATA LEN TYPE I.
DATA COUNT1 TYPE I.
DATA : BEGIN OF DAT OCCURS 0,
LIN(10000),
END OF DAT.
DO.
IF COUNT1 >= LEN.
EXIT.
ENDIF.
DAT-LIN = v_str+COUNT1(125).
APPEND DAT.
WRITE 😕 DAT-LIN.
CLEAR DAT.
COUNT1 = COUNT1 + 125.
ENDDO.
Suppose total no.f characters in v_str is 1165.. the above code is giving
short dump at the statement DAT-LIN = v_str+COUNT1(125)..
So can any body tell me how to change the logic as per this requirement?
Regards
‎2006 Aug 11 2:15 PM
DO.
IF COUNT1 >= LEN.
EXIT.
else.
lchr = len - count1.
if lchr > 125.
lchr = 125.
endif.
ENDIF.
write v_str+COUNT1(lchr) to dat-lin.
APPEND DAT.
WRITE 😕 DAT-LIN.
CLEAR DAT.
COUNT1 = COUNT1 + 125.
ENDDO.
‎2006 Aug 11 2:17 PM
Please see the example code below for some help. You are getting a dump because when processing the last section of the string, your offset is overflowing.
report zrich_0001.
data: v_str type string.
data: len type i.
data: count1 type i.
data: result type i.
data : begin of dat occurs 0,
lin(10000),
end of dat.
v_str = 'This is the string that we must break up into lines of 125' &
'and for this example we will be using a lenght of 50 instead'.
len = strlen( v_str ).
do.
if count1 >= len.
exit.
endif.
<b> result = len - count1.
if result < 50.
dat-lin = v_str+count1(result).
else.
dat-lin = v_str+count1(50).
endif.</b>
append dat.
clear dat.
count1 = count1 + 50.
enddo.
loop at dat.
write:/ dat.
endloop.
Regards,
Rich Heilman
‎2006 Aug 11 2:19 PM
no where you mentioned, what is your requirement. if mention it, you may get a better logic than the existing one.
Regards
srikanth
‎2006 Aug 11 2:22 PM
Hello,
Try this code:
data: v_str type string.
DATA LEN TYPE I.
DATA COUNT1 TYPE I.
<b>data: rem type i.</b>
DATA : BEGIN OF DAT OCCURS 0,
LIN(10000),
END OF DAT.
do 50 times.
concatenate v_str sy-abcde into v_str separated by ' '.
enddo.
len = strlen( v_str ).
DO.
IF COUNT1 >= LEN.
EXIT.
ENDIF.
<b>rem = len - count1.
if rem > 125.
rem = 125.
endif.</b>
DAT-LIN = v_str+COUNT1<b>(rem).</b>
APPEND DAT.
WRITE 😕 DAT-LIN.
CLEAR DAT.
COUNT1 = COUNT1 + 125.
ENDDO.
Regards,
Naimesh