类似VA02-检查项目可用性功能
"DELTA_MANAGEMENT
DATA: l_atpdtLIKE atpdt.
DATA: p_yvbbeTYPE TABLE OF atp_vbbe_ext.
DATA: wa_yvbbe TYPE atp_vbbe_ext.
DATA: wa_vbbeTYPE atp_vbbe_ext.
"S4 ATP Check
DATAls_atpca TYPE atpca.
DATAls_atpcs TYPE atpcs.
DATAlt_atpcs TYPE TABLE OF atpcs.
DATA: p_mdvexTYPE TABLE OF mdve,
wa_mdvex TYPE mdve.
"SD_BACKORDER_UPDATE 更新手工确认
DATA: it_mdvu TYPE TABLE OF mdvu,
wa_mdvu TYPE mdvu.
DATA: it_return TYPE TABLE OF bapiret2,
wa_return TYPE bapiret2.
LOOP AT gt_data INTO gs_data.
CLEAR: p_yvbbe,wa_yvbbe.
SELECT *
INTO CORRESPONDING FIELDS OF TABLE p_yvbbe FROM vbbe
WHERE vbeln = gs_data-vbeln
AND posnr = gs_data-posnr."把已确认的销售订单数量还给库存
READ TABLE p_yvbbe INTO wa_yvbbe WITH KEY vbeln = gs_data-vbeln
posnr = gs_data-posnr.
IF sy-subrc IS INITIAL.
ENDIF.
CLEAR: l_atpdt.
l_atpdt-atpap = 'SO'.
l_atpdt-atptk = 'VB'.
l_atpdt-oldav = 'X'.
l_atpdt-newav = 'X'.
l_atpdt-delst = 'C'.
CALL FUNCTION 'DELTA_MANAGEMENT'
EXPORTING
p_atpdt= l_atpdt
TABLES
p_vbbeox = p_yvbbe
p_vbbenx = p_yvbbe
EXCEPTIONS
OTHERS = 0.
CLEAR:ls_atpca.
ls_atpca-anwdg = '5'. "SO
ls_atpca-anwdg2 = '5'. "SO
ls_atpca-azerg = 'Z'.
ls_atpca-rdmod = 'A'. "总计记录
ls_atpca-msginit = 'D'. "未执行初始化
CLEAR:ls_atpcs,lt_atpcs.
"LS_ATPCS-MATNR = '0000000304**17012'. "物料
ls_atpcs-matnr = gs_data-matnr. "物料
"LS_ATPCS-WERKS = '100B'."工厂
ls_atpcs-werks = gs_data-werks."工厂
"LS_ATPCS-BERID = '100B'."MRP范围
ls_atpcs-berid = gs_data-werks."MRP范围
ls_atpcs-prreg = 'A'. "可用性检查规则 A - SOLS_ATPCS-CHMOD = '011'."TABLE T459-BDART + PLART
ls_atpcs-chmod = '011'.
ls_atpcs-delkz = 'VC'. "销售订单
"LS_ATPCS-DELNR = '1000003042'. "销售订单
ls_atpcs-delnr = gs_data-vbeln. "销售订单
"LS_ATPCS-DELPS = '000010'. "销售订单行项目
ls_atpcs-delps = gs_data-posnr. "销售订单行项目
"LS_ATPCS-DELET = '0001'. "销售订单计划行项目
ls_atpcs-delet = wa_yvbbe-etenr. "销售订单计划行项目
ls_atpcs-bdart = '01'."T459A-BEDAR+0(2)
ls_atpcs-plart = '1'. "T459A-BEDAR+2(1)
ls_atpcs-vbtyp = 'C'. "SO
"""LS_ATPCS-TZONE = 'UTC+8'. "时区
"LS_ATPCS-BDTER = '0510'. "需求日
ls_atpcs-bdter = wa_yvbbe-mbdat. "需求日
ls_atpcs-bdmng = gs_data-kwmen. "需求数量
ls_atpcs-xline = '1'. "在ATPCS内表中的索引LS_ATPCS-XLINE = '0'.
* LS_ATPCS-AUFWG = '00'.
* LS_ATPCS-AUFST = '00'.
* LS_ATPCS-ALPRF = '00'.
ls_atpcs-umren = '1'.
ls_atpcs-umrez = '1'.
ls_atpcs-idxatp = '1'.
* LS_ATPCS-IDXPLN = '0'.
* LS_ATPCS-IDXALL = '0'.
* LS_ATPCS-MNTGA = '0'.
ls_atpcs-resmd = 'X'.
ls_atpcs-chkflg = 'X'.
ls_atpcs-enqflg = 'X'.
"LS_ATPCS-FORCE_DIA = 'X'.
ls_atpcs-sumbd = 'A'.
"""LS_ATPCS-MEINS = 'ST'. "物料基本单位
"""LS_ATPCS-WETZON = 'CHILE'. "时区
ls_atpcs-lfrel = 'X'.
ls_atpcs-kzazu = 'X'.
"""LS_ATPCS-GEWEI = 'KG'.
APPEND ls_atpcs TO lt_atpcs.
CALL FUNCTION 'AVAILABILITY_CHECK_S4'
TABLES
p_atpcsx = lt_atpcs
p_mdvex= p_mdvex "ATP的结果信息存在该表中* CHANGING
CHANGING
p_atpca= ls_atpca
EXCEPTIONS
error = 1
OTHERS = 2.
IF sy-subrc <> 0.
ENDIF.
CLEAR:wa_mdvex, it_mdvu.
READ TABLE p_mdvex INTO wa_mdvex INDEX 1.
IF sy-subrc IS INITIAL.
wa_mdvu-vbeln = gs_data-vbeln.
wa_mdvu-posnr = gs_data-posnr.
wa_mdvu-mbdat = wa_mdvex-dat01.
wa_mdvu-vmeng = wa_mdvex-mng02.
APPEND wa_mdvu TO it_mdvu.
ENDIF.
CLEAR: it_return.
CALL FUNCTION 'SD_BACKORDER_UPDATE'
* EXPORTING
* COMMIT_EXTERNAL = 'X'
* SD_READ_AND_SAVE = 'X'
* FIXMG_SET = ''
* NO_LOCK= ''
* P_CALL_ACTIVITY = 'V03R'
TABLES
kortab = it_mdvu
et_return = it_return.
CLEAR: wa_return.
READ TABLE it_return INTO wa_return WITH KEY type = 'E'.
IF sy-subrc IS INITIAL.
"失败
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
ELSE.
"成功
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'.
ENDIF.
ENDLOOP.