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

problem in summing up inside loop

Former Member
0 Likes
497

Hi Experts..........

The below is my loop code , the problem is suppose if i have 2 line items for one purchase order

i need to sum up the quantity amount etc, displaying the purchase order number only ones,

in order i have made a loop at ekpo where i have the line items , but still i am not able to

sum up , instead all the line items appearing ,

if i give the statmt

delete adjacent duplicates from it_ekpo comparing ebeln.

only first line item is displayed...pls help me out in this issue

sort it_ekpo by ebeln.

sort it_bkpf by belnr.


loop at it_ekpo into wa_ekpo  .
    read table it_ekko into wa_ekko with key ebeln = wa_ekpo-ebeln.

                  wa_final-ematn = wa_ekpo-ematn.
                  wa_final-txz01 = wa_ekpo-txz01.
                  wa_final-menge = wa_ekpo-menge.
                  wa_final-netwr = wa_ekpo-netwr.

        QTY =  QTY + WA_FINAL-MENGE.
        move qty to wa_final-qty.




*******FOR TAX CODE 46 for

If wa_ekpo-mwskz = '46'.
wa_final-ZBED = ( wa_final-netwr * TAX3 ) / 100.
   tot2 = tot2 + wa_final-zbed.
      move tot2 to wa_final-t3.
wa_final-ZEX1 = ( wa_final-netwr * TAX4 ) / 100.
    tot3 = tot3 + wa_Final-zex1.
    move tot3 to  wa_final-t4.
wa_final-ZEX2 = ( wa_final-netwr * TAX5 ) / 100.
    tot4 = tot4 + wa_final-zex2.
      move tot4 to wa_final-t4.
wa_final-JIPC = ( wa_final-netwr * TAX2 ) / 100.
    tot5 = tot5 + wa_final-jipc.
    move tot5 to wa_final-t5.

Endif.

              loop at it_bkpf into wa_bkpf .
            wa_final-budat = wa_bkpf-budat.

        loop at it_bseg into wa_bseg where ebeln = wa_ekpo-ebeln."belnr = wa_bkpf-belnr.
             wa_final-ebeln =  wa_bseg-ebeln.

    read table it_lfa1 into wa_lfa1 with key lifnr = wa_bseg-lifnr.
          if sy-subrc = 0.
              wa_final-name1 = wa_lfa1-name1.
            wa_final-ort01 = wa_lfa1-ort01.
          Endif.

    read table  it_J_1IMOVEND into  wa_J_1IMOVEND with key lifnr = wa_bseg-lifnr.
           if sy-subrc = 0.
                wa_final-J_1ILSTNO =  wa_J_1IMOVEND-J_1ILSTNO.
           endif.

     Endloop.

  Endloop.

 append wa_final to it_final.
 clear :wa_bkpf, wa_ekpo,wa_ekko,qty, wa_final.

delete adjacent duplicates from it_ekpo comparing ebeln.

Endloop.
Endif.

Thanks in advance

Rachel

4 REPLIES 4
Read only

Former Member
0 Likes
471

hi,

write the code delete adjacent duplicate outside the loop endloop.... it should not be within the loop.

this will resolve your issue

something like the code given below....

sort it_ekpo by ebeln.
 
sort it_bkpf by belnr.
 
 
loop at it_ekpo into wa_ekpo  .
    read table it_ekko into wa_ekko with key ebeln = wa_ekpo-ebeln.
 
                  wa_final-ematn = wa_ekpo-ematn.
                  wa_final-txz01 = wa_ekpo-txz01.
                  wa_final-menge = wa_ekpo-menge.
                  wa_final-netwr = wa_ekpo-netwr.
 
        QTY =  QTY + WA_FINAL-MENGE.
        move qty to wa_final-qty.
 
 
 
 
*******FOR TAX CODE 46 for
 
If wa_ekpo-mwskz = '46'.
wa_final-ZBED = ( wa_final-netwr * TAX3 ) / 100.
   tot2 = tot2 + wa_final-zbed.
      move tot2 to wa_final-t3.
wa_final-ZEX1 = ( wa_final-netwr * TAX4 ) / 100.
    tot3 = tot3 + wa_Final-zex1.
    move tot3 to  wa_final-t4.
wa_final-ZEX2 = ( wa_final-netwr * TAX5 ) / 100.
    tot4 = tot4 + wa_final-zex2.
      move tot4 to wa_final-t4.
wa_final-JIPC = ( wa_final-netwr * TAX2 ) / 100.
    tot5 = tot5 + wa_final-jipc.
    move tot5 to wa_final-t5.
 
Endif.
 
              loop at it_bkpf into wa_bkpf .
            wa_final-budat = wa_bkpf-budat.
 
        loop at it_bseg into wa_bseg where ebeln = wa_ekpo-ebeln."belnr = wa_bkpf-belnr.
             wa_final-ebeln =  wa_bseg-ebeln.
 
    read table it_lfa1 into wa_lfa1 with key lifnr = wa_bseg-lifnr.
          if sy-subrc = 0.
              wa_final-name1 = wa_lfa1-name1.
            wa_final-ort01 = wa_lfa1-ort01.
          Endif.
 
    read table  it_J_1IMOVEND into  wa_J_1IMOVEND with key lifnr = wa_bseg-lifnr.
           if sy-subrc = 0.
                wa_final-J_1ILSTNO =  wa_J_1IMOVEND-J_1ILSTNO.
           endif.
 
     Endloop.
 
  Endloop.
 
 append wa_final to it_final.
 clear :wa_bkpf, wa_ekpo,wa_ekko,qty, wa_final.
 
Endloop.
delete adjacent duplicates from it_ekpo comparing ebeln.
Endif.

Regards,

Siddarth

Read only

0 Likes
471

sorry still i face the same problem.......

Read only

Former Member
0 Likes
471

hi,

create anothere internal table of the same structure..pass the values this inernal table using statement

itab1[] = itab2[].

sort the table itab1 by ebeln

then delete adjacent dupicate from itab1 comparing ebeln,

then loop the internal table itab1 and loop the other internal table itab2 inside it has below

loop at itab1.

loop at itab2 where ebeln = itab1-ebeln.

.....add the quantity.

endloop.

endloop.

Regrds

Yogi

Read only

Former Member
0 Likes
471

hi,

as per my understanding.. assume 3 same order number with diffrent line item ..and you have to add the qntity of the three line item .. and make it single row aganis order numner rt?

loop at itab1 into wa_itab1.

loop at itab2 into wa_itan2 with key ordernumbr = wa_itab1-ordernumber lineitem = wa_itab1-lineitem.

if sy-subrc = 0.

wa_final = add the qntity .

  • other conditions A " according to your req inside loop

endif.

endloop.

other conditions A " according to your req outside loop.

or

you can use key word COLLECT in final itable but dont insert line item in this table.

loop at itab.

read table itab1 into wa2 with key ordernumbr = itab-ordernumber line-item =itab-line

if sy-subrc = 0.

wa_final-qnty = itan1 0r itab-qnty.

endif.

append wa_final to finaltab

endloop.

COLLECT FINALITAB.