‎2022 May 05 7:54 AM
Hi guys,
I am facing an issue with an ALV report, where if I am executing for single material, it is showing correct values. Similarly, if I am trying to execute it for 2 materials, the second row is correct, but the first row is showing incorrect values for two particular columns.
Thanks in advance!!!
‎2022 May 05 8:25 AM
Cristal ball said, you forget to clear the structure before inserting data.
‎2022 May 05 8:40 AM
I am attaching screenshots for better understanding of the issue.
IF Executing for single material: CORRECT values of highlighted columns

--------------------
IF Executing for two materials: INCORRECT VALUE OF this column, but the second-row values are correct

‎2022 May 05 1:19 PM
Prefer editing your question to contain all this information.
ANSWER is only to propose a solution, dixit SAP text at the right of the answer area.
‎2022 May 05 8:51 AM
Show your code, or if you are sure your code is correct maybe standard code contains an error, search SAP notes.
‎2022 May 05 10:37 AM
‎2022 May 05 12:30 PM
Code for reference:
READ TABLE it_vbrp1 INTO wa_vbrp1 WITH KEY matnr = wa_mara-matnr BINARY SEARCH.
IF sy-subrc = 0.
lv_index3 = sy-tabix.
LOOP AT it_vbrp1 INTO wa_vbrp1 FROM lv_index3.
IF ( wa_vbrp1-matnr = wa_mara-matnr ).
wa_final-fkimg = wa_vbrp1-fkimg .
wa_final-netwr = wa_vbrp1-netwr .
wa_final-kzwi1 = wa_vbrp1-kzwi1 .
"------------------------ 04.05.2022 (Supplemetary data)--------------"
wa_final-fkimg1 = wa_vbrp1-fkimg. "----------------------for Quantity
wa_final-amount = wa_vbrp1-netwr. "----------------------for amount
"-----------------------------------------------------------------------------"
READ TABLE it_vbrk INTO wa_vbrk WITH KEY vbeln = wa_vbrp1-vbeln.
IF sy-subrc = 0.
wa_final-fkart = wa_vbrk-fkart.
wa_final-vbtyp = wa_vbrk-vbtyp.
ENDIF.
IF ( ( wa_final-fkart = 'ZDAG' OR wa_final-fkart = 'ZSCR' OR wa_final-fkart = 'ZRMS' ) AND wa_final-vbtyp = 'M' ).
wa_final-qty = wa_final-qty + wa_final-fkimg .
wa_final-value = wa_final-value + wa_final-netwr .
ELSEIF wa_final-fkart = 'ZRE' OR wa_final-fkart = 'ZRE1' OR wa_final-fkart = 'ZSTR'. "---Addind ZRE/ZRE1/ZSTR for D3 inclusion
wa_final-fkimg = wa_final-fkimg * -1.
wa_final-netwr = wa_final-netwr * -1.
wa_final-qty = wa_final-qty + wa_final-fkimg .
wa_final-value = wa_final-value + wa_final-netwr .
ENDIF.
IF ( ( wa_final-fkart = 'ZIPT' OR wa_final-fkart = 'ZSTO' OR wa_final-fkart = 'ZIPS' ) AND ( wa_final-vbtyp = 'M' OR wa_final-vbtyp = 'U' ) ).
wa_final-qty1 = wa_final-qty1 + wa_final-fkimg .
wa_final-value1 = wa_final-value1 + wa_final-netwr .
ENDIF.
"------------------------ JWP ----------------"
IF ( ( wa_final-fkart = 'ZJWP' OR wa_final-fkart = 'ZJWI' ) AND wa_final-vbtyp = 'M' ).
wa_final-qty2 = wa_final-qty2 + wa_final-fkimg.
IF wa_final-fkart = 'ZJWP'.
wa_final-value2 = wa_final-value2 + wa_final-kzwi1.
"------------ 04.05.2022 (SUPPLEMENTARY)--------------*
wa_final-amount = wa_final-kzwi1.
"-------------------------------------------------------------*
ELSE.
wa_final-value2 = wa_final-value2 + wa_final-netwr.
"----------- 04.05.2022 (SUPPLEMENTARY)--------------*
wa_final-amount = wa_final-netwr.
"------------------------------------------------------------*
ENDIF.
ENDIF.
* ------------------------------ 04.05.2022 (Supplemetary add) -------------------"
IF wa_final-vbtyp = 'O' OR wa_final-vbtyp = 'N' OR wa_final-vbtyp = 'M'.
wa_final-fkimg1 = wa_final-fkimg1 * -1. "--------for actual Quantity
wa_final-amount1 = wa_final-amount * -1. "--------for actual Amount
ELSE.
wa_final-fkimg1 = wa_final-fkimg1.
wa_final-amount1 = wa_final-amount.
ENDIF.
* ----------------------------------------------------------------------------------------"
ELSE.
EXIT .
ENDIF.
ENDLOOP.
‎2022 May 05 1:20 PM
As Raymond said, "how do you load this data" ? I don't see any BAPI here.
‎2022 May 05 1:52 PM
The logic looks rather involved with the many nested IF-statements which makes it difficult to follow without seeing the data used within the loop.
Have you tried stepping through your logic with debugging to actually see what is happening? This would be the first step I'd take in a case like this.
‎2022 May 06 5:58 AM
From debugging, I find out that the value I am getting in the first iteration of loop is correct,
but in the third iteration, the value became incorrect.