Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

READ within LOOP replacement as per New Syntax 7.4 and 7.5

0 Kudos
10,819

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     ) ).
1 ACCEPTED SOLUTION

j_pavan_kumar
Product and Topic Expert
Product and Topic Expert
8,481

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

2 REPLIES 2

j_pavan_kumar
Product and Topic Expert
Product and Topic Expert
8,482

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

Sandra_Rossi
Active Contributor
0 Kudos
8,481

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 ) ).