2023 Feb 19 2:59 PM
Hi All,
I am using below code to replace LOOP with READ statemnst as per ABAP 7.4 and 7.5 syntax, :
Here LT_STOCK table will be read every time by below key : WH = LS_BIN-WH BATCH = LS_BIN-BATCH
Instead, is there any way to get LT_STOCK contents in work-area LS_STOCK and use it for mapping.
We can use FOR LOOP twice and achieve it but it does not give readability as LT_STOCK will always have
1 record for key WH and Batch. IF use 2 FOR LOOPS it gives impression that it is conventional LOOP within LOOP scenario rather than READ within LOOP.
Kindly suggest.
DATA(LT_FINAL) = VALUE TT_FINAL( FOR LS_BIN IN LT_BINS ( MATERIAL = LT_STOCK[ WH = LS_BIN-WH BATCH = LS_BIN-BATCH ]-MATERIAL
STOCK_TYPE = LT_STOCK[ WH = LS_BIN-WH BATCH = LS_BIN-BATCH ]-STOCK_TYPE
QUANTITY = LT_STOCK[ WH = LS_BIN-WH BATCH = LS_BIN-BATCH ]-QUANTITY
UNIT = LT_STOCK[ WH = LS_BIN-WH BATCH = LS_BIN-BATCH ]-UNIT ) ).
2023 Feb 19 5:05 PM
Hi Snehal,
You can use LET after the for loop to read the record. Please see the below example.
DATA(LT_FINAL) = VALUE TT_FINAL( FOR LS_BIN IN LT_BINS
LET ls_stock = VALUE #( lt_stock[ WH = LS_BIN-WH BATCH = LS_BIN-BATCH ] OPTIONAL )
IN ( MATERIAL = ls_stock-MATERIAL
STOCK_TYPE = ls_stock-STOCK_TYPE
QUANTITY = ls_stock-QUANTITY
UNIT = ls_stock-UNIT ) ).
Thanks,
Pavan
2023 Feb 19 5:05 PM
Hi Snehal,
You can use LET after the for loop to read the record. Please see the below example.
DATA(LT_FINAL) = VALUE TT_FINAL( FOR LS_BIN IN LT_BINS
LET ls_stock = VALUE #( lt_stock[ WH = LS_BIN-WH BATCH = LS_BIN-BATCH ] OPTIONAL )
IN ( MATERIAL = ls_stock-MATERIAL
STOCK_TYPE = ls_stock-STOCK_TYPE
QUANTITY = ls_stock-QUANTITY
UNIT = ls_stock-UNIT ) ).
Thanks,
Pavan
2023 Feb 20 8:27 AM
I notice that you take all your data from LT_STOCK, just filtering lines from LT_STOCK which are in LT_BINS.
So I would opt for FILTER combined with either VALUE or CORRESPONDING (depends whether LT_STOCK and LT_FINAL have same types or not).
e.g.
DATA(lt_final) = CORRESPONDING #( FILTER( lt_stock IN lt_bins WHERE wh = wh AND batch = batch ) ).