Hi!
Instead of,
"READ TABLE ITAB_2 WITH KEY DATE = WA_1-DATE INTO WA_2. " you can also write:
LOOP AT ITAB_1 INTO WA_1.
AT NEW DATE.
WA_2-DATE = WA_1-DATE.
WA_2-CID = WA_1-CID.
WA_2-MAX_REV = WA1_REV.
WA_2-MIN_REV = WA1_REV.
APPEND WA_2 TO ITAB_2.
CLEAR WA_2.
END AT.
LOOP AT ITAB_2 INTO WA_2.
IF WA_2-DATE = WA_1_DATE AND WA_2-CID <> WA_1-CID.
IF WA_2-MAX_REV <= WA_1-REV.
WA_2-MAX_REV = WA_1-REV.
ELSE
IF WA_2-MIN_REV >= WA_1-REV.
WA_2-MIN_REV = WA_1-REV.
ENDIF.
MODIFY ITAB_2 FROM WA_2 WHERE DATE = WA_2-DATE TRANSPORTING MIN_REV MAX_REV.
ENDIF.
ENDLOOP.
=> But if you see, we are having to perform the same logic using a loop within a loop, which is not efficient. Rather than looping, we are first sorting ITAB_2 with date, and then with date as index we are directly searching for the record - binary search - which is faster than loop within loop.
Hope it helps. And let me know if you are getting the desired output.
If not i will check in the system and get back to you.
Regards,
Khushboo