SAP PP销售预测转独立需求
程序员文章站
2022-03-09 21:19:09
销售预测转独立需求 调用BAPI_REQUIREMENTS_CREATE生成MD61代码示例前台界面代码示例FUNCTION zsdfm003f001.*"----------------------------------------------------------------------*"*"本地接口:*" TABLES*" PT_DLXQ TYPE ZTYDS_DLXQ_IN*" PT_RETURN TYPE ZTYDS_DLXQ_OUT OPTIONAL...
代码示例
FUNCTION zsdfm003f001.
*"----------------------------------------------------------------------
*"*"本地接口:
*" TABLES
*" PT_DLXQ TYPE ZTYDS_DLXQ_IN
*" PT_RETURN TYPE ZTYDS_DLXQ_OUT OPTIONAL
*"----------------------------------------------------------------------
* bapi data
DATA: matemp LIKE bapisitemr-material.
DATA: req_item LIKE bapisitemr.
DATA: req_data LIKE bapisshdin OCCURS 0 WITH HEADER LINE.
DATA: return LIKE bapireturn1 OCCURS 0 WITH HEADER LINE.
DATA: matertemp LIKE bapisitemr-material.
DATA:re_item LIKE bapisitemr,
re_schedule_in LIKE TABLE OF bapisshdin WITH HEADER LINE,
re_change LIKE bapisitemr.
DATA: gt_dlxq TYPE TABLE OF zsds_dlxq_in WITH HEADER LINE,
piv_mode TYPE mode VALUE 'C'.
TYPES: BEGIN OF typ_cha,
material TYPE matnr18,
plant TYPE werks_d,
version TYPE versb,
pbdnr TYPE pbdnr,
END OF typ_cha.
DATA: gs_cha TYPE typ_cha.
gt_dlxq[] = pt_dlxq[].
"物料编码
READ TABLE gt_dlxq INDEX 1.
IF sy-subrc = 0.
CLEAR:matertemp.
CALL FUNCTION 'CONVERSION_EXIT_MATN5_INPUT'
EXPORTING
input = gt_dlxq-material
IMPORTING
output = matertemp
EXCEPTIONS
length_error = 1
OTHERS = 2.
SELECT SINGLE *
INTO @DATA(lw_pbim)
FROM pbim
WHERE matnr = @matertemp
AND werks = @gt_dlxq-plant
AND versb = @gt_dlxq-version
AND vervs = 'X'.
IF sy-subrc = 0."若预测已存在,先删除再创建
CALL FUNCTION 'BAPI_REQUIREMENTS_CHANGE'
EXPORTING
material = matertemp
plant = lw_pbim-werks
requirementstype = lw_pbim-bedae
version = lw_pbim-versb
reqmtsplannumber = lw_pbim-pbdnr
vers_activ = ''
TABLES
return = return.
READ TABLE return INTO DATA(w_return) WITH KEY type = 'E'.
IF sy-subrc = 0."E类型错误
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
CLEAR pt_return.
pt_return-material = matertemp.
pt_return-plant = lw_pbim-werks.
* pt_return-version = lw_pbim-versb.
CALL FUNCTION 'MESSAGE_TEXT_BUILD'
EXPORTING
msgid = w_return-id
msgnr = w_return-number
msgv1 = w_return-message_v1
msgv2 = w_return-message_v2
msgv3 = w_return-message_v3
msgv4 = w_return-message_v4
IMPORTING
message_text_output = pt_return-message.
pt_return-message = w_return-type.
APPEND pt_return .
RETURN.
ELSE.
READ TABLE return INTO w_return WITH KEY type = 'A'.
IF sy-subrc = 0."A类型错误
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
pt_return-material = matertemp.
pt_return-plant = lw_pbim-werks.
* pt_return-version = lw_pbim-versb.
CALL FUNCTION 'MESSAGE_TEXT_BUILD'
EXPORTING
msgid = w_return-id
msgnr = w_return-number
msgv1 = w_return-message_v1
msgv2 = w_return-message_v2
msgv3 = w_return-message_v3
msgv4 = w_return-message_v4
IMPORTING
message_text_output = pt_return-message.
pt_return-message = w_return-type.
APPEND pt_return .
RETURN.
ELSE.
WAIT UP TO 1 SECONDS.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'.
WAIT UP TO 1 SECONDS.
ENDIF.
ENDIF.
piv_mode = 'U'.
ELSE.
piv_mode = 'C'.
ENDIF.
ENDIF.
*---bapi调用前内表赋值
LOOP AT gt_dlxq.
IF piv_mode = 'C'.
req_item-material = matertemp.
req_item-plant = gt_dlxq-plant.
req_item-requ_type = ''."gt_dlxq-requ_type.
req_item-version = gt_dlxq-version.
req_item-vers_activ = gt_dlxq-vers_activ.
req_item-req_number = gt_dlxq-pbdnr.
"期间标识
IF gt_dlxq-date_type = 'D' OR gt_dlxq-date_type = '1'.
req_data-date_type = '1'.
ENDIF.
req_data-req_date = gt_dlxq-req_date."需求日期
req_data-req_qty = gt_dlxq-req_qty."计划数量
APPEND req_data.
ELSEIF piv_mode = 'U'.
gs_cha-material = gt_dlxq-material.
gs_cha-plant = gt_dlxq-plant.
gs_cha-version = gt_dlxq-version.
gs_cha-pbdnr = gt_dlxq-pbdnr.
"期间标识
IF gt_dlxq-date_type = 'D' OR gt_dlxq-date_type = '1'.
re_schedule_in-date_type = '1'.
ENDIF.
re_schedule_in-req_date = gt_dlxq-req_date.
re_schedule_in-req_qty = gt_dlxq-req_qty.
* re_schedule_in-prod_ves = gt_dlxq-version.
APPEND re_schedule_in.
CLEAR re_schedule_in.
ENDIF.
ENDLOOP.
*---调用bapi
IF piv_mode = 'C'.
* 创建独立需求
CLEAR:matemp.
CALL FUNCTION 'BAPI_REQUIREMENTS_CREATE'
EXPORTING
requirements_item = req_item
* REQUIREMENT_PARAM =
IMPORTING
material = matemp
* PLANT =
* REQUIREMENTSTYPE =
* VERSION =
* REQMTSPLANNUMBER =
TABLES
requirements_schedule_in = req_data
* REQUIREMENTS_CHAR_IN =
return = return.
IF NOT matemp IS INITIAL.
pt_return-pbdnr = matemp.
pt_return-type = 'S'.
pt_return-message = '计划独立需求创建成功.'.
APPEND pt_return.
COMMIT WORK.
ELSE.
pt_return-index = gt_dlxq-index.
pt_return-type = 'E'.
pt_return-message = return-message.
APPEND pt_return.
ROLLBACK WORK.
ENDIF.
CLEAR matemp.
REFRESH req_data.
CLEAR matertemp.
CLEAR req_item.
ELSEIF piv_mode = 'U'.
* 更改独立需求
CLEAR re_change.
CALL FUNCTION 'BAPI_REQUIREMENTS_CHANGE'
EXPORTING
material = gs_cha-material
plant = gs_cha-plant
requirementstype = lw_pbim-bedae
version = gs_cha-version
reqmtsplannumber = gs_cha-pbdnr
vers_activ = 'X'
* REQUIREMENT_PARAM =
* MRP_AREA =
* DO_COMMIT = 'X'
* UPDATE_MODE = 'X'
delete_old = ''
* NO_WITHDR = ' '
* MATERIAL_EVG =
IMPORTING
requirement_item_out = re_change
TABLES
requirements_schedule_in = re_schedule_in
* REQUIREMENTS_CHAR_IN =
return = return.
IF re_change IS NOT INITIAL.
pt_return-material = gs_cha-material.
pt_return-plant = gs_cha-plant.
pt_return-pbdnr = gs_cha-pbdnr.
pt_return-type = 'S'.
pt_return-message = '计划独立需求修改成功.'.
APPEND pt_return .
CLEAR pt_return.
COMMIT WORK.
ELSE.
READ TABLE return WITH KEY type = 'E'.
pt_return-material = gs_cha-material.
pt_return-plant = gs_cha-plant.
pt_return-type = 'E'.
pt_return-message = return-message.
APPEND pt_return .
CLEAR pt_return.
ROLLBACK WORK.
ENDIF.
CLEAR:return,return[],"lv_pbdnr,
re_item,re_schedule_in[].
ENDIF.
ENDFUNCTION.
前台界面
TCODE:MD61
本文地址:https://blog.csdn.net/qq_38913810/article/details/109003650
上一篇: docker中安装seata
下一篇: Java实现自动取消订单