‎2021 Mar 12 5:31 PM
HI EXPERT
This is my code that I display using ALV REPORT . My data is correct just before I get into the reading table, but after I get into READ TABLE Displays data incorrectly. Why does it not enter the data correctly in the final table?
SELECT QALS~PRUEFLOS QALS~KTEXTLOS
QALS~AUFNR QASR~VORGLFNR
QALS~MATNR MAKT~MAKTX
INTO TABLE IT_FINAL
FROM QALS
INNER JOIN QASR ON QASR~PRUEFLOS = QALS~PRUEFLOS
INNER JOIN MAKT ON QALS~MATNR = MAKT~MATNR
WHERE QALS~ART = '03'
AND QASR~VORGLFNR IN ('22' , '23' , '24')
AND MAKT~SPRAS = 'EN' .
IF IT_FINAL IS NOT INITIAL .
SELECT PRUEFLOS VCODE
INTO TABLE IT_QAVE1
FROM QAVE
FOR ALL ENTRIES IN IT_FINAL
WHERE PRUEFLOS = IT_FINAL-PRUEFLOS .
LOOP AT IT_FINAL INTO WA_FINAL .
READ TABLE IT_QAVE1 INTO WA_QAVE1 WITH KEY PRUEFLOS = WA_FINAL-PRUEFLOS .
WA_FINAL-VCODE = WA_QAVE1-VCODE .
CLEAR : WA_QAVE1 ,WA_FINAL .
ENDLOOP.
ENDIF.
<br>
‎2021 Mar 13 6:49 AM
Hi Afsane Salehi,
When we works with READ TABLE , we must have to do Sorting and binary search. Below is the Updated code . Check Once.
SORT IT_FINAL.
LOOP AT IT_FINAL INTO WA_FINAL .
READ TABLE IT_QAVE1 INTO WA_QAVE1 WITH KEY PRUEFLOS = WA_FINAL-PRUEFLOS BINARY SEARCH .
WA_FINAL-VCODE = WA_QAVE1-VCODE .
CLEAR: WA_QAVE1 ,WA_FINAL .
ENDLOOP.Thanks and Regards,
Chaitali Pandya
‎2021 Mar 12 5:54 PM
You want to update the VCODE value in your IT_FINAL table? Then you have to use either a field-symbol or a reference. The loop "transfers" the data just into a structure; if you update the structure and not no update on the internal table, the internal table is not changed.
One option using a reference is like following (your_line_type needs to be replaced with the type you used for your workarea; if you have an NW system > 7.40 you could use a lot more modern syntax, but as I do not know if you have that option, I sticked with the old stuff):
DATA lr_final TYPE REF TO your_line_type.
LOOP AT IT_FINAL REFERENCE INTO lr_final.
READ TABLE IT_QAVE1 INTO WA_QAVE1 WITH KEY PRUEFLOS = WA_FINAL-PRUEFLOS.
IF sy-subrc = 0.
lr_final-vcode = wa_qave1-vcode.
ENDIF.
ENDLOOP.
‎2021 Mar 12 5:57 PM
Hi!
LOOP AT IT_FINAL INTO WA_FINAL .Is only making a copy if the table line into WA_FINAL so you are only assigning the WA_QAVE1-VCODE to that copy. Also on the next line you are clearing it again, and you're not expecting the line to be cleared in the table, I suppose...
You should prefer to declare a field-symbol instead. That way you can change the table line data inside of the LOOP. Make sure not to clear it though. And for good measure, I recommend checking sy-subrc after the READ TABLE.
LOOP AT IT_FINAL ASSIGNING FIELD-SYMBOL(<wa_final>).
READ TABLE IT_QAVE1 INTO WA_QAVE1 WITH KEY PRUEFLOS = WA_FINAL-PRUEFLOS .
IF sy-subrc = 0.
<wa_final>-VCODE = WA_QAVE1-VCODE.
ENDIF.
ENDLOOP.ABAP Documentation, look for ASSIGNING.
Addition: I don't really know the tables QAVE and QALS and what you need, but there is a chance that you can JOIN them instead of doing the FOR ALL ENTRIES and LOOP. But since you are not use the full key of QAVE so you might get more lines from that one...
‎2021 Mar 13 8:55 AM
Or
LOOP AT IT_FINAL REFERENCE INTO DATA(line).
READ TABLE IT_QAVE1 INTO WA_QAVE1
WITH KEY PRUEFLOS = WA_FINAL->PRUEFLOS.
CHECK sy-subrc = 0.
line->VCODE = WA_QAVE1-VCODE.
ENDLOOP.
‎2021 Mar 13 5:10 AM
The origin of this issue can be found easily by using the debugger.
‎2021 Mar 13 5:12 AM
Try this,
LOOPAT IT_FINAL ASSIGNINGFIELD-SYMBOL(<wa_final>).
READTABLE IT_QAVE1 INTO WA_QAVE1 WITHKEY PRUEFLOS = WA_FINAL-PRUEFLOS.
IFsy-subrc =0.
<wa_final>-VCODE = WA_QAVE1-VCODE.
ENDIF.
ENDLOOP.
append required data to final inernal table
‎2021 Mar 13 6:49 AM
Hi Afsane Salehi,
When we works with READ TABLE , we must have to do Sorting and binary search. Below is the Updated code . Check Once.
SORT IT_FINAL.
LOOP AT IT_FINAL INTO WA_FINAL .
READ TABLE IT_QAVE1 INTO WA_QAVE1 WITH KEY PRUEFLOS = WA_FINAL-PRUEFLOS BINARY SEARCH .
WA_FINAL-VCODE = WA_QAVE1-VCODE .
CLEAR: WA_QAVE1 ,WA_FINAL .
ENDLOOP.Thanks and Regards,
Chaitali Pandya