‎2007 Oct 18 3:18 PM
Hello experts,
I tryed to execute the following lines of code, but I get an error message saying something like "offset too long".
-
DATA: str1(60) TYPE c,
len type i,
spcarr(60) type c value
'0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ@&()_-+=|\:;",./'.
str1 = TRAN_STRUCTURE-DBBUSNAME.
REPLACE ALL OCCURRENCES OF '`' IN
str1 WITH ''''.
len = strlen( str1 ).
do len times.
if str1+sy-index(1) na spcarr. <<<< error here!
clear str1+sy-index(1).
endif.
enddo.
RESULT = str1.
-
Any suggestions
Thanks
hiza
‎2007 Oct 18 4:15 PM
You need another variable of type i.
data startpos type i.
do len times.
startpos = sy-index - 1.
if str1+startpos(1) na spcarr. <<<< error here!
clear str1+startpos(1).
endif.
enddo.
‎2007 Oct 18 3:23 PM
I have executed you r code and am not getting any error. Can you check in DEBUG mode where exactly you are getting error ad let me know.
ashish
‎2007 Oct 18 3:23 PM
I tried to execute this, but result wasnt defined, i guess this is a function module.
Second,
str1 = TRAN_STRUCTURE-DBBUSNAME.
is not a valid abap statement. Qre quotes missing?
‎2007 Oct 18 3:31 PM
This code is placed inot a transfer routine of SAP BW!
TRAN_STRUCTURE-DBBUSNAME represents a field of a table and is character string.
Since this is a ABAP-problem I thought it would be reasonable to place my quetion in this forum.
hiza
‎2007 Oct 18 3:24 PM
‎2007 Oct 18 3:24 PM
Hi,
Lets say if the String length is 50, then LEN field will have 50 value.
the statment if str1sy-index(1) na spcarr.. lets take the last record, then here, in this line it will become if str150(1) na spcarr. so there is no 51st charecter in the feild STR1, so it it giving the error.
len = strlen( str1 ).
len = len - 1.
do len times.
if str1+sy-index(1) na spcarr. <<<< error here!
clear str1+sy-index(1).
endif.
enddo.
Regards
Sudheer
‎2007 Oct 18 4:15 PM
You need another variable of type i.
data startpos type i.
do len times.
startpos = sy-index - 1.
if str1+startpos(1) na spcarr. <<<< error here!
clear str1+startpos(1).
endif.
enddo.
‎2007 Oct 19 9:01 AM
So if I loop an array "ABCD", str1+sy-index(1) starts with "B" and not "A"!
hiza
‎2007 Oct 19 1:20 PM
Correct. When you say stringstartpos(offset), startpos indicates where you are starting and offset indicates the length of the string you want from out of the total string. So for the first character you are starting at zero position and you want 1 character which would be string0(1).