Skip to Content

How local is a 'local auxiliary field'?

A colleague noticed something interesting: If we use the same variable name in multiple FOR or LET expressions with different data types, we get type conflicts.

The documentation calls them "local auxiliary field", which I always interpreted as local to the expression - particularly since it also states "There is no way of accessing an auxiliary field statically outside its expression".

But:

TYPES numtab  TYPE STANDARD TABLE OF i WITH DEFAULT KEY.
TYPES chartab TYPE STANDARD TABLE OF c WITH DEFAULT KEY.

DATA(nums)  = VALUE numtab( ( 1 ) ( 2 ) ( 3 ) ).
DATA(nums2) = VALUE numtab( FOR x IN nums ( x ) ).

DATA(chars)  = VALUE chartab( ( 'A' ) ( 'B' ) ( 'C' ) ).
DATA(chars2) = VALUE chartab( FOR x IN chars ( x ) ).  "Error 1

"Just for kicks let's try the same with LET
DATA(nums3)  = VALUE numtab( LET a = 1 IN ( a ) ).
DATA(chars3) = VALUE chartab( LET a = 'A' IN ( a ) ).  "Error 2

x = 5.  "Error 3: X cannot be used here

Errors 1 and 2 are "X was already declared with the type "I" and cannot be used with the type "C" here.

Error 3 states that "X cannot be used here" which matches the docu.

So is the documentation vaguely worded or is this not as local as it is designed to be?

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • Best Answer
    Apr 12 at 01:58 PM

    The documentation is correct, because it says "statically". Try to address it dynamically and you'll see (it is ABAP, sigh).

    Add comment
    10|10000 characters needed characters exceeded