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 a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

1 Answer

  • Best Answer
    Posted on Apr 12, 2018 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 a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.