06-04-2015 8:38 AM
Hi,
when trying the following two blocks, they provide different output, while they should not. Only the block #2 provides an expected output. Any idea why block #1 does not work? I am curious why the offset1 is calculated incorrectly (and why is it calculated incorrectly ONLY in 2nd iteration???)...
TYPES:
BEGIN OF struc,
col1 TYPE c,
col2 TYPE i,
END OF struc.
* block #1
DO 3 TIMES.
DATA(struc) = VALUE struc(
LET offset1 = sy-index - 1
IN col1 = sy-abcde+offset1(1)
col2 = sy-index ).
WRITE:/ struc-col1, struc-col2.
ENDDO.
SKIP.
* block #2
DO 3 TIMES.
DATA(offset2) = sy-index - 1.
struc = VALUE struc(
col1 = sy-abcde+offset2(1)
col2 = sy-index ).
WRITE:/ struc-col1, struc-col2.
ENDDO.
Output:
A 1
A 2 "2nd loop: offset1 was not increased, resulting in A instead of B
B 3 "3rd loop: offset1 was increased as expected
A 1
B 2
C 3
Am I missing something?
Thanks, Michal
06-04-2015 3:43 PM
I think I can confirm myself it's a bug. It can be demonstrated (and explained) with another construction:
DO 3 TIMES.
struc = VALUE ty_struc(
LET offset1 = sy-index
IN col1 = sy-abcde+offset1(1)
col2 = sy-index ).
WRITE:/ struc-col1, struc-col2.
ENDDO.
Here, the output is surprisingly
A 1
B 2
C 3
but should be instead
B 1
C 2
D 3
as sy-abcde+1(1) = B and not A. The reason is that the LET addition does not probably work during the first iteration. Then the helper variable keeps its initial value (means that the type is derived correctly, but not the value?)) and it's only 'lately bound' to the source variable value. If this explanation is correct, then it 'works' the same way in my previous example as well.
Closing the thread.
06-04-2015 3:43 PM
I think I can confirm myself it's a bug. It can be demonstrated (and explained) with another construction:
DO 3 TIMES.
struc = VALUE ty_struc(
LET offset1 = sy-index
IN col1 = sy-abcde+offset1(1)
col2 = sy-index ).
WRITE:/ struc-col1, struc-col2.
ENDDO.
Here, the output is surprisingly
A 1
B 2
C 3
but should be instead
B 1
C 2
D 3
as sy-abcde+1(1) = B and not A. The reason is that the LET addition does not probably work during the first iteration. Then the helper variable keeps its initial value (means that the type is derived correctly, but not the value?)) and it's only 'lately bound' to the source variable value. If this explanation is correct, then it 'works' the same way in my previous example as well.
Closing the thread.