CTS
FUNCTION Z_SD_DN_PGI1. *"---------------------------------------------------------------------- *"*"Local Interface: *" IMPORTING *" REFERENCE(I_VBELN) TYPE VBELN *" REFERENCE(I_BUDAT) TYPE BUDAT DEFAULT SY-DATUM *" EXPORTING *" REFERENCE(E_MBLNR) TYPE MBLNR *" TABLES *" T_DATA STRUCTURE ZSDS0015 *" IT_RETURN STRUCTURE BAPIRET2 OPTIONAL *"---------------------------------------------------------------------- DATA : LS_DATA LIKE LINE OF T_DATA, LT_DATA LIKE TABLE OF ZSDS0015. DATA: LV_VBELN LIKE LIKP-VBELN, LW_VBKOK LIKE VBKOK, IT_PROTT LIKE PROTT OCCURS 0 WITH HEADER LINE, "Return Message IT_VBPOK LIKE VBPOK OCCURS 0 WITH HEADER LINE. "Delivery items DATA : LV_PGI, LV_VBTYP_N TYPE VBFA-VBTYP_N, LV_COUNT TYPE I. REFRESH IT_RETURN. * 检查交货单是否已经过账 SELECT VBELN VBTYP_N INTO (E_MBLNR,LV_VBTYP_N) FROM VBFA WHERE VBELV = I_VBELN AND POSNV = 10 AND VBTYP_N IN ('R','h'). "货物移动 ENDSELECT. IF SY-SUBRC EQ 0 AND LV_VBTYP_N EQ 'R'."交货 h 取消交货 EXIT. ENDIF. LW_VBKOK-VBELN_VL = I_VBELN. "<- Delivery number LW_VBKOK-WABUC = 'X'. "<- Automatic PGI LW_VBKOK-WADAT_IST = I_BUDAT. "<- Automatic PGI Date LT_DATA[] = T_DATA[]. LOOP AT LT_DATA INTO LS_DATA. CLEAR IT_VBPOK. IT_VBPOK-VBELN_VL = I_VBELN. IT_VBPOK-POSNR_VL = LS_DATA-POSNR. IT_VBPOK-VBELN = I_VBELN. IT_VBPOK-POSNN = LS_DATA-POSNR. IT_VBPOK-CHARG = LS_DATA-CHARG. "批次 IT_VBPOK-LGORT = LS_DATA-LGORT. "库存地点 IT_VBPOK-KZLGO = 'X'. "库存地点可修改 IT_VBPOK-PIKMG = LS_DATA-PIKMG. "捡配数量 IT_VBPOK-LFIMG = LS_DATA-LFIMG. "交货数量 APPEND IT_VBPOK. ENDLOOP. PERFORM FRM_LOCK_DELIVERY(ZSDS0002) USING I_VBELN. * DO PGI LV_PGI = 'X'. FREE MEMORY ID 'PGI'. EXPORT LV_PGI TO MEMORY ID 'PGI'. FREE MEMORY ID 'PGI_DATA'. EXPORT LT_DATA FROM LT_DATA TO MEMORY ID 'PGI_DATA'. * Perform Pick and PGI CALL FUNCTION 'WS_DELIVERY_UPDATE' EXPORTING VBKOK_WA = LW_VBKOK SYNCHRON = 'X' UPDATE_PICKING = 'X' COMMIT = ' ' DELIVERY = I_VBELN NICHT_SPERREN = 'X' IF_ERROR_MESSAGES_SEND_0 = 'X' TABLES PROT = IT_PROTT VBPOK_TAB = IT_VBPOK EXCEPTIONS ERROR_MESSAGE = 1 OTHERS = 2. IF SY-SUBRC <> 0. ROLLBACK WORK. ELSE. LOOP AT IT_PROTT WHERE MSGTY EQ 'E' OR MSGTY EQ 'A' OR MSGTY EQ 'X'. EXIT. ENDLOOP. IF SY-SUBRC NE 0. COMMIT WORK AND WAIT. SELECT COUNT(*) INTO LV_COUNT FROM LIPS WHERE VBELN = I_VBELN AND LFIMG NE 0. IF LV_COUNT NE LINES( LT_DATA ). PERFORM FRM_REVERSE_POSTING(ZSDS0002) TABLES IT_RETURN USING I_VBELN I_BUDAT. MAC_APPEND_IT_RETURN: '00' '000' 'E' '实际交货数量与请求交货数量不一致,停止交货' '实际交货数量与请求交货数量不一致' ',停止交货' I_VBELN ''. EXIT. ENDIF. SELECT MBLNR INTO E_MBLNR FROM MKPF WHERE LE_VBELN = I_VBELN AND BUDAT = I_BUDAT. ENDSELECT. ELSE. ROLLBACK WORK. ENDIF. ENDIF. LOOP AT IT_PROTT. CLEAR GS_RETURN. MOVE : IT_PROTT-MSGTY TO GS_RETURN-TYPE, IT_PROTT-MSGID TO GS_RETURN-ID, IT_PROTT-MSGNO TO GS_RETURN-NUMBER, IT_PROTT-MSGV1 TO GS_RETURN-MESSAGE_V1, IT_PROTT-MSGV2 TO GS_RETURN-MESSAGE_V2, IT_PROTT-MSGV3 TO GS_RETURN-MESSAGE_V3, IT_PROTT-MSGV4 TO GS_RETURN-MESSAGE_V4. MESSAGE ID IT_PROTT-MSGID TYPE IT_PROTT-MSGTY NUMBER IT_PROTT-MSGNO WITH IT_PROTT-MSGV1 IT_PROTT-MSGV2 IT_PROTT-MSGV3 IT_PROTT-MSGV4 INTO GS_RETURN-MESSAGE. APPEND GS_RETURN TO IT_RETURN. ENDLOOP. ENDFUNCTION.
FORM frm_lock_delivery USING p_delivery. DATA : lv_time TYPE p DECIMALS 2 VALUE '0.50'. CHECK p_delivery IS NOT INITIAL. DO 50 TIMES. CALL FUNCTION 'ENQUEUE_EVVBLKE' EXPORTING vbeln = p_delivery EXCEPTIONS foreign_lock = 1 system_failure = 2 OTHERS = 3. IF sy-subrc <> 0. * Implement suitable error handling here ENDIF. IF sy-subrc EQ 0. CALL FUNCTION 'DEQUEUE_EVVBLKE' EXPORTING mode_likp = 'E' mandt = sy-mandt vbeln = p_delivery x_vbeln = ' ' _scope = '3' _synchron = ' ' _collect = ' '. WAIT UP TO lv_time SECONDS. EXIT. ELSE. WAIT UP TO lv_time SECONDS. ENDIF. ENDDO. ENDFORM. " FRM_LOCK_DELIVERY
FORM frm_reverse_posting TABLES it_return USING p_vbeln p_budat. DATA: BEGIN OF lt_mesg OCCURS 0. INCLUDE STRUCTURE mesg. DATA: END OF lt_mesg. DATA : lv_vbeln TYPE likp-vbeln, lv_budat TYPE sy-datlo. lv_vbeln = p_vbeln. lv_budat = p_budat. PERFORM frm_lock_delivery(zsds0002) USING p_vbeln. DO 10 TIMES. CALL FUNCTION 'WS_REVERSE_GOODS_ISSUE' EXPORTING i_vbeln = lv_vbeln i_budat = lv_budat i_tcode = 'VL09' i_vbtyp = 'J' TABLES t_mesg = lt_mesg EXCEPTIONS error_reverse_goods_issue = 1 OTHERS = 2. IF sy-subrc = 0. * 删除交货单 COMMIT WORK. PERFORM frm_delete_delivery_note TABLES it_return USING p_vbeln. EXIT. ENDIF. WAIT UP TO 1 SECONDS. ENDDO. ENDFORM. " FRM_REVERSE_POSTING
FORM frm_delete_delivery_note TABLES it_return STRUCTURE bapiret2 USING p_vbeln. DATA : lv_delivery TYPE likp-vbeln. CHECK p_vbeln IS NOT INITIAL. lv_delivery = p_vbeln. PERFORM frm_lock_delivery(zsds0002) USING lv_delivery. REFRESH bdcdata. * Go to VL02N * Init Screen and input DN number PERFORM bdc_dynpro USING 'SAPMV50A' '4004'. PERFORM bdc_field USING 'BDC_CURSOR' 'LIKP-VBELN'. PERFORM bdc_field USING 'BDC_OKCODE' '/00'. PERFORM bdc_field USING 'LIKP-VBELN' lv_delivery. * Delete DN PERFORM bdc_dynpro USING 'SAPMV50A' '1000'. PERFORM bdc_field USING 'BDC_OKCODE' '/ELOES_T'. PERFORM bdc_transaction TABLES it_return USING 'VL02N'. ENDFORM.
^_^很多人都把资料锁进了note里,以后还怎么百度呢^_^