2020 May 22 5:48 AM
I have internal table like below.
Month number Index
-----------------------------------
1 5
1 6
2 3
---------------------------------------
Now I want to add index based on month. The result will like below
Month number Index
-----------------------------------
1 5 1
1 6 2
2 3 1
---------------------------------------
I want to use loop group to implement.
The code is like below.
loop at itab into data(wa)
location = sy-tabix.
loop at group wa into data(wa1)
wa1-index = sy-tabix - location.
modify itab from wa1.
endloop.
end loop.
But the modify line has error like
"DELETE itab." 和 "MODIFY itab FROM wa." can't use in "LOOP AT itab ... USING KEY keyname ..." <br>
Then what's the correct syntax to write back to the itab? Thx.
2020 May 23 6:53 AM
Hi
loop at itab into data(wa)
location = sy-tabix.
loop at group wa into data(wa1)
wa-index = sy-tabix - location. <== use wa-index
modify itab from wa INDEX location. <== use INDEX keyword
endloop.
end loop.
I have internal table like below.
Month number Index
-----------------------------------
1 5
1 6
2 3
---------------------------------------
Now I want to add index based on month. The result will like below
Month number Index
-----------------------------------
1 5 1
1 6 2
2 3 1
---------------------------------------
I want to use loop group to implement.
The code is like below.
loop at itab into data(wa)
location = sy-tabix.
loop at group wa into data(wa1)
wa1-index = sy-tabix - location.
modify itab from wa1.
endloop.
end loop.
But the modify line has error like
"DELETE itab." 和 "MODIFY itab FROM wa." can't use in "LOOP AT itab ... USING KEY keyname ..." <br>
Then what's the correct syntax to write back to the itab? Thx.
2020 May 22 7:31 AM
Hi loki_luo15
You cannot modify the internal table inside the group loop: "The internal table itab cannot be modified in the group loop unless the addition WITHOUT MEMBERS is specified.".
https://help.sap.com/doc/abapdocu_751_index_htm/7.51/en-us/abaploop_at_itab_group_by.htm.
Regards,
Mateusz
2020 May 22 9:04 AM
Your code doesn't make sense: how can you use LOOP AT GROUP inside a loop which doesn't use GROUP BY? Moreover, probably you didn't understand that MODIFY itab FROM wa1 modifies the line currently iterated by LOOP AT itab, so it's useless doing it several times (inside a secondary loop). As what you want to achieve is unclear, I cannot propose a solution.
2020 May 22 10:35 AM
@sandra.rossi. My mistake. The outer loop should be loop at itab into data(wa) group by wa-month. Then inside I will loop through this month's record and asign index to each.
2020 May 23 6:13 AM
2020 May 23 6:53 AM
Hi
loop at itab into data(wa)
location = sy-tabix.
loop at group wa into data(wa1)
wa-index = sy-tabix - location. <== use wa-index
modify itab from wa INDEX location. <== use INDEX keyword
endloop.
end loop.
| User | Count |
|---|---|
| 4 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |