‎2008 Jul 27 12:39 PM
experts,
the following is the sample code where i want to assign
a part of a string value to the variable.
when executed, program is getting shortdumped with the
following message.
In the running program "Z_FORSTR", part of a string was about to be accessed with an explicitly specified length.
However, this length (5) exceeded the current length of the string (3).
This kind of access is illegal.
how to solve the error.
REPORT z_forstr.
DATA : str TYPE string, str1 TYPE str.
DATA : BEGIN OF itab OCCURS 0,
line TYPE char5,
END OF itab.
DATA : l TYPE i,
j TYPE i,
m TYPE i.
str = 'ABCDEFGHIJKLMNOPQRSTUVWXZYABDCEFH'.
l = strlen( str ).
j = l DIV 5.
m = l MOD 5.
IF m <> 0.
j = j + 1.
ENDIF.
DO j TIMES.
itab-line = str+0(5).
APPEND itab-line TO itab.
CLEAR itab-line.
str = str+5.
ENDDO.
LOOP AT itab.
WRITE 😕 itab-line.
ENDLOOP.
thanks in advance.
‎2008 Jul 27 12:55 PM
Hello Rae,
The shortdump occurs because in last step of the loop, str variable was 3 characters and you're asking for 5. Try to check first if variable str has less than 5 characteres in last part of the loop.
You can try like this:
DO j TIMES.
l = strlen( str ).
IF l > 5.
itab-line = str+0(5).
str = str+5.
ELSE.
itab-line = str.
ENDIF.
APPEND itab-line TO itab.
CLEAR itab-line.
ENDDO.
Kind regards.
‎2008 Jul 27 12:55 PM
Hello Rae,
The shortdump occurs because in last step of the loop, str variable was 3 characters and you're asking for 5. Try to check first if variable str has less than 5 characteres in last part of the loop.
You can try like this:
DO j TIMES.
l = strlen( str ).
IF l > 5.
itab-line = str+0(5).
str = str+5.
ELSE.
itab-line = str.
ENDIF.
APPEND itab-line TO itab.
CLEAR itab-line.
ENDDO.
Kind regards.
‎2008 Jul 27 1:01 PM
Hi,
I copy pasted ur code and i am not getting any dump. But result is wrong.
Modify the code like this.
DO j TIMES.
itab-line = str+0(5).
APPEND itab-line TO itab.
CLEAR itab-line.
str = str+5.
ENDDO.
itab-line = str.
APPEND itab-line TO itab.
Above two lines will put the remaining string into itab.
Thanks,
Vinod.
‎2008 Jul 27 1:06 PM
‎2008 Jul 27 1:44 PM