2016 Jun 13 8:19 AM
Hello Experts,
I am displaying three fields in my report . i wants total po quantity against vendor.
how i can display.
PLEASE REFER FOLLOWING CODE.
form GET_DATA .
SELECT LIFNR EBELN FROM EKKO INTO TABLE IT_EKKO
WHERE LIFNR IN S_LIFNR.
IF NOT IT_EKKO[] IS INITIAL.
SELECT EBELN ELIKZ MENGE FROM EKPO INTO TABLE IT_EKPO
FOR ALL ENTRIES IN IT_EKKO
WHERE EBELN = IT_EKKO-EBELN
AND ELIKZ = ''.
SELECT LIFNR TOTAL_STOCK UNIT FROM ZVENDOR_STOCK INTO TABLE IT_STOCK
FOR ALL ENTRIES IN IT_EKKO
WHERE LIFNR = IT_EKKO-LIFNR.
ENDIF.
endform. " GET_DATA
*&---------------------------------------------------------------------*
*& Form COMBINE_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form COMBINE_DATA .
DATA : SUM_MENGE(13) TYPE C.
LOOP AT IT_EKKO INTO WA_EKKO.
* WA_FINAL-EBELN = WA_EKPO-EBELN.
WA_FINAL-LIFNR = WA_EKKO-LIFNR.
WA_FINAL-EBELN = WA_EKKO-EBELN.
READ TABLE IT_EKPO INTO WA_EKPO WITH KEY EBELN = WA_FINAL-EBELN .
WA_FINAL-SUM_MENGE = WA_FINAL-SUM_MENGE + WA_EKPO-MENGE.
* COLLECT WA_FINAL-MENGE INTO IT_FINAL.
**** data : sum_menge(13) type c.
****LOOP AT it_ekpo INTO wa_ekpo.
**** AT NEW ebeln .
**** sum_menge = sum_menge + wa_ekpo-menge.
**** ENDAT.
****wa_final-menge = sum_menge.
****MODIFY it_final FROM wa_final.
****CLEAR: sum_menge.
READ TABLE IT_STOCK INTO WA_STOCK WITH KEY LIFNR = WA_FINAL-LIFNR.
*on change of wa_ekko-lifnr.
WA_FINAL-TOTAL_STOCK = WA_STOCK-TOTAL_STOCK.
APPEND WA_FINAL TO IT_FINAL.
*modify it_final from wa_final.
*endon.
CLEAR:WA_FINAL , WA_EKKO , WA_EKPO , WA_STOCK .
ENDLOOP.
endform. " COMBINE_DATA
2016 Jun 13 8:36 AM
3 fields? or 4?
WA_FINAL-LIFNR = WA_EKKO-LIFNR.
WA_FINAL-EBELN = WA_EKKO-EBELN.
WA_FINAL-SUM_MENGE
WA_FINAL-TOTAL_STOCK
You want to add sum_menge and total_stock? If so you can add it directly as long the two fields have the same data type.
ADD wa_final-sum_menge TO wa_final_total-stock.
2016 Jun 13 8:56 AM
hello elzkie ,
I wants to sum of MENGE against vendor.
dont consider field sum_menge.
thnks in advance,
2016 Jun 13 8:59 AM
Hello elzkie.
Only need three fields.
vendor code
total PO qty problem is here. i wants subtotal of po against vendor. without displaying quantity.
total_sock field in zvendor table.
2016 Jun 13 10:14 AM
You can use collect for this.
SORT it_ekpo BY lifnr.
LOOP AT it_ekpo INTO wa_ekpo.
wa_final-lifnr = wa_ekpo-lifnr. "Vendor
wa_final-total_po_qty = wa_ekpo-menge. "Total Qty
READ TABLE it_stock INTO wa_stock WITH KEY lifnr = wa_final-lifnr.
IF sy-subrc EQ 0.
wa_final-total_stock = wa_stock-total_stock.
ENDIF.
COLLECT wa_final INTO it_final.
ENDLOOP.
2016 Jun 13 11:21 AM
2016 Jun 13 9:51 AM
Hi Nilesh,
Use LOOP instead of READ. Refer below code to sum up MENGE:
LOOP AT IT_EKKO INTO WA_EKKO.
WA_FINAL-LIFNR = WA_EKKO-LIFNR.
WA_FINAL-EBELN = WA_EKKO-EBELN.
loop at IT_EKPO INTO WA_EKPO where EBELN = WA_FINAL-EBELN .
WA_FINAL-SUM_MENGE = WA_FINAL-SUM_MENGE + WA_EKPO-MENGE.
clear WA_EKPO.
endloop.
----rest of code----
ENDLOOP.
2016 Jun 13 11:21 AM
2016 Jun 13 11:29 AM
there's a mistake in above code i pasted. Create a variable to store sum of quantity and then move it to wa_final. Check below:
Data: LV_MENGE_SUM type EKPO-MENGE.
LOOP AT IT_EKKO INTO WA_EKKO.
WA_FINAL-LIFNR = WA_EKKO-LIFNR.
WA_FINAL-EBELN = WA_EKKO-EBELN.
clear LV_MENGE_SUM.
loop at IT_EKPO INTO WA_EKPO where EBELN = WA_FINAL-EBELN .
LV_MENGE_SUM = LV_MENGE_SUM + WA_EKPO-MENGE.
clear WA_EKPO.
endloop.
WA_FINAL-SUM_MENGE = LV_MENGE_SUM.
----rest of code----
ENDLOOP.
2016 Jun 13 11:50 AM
2016 Jun 13 11:58 AM
No, there's a difference. In earlier case, it was summing up for all PO, but now it will sum up quantities only for corresponding EBELN. See the clear statement before second LOOP statement.
2016 Jun 13 1:11 PM
Hi.
See if this works.
Define one internal table with lifnr and MENGE say it as it_menge.
loop at IT_EKPO INTO WA_EKPO.
clear wa_ekko.
read table it_ekko into wa_ekko with key ebeln - wa_ekpo-ebeln.
if sy-subrc eq 0.
wa_menge-lifnr = wa_ekko-lifnr.
wa_menge-menge = wa_ekpo-menge.
collect wa_menge into it_menge.
clear wa_menge.
endif.
clear wa_ekpo.
endloop.
loop at it_ekpo into wa_ekpo.
clear wa_ekko.
read table it_ekko into wa_ekko with key ebeln = wa_ekpo-ebeln.
if sy-subrc eq 0.
clear wa_menge.
read table it_menge into wa_menge with key lifnr = wa_ekko-lifnr.
if sy-subrc eq 0.
wa_final-ebeln = wa_ekpo-ebeln.
wa_final-lifnr = wa_ekko-lifnr.
wa_final-menge = wa_menge-menge.
append wa_final into it_final.
clear wa_final.
endif.
endif.
clear wa_ekpo.
endloop.
Regards,
Sid
2016 Jun 21 6:53 AM
First correct your current code, the FAE remove duplicates and you didn't select item number EBELP, so you will lose records with same quantity and final status in a single PO.
You should also consider
Else try to code the LOOP like following pattern:
SORT itab_ekpo BY lifnr. (or use a sorted type in definition of itab)
LOOP AT itab_ekpo
AT NEW lifnr.
initialize itab_final record with LIFNR
READ TABLE itab_zstock to update the qty field
ENDAT
ADD menge to record
AT END OF lifnr
APPEND itab_final (or WRITE /)
ENDAT
ENDLOOP
If you cannot sort by vendor due to your conception/coding, use a READ TABLE to identify (and create first time) the vendor record.
But without material number/unit of measure, it seems you will confuse apples with oranges, is this an exercise?
Regards,
Raymond