‎2020 Apr 14 4:11 PM
Hi all,
I loop over clients and I want to get the orders of that client every time :
loop at lt_client into ls_client.
read table lt_orders
into ls_orders
with key client_id = ls_orders-client_id.
end loop.
the problem is that I get the first order of the client every time.
Ex : I have client1 that has Order1, Order2 and Order3
I want to read into ls_orders :
- Order1 in the first loop
- Order2
- and order 3
Any Ideas?
‎2020 Apr 14 4:53 PM
error:
with key client_id = ls_orders-client_id.correction:
with key client_id = ls_client-client_id.
‎2020 Apr 14 5:07 PM
You need to do a nested loop. With your current logic, it would look like this:
LOOP AT lt_client INTO ls_client.
" do client/customer logic based on ls_client
LOOP AT lt_orders INTO ls_orders WITH KEY client_id = ls_client-client_id.
" do orders of customer logic based on ls_orders
ENDLOOP.
ENDLOOP.For performance reasons, if necessary, I would recommend an index on lt_orders by client. And also assign field-symbols instead of copying to new objects (unless you are messing around with values that shouldnt be updated in the table data):
DATA: lt_client TYPE SORTED TABLE OF .... WITH UNIQUE KEY client_id.
FIELD-SYMBOLS: <fs_client> LIKE LINE OF lt_client,
<fs_order> LIKE LINE OF lt_orders.
LOOP AT lt_client ASSIGNING <fs_client>.
" do client/customer logic based on <fs_client>
LOOP AT lt_orders ASSIGNING <fs_order> WITH TABLE KEY client_id = <fs_client>-client_id.
" do orders of customer logic based on <fs_order>
ENDLOOP.
ENDLOOP.
‎2020 May 13 4:08 PM
khalilferhat, please follow up on your open question.