Application Development and Automation 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 only

Incorrect Data if executing for multiple material, but correct for single material

PragatiBabbar
Explorer
0 Likes
2,488

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!!!

9 REPLIES 9
Read only

FredericGirod
Active Contributor
2,415

Cristal ball said, you forget to clear the structure before inserting data.

Read only

PragatiBabbar
Explorer
0 Likes
2,414

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

Read only

0 Likes
2,414

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.

Read only

Sandra_Rossi
Active Contributor
2,414

Show your code, or if you are sure your code is correct maybe standard code contains an error, search SAP notes.

Read only

RaymondGiuseppi
Active Contributor
0 Likes
2,414

How do you load this data, SQL statements, SAP procedure calls?

Can you post (in the question or as a comment to it and not as an answer) the most relevant code.

It is probably a bad initialization or a bad processing of the read data, but without the source, it will be almost impossible to help you?

Read only

PragatiBabbar
Explorer
0 Likes
2,414

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.
Read only

Sandra_Rossi
Active Contributor
0 Likes
2,414

As Raymond said, "how do you load this data" ? I don't see any BAPI here.

Read only

BaerbelWinkler
SAP Champion
SAP Champion
2,414

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.

Read only

PragatiBabbar
Explorer
0 Likes
2,414

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.