2 weeks ago
Hi Everyone. I'm an ABAP student having a problem to understand the logic when looping a table with a Reference Variable that have different ways to print. Why the figure I just upload when the work area is different to the reference Variable that call de method (get_attribute) the print logic is to get de value assigned to that reference variable 3 times (same lines), but when the work area is the same that the reference variable it prints
all of the correct values of the 3 different reference variables?. Thanks a Lot in advanced.
Request clarification before answering.
The answer was given before, but looks like you didn't understand, so I'll try my best here.
You have 3 objects(VAR, NUM, CONNECTION), when you do the append, you are adding their values in CONNECTIONS, so now it has 3 rows, one containing(LH..., then AA..., then KR...) .
In line 49, CONNECTIONS has 3 rows added by each of the objects before, hence, when you LOOP connections it will it will execute get_attributes and out-write 3 times, one for each row of CONNECTION.
When you Loop Connection into VAR you are putting the content of the row into VAR, so at the first pass, var value will be LH-0400, the second will be AA-0017 and the third will be KK-2500. BUT to use get_attributes you are using NUM which has only the value you added before(KK-2500), so you are effectively getting the same value which is in NUM three times.
On your second LOOP you are sending the values of CONNECTIONS into CONNECTION and then using it to get the attributes, so now you are effectively getting the attributes of all rows of CONNECTIONS and writing them after.
I suggest you to debug the execution and see the values of your variables, that will make you understand better what's happening
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
num is not linked in any way to the first loop. You can even move the num statement out of the loop.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Solution is already given.
I am confused about the title.
In your case both variables are work areas: INTO <wa>
there is no reference variable in the loop: REFERENCE INTO <ref>.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
in the first Loop, the actual values are stored into var. But inside the Loop you reference on the variable num. This holds the last value which you assigned to num.
To have all the different values you need to use var->get_attributes instead of num->get_attributes.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
75 | |
21 | |
9 | |
7 | |
6 | |
6 | |
4 | |
4 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.