This is to Check the Sales Order Stock Check during Creation of the DO with ref to SO.This can be written in Delivery Copy Control Requirement routine.
DATA: l_so_stock LIKE bapicm61v-wkbst.
DATA:BEGIN OF it_vbfa OCCURS 0,
vbelv LIKE vbfa-vbelv,
posnv LIKE vbfa-posnv,
vbeln LIKE vbfa-vbeln,
posnn LIKE vbfa-posnn,
END OF it_vbfa.
DATA: BEGIN OF it_vbuk OCCURS 0,
vbeln LIKE vbfa-vbeln,
END OF it_vbuk.
DATA: BEGIN OF it_lips OCCURS 0,
vbeln LIKE lips-vbeln,
posnr LIKE lips-posnr,
lfimg LIKE lips-lfimg,
END OF it_lips.
*Check the sales Order stock
CLEAR : atp_qty,yxwmdvs[],yxwmdve[], l_so_stock.
yxwmdvs-req_qty = cvbap-kwmeng.
APPEND yxwmdvs.
*Check the sales order stock for that item.
CALL FUNCTION 'BAPI_MATERIAL_AVAILABILITY'
EXPORTING
plant = cvbap-werks
stge_loc = cvbap-lgort
material = cvbap-matnr
doc_number = cvbap-vbeln " Sales Order
itm_number = cvbap-posnr " Sales Item
unit = cvbap-meins
stock_ind = 'E' " Sales Order Stock
check_rule = 'BE' " Mile stone orders
IMPORTING
av_qty_plt = l_so_stock
TABLES
wmdvsx = yxwmdvs
wmdvex = yxwmdve.
IF sy-subrc = 0 AND l_so_stock GT 0 .
atp_qty = l_so_stock.
* get all the Delivery Orders for this Item.
REFRESH: it_vbfa[],it_vbuk[],it_lips[].
* Compute the remaining ATP Qty.If there is no PGi for a Delv , that qty will still be shown inn
* the Function module. so reduce that qty from the atp qty.
* get all delivery for the selected orders.
SELECT vbelv posnv vbeln posnn INTO TABLE it_vbfa FROM vbfa
WHERE vbelv = cvbap-vbeln AND posnv = cvbap-posnv
AND vbtyp_n = 'J' AND vbtyp_v = 'C'.
*Check the status of the Goods Movement (PGI)
IF NOT it_vbfa[] IS INITIAL.
SELECT vbeln FROM vbuk INTO TABLE it_vbuk
FOR ALL ENTRIES IN it_vbfa
WHERE vbeln = it_vbfa-vbeln AND
wbstk NE 'C'.
ENDIF.
* Collect deliveries which doesnt have PGI Doc.
LOOP AT it_vbfa.
READ TABLE it_vbuk WITH KEY vbeln = it_vbfa-vbeln.
IF sy-subrc NE 0.
DELETE it_vbfa WHERE vbeln = it_vbfa-vbeln .
ENDIF.
ENDLOOP.
*Get the Delv Qty
IF NOT it_vbfa[] IS INITIAL.
SELECT vbeln posnr lfimg INTO TABLE it_lips FROM lips
FOR ALL ENTRIES IN it_vbfa
WHERE vbeln = it_vbfa-vbeln AND
posnr = it_vbfa-posnn.
ENDIF.
* Now ATP qty = ATP QTY - Delv Qty(with NO PGI).
LOOP AT it_lips.
atp_qty = atp_qty - it_lips-lfimg.
ENDLOOP.
IF atp_qty GT 0.
bp_subrc = 0.
ELSE.
bp_subrc = 4." NO atp Qty
ENDIF.
ELSE.
bp_subrc = 4." NO atp Qty
ENDIF.
Thanks & Regards
Durga Prasad
No comments:
Post a Comment