PP生产订单创建、下达、报工、收货、投料
转自http://blog.sina.com.cn/s/blog_69fb8eb60102vpjd.html
SAP 物料订单创建、下达、报工、收货与投料(ABAP代码)
(2015-06-03 22:48:01)
分类: ABAP |
对主体订单下的某一类物料通过MRP控制者的判断,可以对此类物料进行自动创建生产订单,自动下达,报工、收货,最后对主体订单投料。
1、新增加一个MRP控制者:泵送钢管类物料的MRP控制者必须设置为168.
2、根据输入条件读取主体订单(剔除CLSD、TECO、DLT)的OBOM清单,挑取MRP控制者为钢管(168)胶管(170)(泵送钢管订单、泵送胶管订单)下达钢管、胶管的生产订单(订单类型为PP51)。
3、程序在下达钢管、胶管的生产订单时候,要判断物料的MRP类型是否是ND,若是ND的话,程序报错,则提示需要将该物料改为PD。计划员手动修正MRP参数。
4、下达生产订单时,按物料编码将数量汇总下达钢管、胶管订单,基本完成日期取当天。
5、订单下达后(REL状态)模拟CO15报完工。
6、订单报完工后模拟MB31收货(移动类型为101,库存地点取MRP2视图生产仓储地)。
7、入库后模拟MB1A(移动类型为261,库存地点取MRP2视图的生产仓储地)对预留投料到对应的主体生产订单。
8、可选择部分MRP控制者未168的物料下生产订单
9、在下了生产订单后,如果OBOM中增加了物料的数量,则对差异数量下单
REPORT ZR_MM_GLDDCL.
TABLES: AFKO,RESB,MARC,MAKT,ZGLDDCL.
DATA: BEGIN OF GT_RESB OCCURS 0,
AUFNR LIKE RESB-AUFNR,
WERKS LIKE RESB-WERKS,
RSNUM LIKE RESB-RSNUM,
RSPOS LIKE RESB-RSPOS,
MATNR LIKE RESB-MATNR,
MEINS LIKE RESB-MEINS,
BDMNG LIKE RESB-BDMNG,
ENMNG LIKE RESB-ENMNG,
END OF GT_RESB.
DATA: BEGIN OF ITAB_SHOW OCCURS 0,
CHKID(1),
WERKS LIKE RESB-WERKS,
MATNR LIKE RESB-MATNR,
MAKTX LIKE MAKT-MAKTX, "物料描述
MEINS LIKE RESB-MEINS, "基本单位
XLOEK LIKE RESB-XLOEK, "删除标识
BDMNG LIKE RESB-BDMNG, "需求数量
ENMNG LIKE RESB-ENMNG, "提取数量
RGEKZ LIKE RESB-RGEKZ, "反冲
DISPO LIKE MARC-DISPO, "MRP控制者
DISMM LIKE MARC-DISMM, "MRP类型
LGPRO LIKE MARC-LGPRO, "生产仓储地
SCDDH LIKE RESB-AUFNR, "生成的生产订单号
YCXX1(100), "PD,ND异常判断
YCXX2(100), "订单创建
YCXX3(100), "下达
YCXX4(100), "报工
YCXX5(100), "收货
END OF ITAB_SHOW.
DATA: BEGIN OF GT_DDTL OCCURS 0,
AUFNR LIKE RESB-AUFNR,
WERKS LIKE RESB-WERKS,
RSNUM LIKE RESB-RSNUM,
RSPOS LIKE RESB-RSPOS,
MATNR LIKE RESB-MATNR,
MEINS LIKE RESB-MEINS,
BDMNG LIKE RESB-BDMNG,
ENMNG LIKE RESB-ENMNG,
LGPRO LIKE MARC-LGPRO,
YCXX1(100),
END OF GT_DDTL.
DATA: BEGIN OF GT_AFKO OCCURS 0,
RSNUM LIKE RESB-RSNUM,
AUFNR LIKE AFKO-AUFNR,
END OF GT_AFKO.
DATA: BEGIN OF GT_MARC OCCURS 0,
MATNR LIKE MARC-MATNR,
DISPO LIKE MARC-DISPO,
DISMM LIKE MARC-DISMM,
LGPRO LIKE MARC-LGPRO,
WERKS LIKE MARC-WERKS,
END OF GT_MARC.
DATA: BEGIN OF GT_MAKT OCCURS 0,
MATNR LIKE MAKT-MATNR,
MAKTX LIKE MAKT-MAKTX,
END OF GT_MAKT.
DATA: BEGIN OF BDCDATA OCCURS 0.
INCLUDE STRUCTURE BDCDATA.
DATA: END OF BDCDATA.
DATA: BDCMESS LIKE BDCMSGCOLL OCCURS 0 WITH HEADER LINE.
DATA: BDC_MODE(1).
DATA: P_MODE LIKE CTU_PARAMS-DISMODE VALUE 'N'.
DATA: IN_ZGLDDCL LIKE ZGLDDCL OCCURS 0 WITH HEADER LINE.
DATA: GT_ZGLDDCL LIKE ZGLDDCL OCCURS 0 WITH HEADER LINE.
DATA: TL_ZGLDDCL LIKE ZGLDDCL OCCURS 0 WITH HEADER LINE.
DATA: FLAG_SUCCESS(1).
RANGES: R_RSNUM FOR RESB-RSNUM.
RANGES: R_MATNR FOR RESB-MATNR.
*&--------------------------------------------------------------------*
*& 屏幕显示
*&--------------------------------------------------------------------*
SELECTION-SCREEN: BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.
PARAMETERS: P_WERKS LIKE RESB-WERKS OBLIGATORY DEFAULT '1802',"工厂
P_DISPO LIKE MARC-DISPO DEFAULT '168'. "MRP控制者
SELECT-OPTIONS: S_AUFNR FOR AFKO-AUFNR."生产订单
SELECTION-SCREEN: END OF BLOCK B1.
*&--------------------------------------------------------------------*
*& 程序执行
*&--------------------------------------------------------------------*
START-OF-SELECTION.
PERFORM AUTHORITY_CHECK.
PERFORM INPUT_CHECK.
PERFORM GET_DATA.
PERFORM SHOW.
*&---------------------------------------------------------------------*
*& Form GET_DATA
*&---------------------------------------------------------------------*
FORM GET_DATA .
DATA:
LV_OBJNR TYPE AUFK-OBJNR,
LV_LINE TYPE BSVX-STTXT,
LV_LOEKZ TYPE AUFK-LOEKZ,
LV_FLAG TYPE CHAR1.
* 剔除订单状态为 CLSD、TECO、DLT、CRTD OBOM清单
CLEAR: GT_AFKO,GT_AFKO[].
SELECT RSNUM AUFNR INTO TABLE GT_AFKO
FROM AFKO
WHERE AUFNR IN S_AUFNR.
IF GT_AFKO[] IS INITIAL.
MESSAGE '该订单预留不存在!' TYPE 'S'.
STOP.
ENDIF.
LOOP AT GT_AFKO.
* 订单的对象号
SELECT SINGLE OBJNR INTO LV_OBJNR
FROM AUFK
WHERE AUFNR = GT_AFKO-AUFNR
AND LOEKZ = ''.
IF LV_OBJNR IS NOT INITIAL.
* 取得订单的订单状态
CALL FUNCTION 'STATUS_TEXT_EDIT'
EXPORTING
OBJNR = LV_OBJNR
SPRAS = SY-LANGU
IMPORTING
LINE = LV_LINE
EXCEPTIONS
OBJECT_NOT_FOUND = 1
OTHERS = 2.
IF LV_LINE CS 'TECO' OR LV_LINE CS 'CLSD' OR
LV_LINE CS 'DLT' OR LV_LINE CS 'CRTD'.
DELETE GT_AFKO.
ENDIF.
ENDIF.
ENDLOOP.
IF GT_AFKO[] IS INITIAL.
MESSAGE '该订单预留不存在!' TYPE 'S'.
STOP.
ELSE.
LOOP AT GT_AFKO.
R_RSNUM-SIGN = 'I'.
R_RSNUM-OPTION = 'EQ'.
R_RSNUM-LOW = GT_AFKO-RSNUM.
APPEND R_RSNUM.
CLEAR R_RSNUM.
ENDLOOP.
ENDIF.
SELECT AUFNR WERKS RSNUM RSPOS MATNR MEINS BDMNG ENMNG INTO
CORRESPONDING FIELDS OF TABLE GT_RESB
FROM RESB
WHERE RSNUM IN R_RSNUM
AND XLOEK <> 'X' "删除的
AND DUMPS <> 'X' "虚拟件
AND DBSKZ <> 'E' "父子订单物料,排除
AND BDMNG <> '0'.
LOOP AT GT_RESB.
MOVE-CORRESPONDING GT_RESB TO ITAB_SHOW.
COLLECT ITAB_SHOW.
ENDLOOP.
* 判断物料是否为钢管或胶管
IF ITAB_SHOW[] IS NOT INITIAL.
SELECT MATNR DISPO DISMM LGPRO WERKS INTO TABLE GT_MARC
FROM MARC
FOR ALL ENTRIES IN ITAB_SHOW
WHERE MATNR = ITAB_SHOW-MATNR
AND WERKS = ITAB_SHOW-WERKS.
ENDIF.
SORT GT_MARC BY MATNR.
LOOP AT ITAB_SHOW.
READ TABLE GT_MARC WITH KEY MATNR = ITAB_SHOW-MATNR BINARY SEARCH.
IF SY-SUBRC = 0.
ITAB_SHOW-DISPO = GT_MARC-DISPO.
ITAB_SHOW-DISMM = GT_MARC-DISMM.
ITAB_SHOW-LGPRO = GT_MARC-LGPRO.
IF GT_MARC-DISMM = 'ND'.
ITAB_SHOW-YCXX1 = 'MRP类型为ND,请手动修正MRP参数。'.
ENDIF.
ENDIF.
MODIFY ITAB_SHOW.
ENDLOOP.
* 删除MRP控制者不为168的。
DELETE ITAB_SHOW WHERE DISPO <> P_DISPO.
* 获取物料描述
IF ITAB_SHOW[] IS NOT INITIAL.
SELECT MATNR MAKTX INTO TABLE GT_MAKT
FROM MAKT
FOR ALL ENTRIES IN ITAB_SHOW
WHERE MATNR = ITAB_SHOW-MATNR
AND SPRAS = SY-LANGU.
ENDIF.
SORT GT_MAKT BY MATNR.
LOOP AT ITAB_SHOW.
READ TABLE GT_MAKT WITH KEY MATNR = ITAB_SHOW-MATNR BINARY SEARCH.
IF SY-SUBRC = 0.
ITAB_SHOW-MAKTX = GT_MAKT-MAKTX.
ENDIF.
MODIFY ITAB_SHOW.
ENDLOOP.
ENDFORM. " GET_DATA
*&---------------------------------------------------------------------*
*& Form SHOW
*&---------------------------------------------------------------------*
FORM SHOW .
TYPE-POOLS SLIS.
DATA: WS_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV WITH HEADER LINE,
WS_FIELDGROUPS_TAB TYPE SLIS_T_SP_GROUP_ALV,
WS_LAYOUT TYPE SLIS_LAYOUT_ALV,
WS_SORTFIELDS_TAB TYPE SLIS_T_SORTINFO_ALV WITH HEADER LINE,
WS_EVENTS TYPE SLIS_T_EVENT.
DATA: V_REPID LIKE SY-REPID.
DATA: NN TYPE I VALUE 0.
DATA: TITLE TYPE LVC_TITLE.
DEFINE HOUT.
NN = NN + 1.
WS_FIELDCAT-TABNAME = 'ITAB_SHOW'.
WS_FIELDCAT-FIELDNAME = '&1'.
WS_FIELDCAT-SELTEXT_M = &2.
WS_FIELDCAT-COL_POS = NN.
WS_FIELDCAT-OUTPUTLEN = &3.
WS_FIELDCAT-DATATYPE = '&4'.
* ws_fieldcat-do_sum = '&5'.
WS_FIELDCAT-LZERO = 'X'.
APPEND WS_FIELDCAT.
CLEAR WS_FIELDCAT.
END-OF-DEFINITION.
HOUT MATNR '物料' 15 CHAR.
HOUT MAKTX '物料描述' 30 CHAR.
HOUT MEINS '单位' 6 CHAR.
HOUT BDMNG '需求数量' 13 QUAN.
HOUT ENMNG '提货数量' 13 QUAN.
HOUT SCDDH '生产订单' 12 CHAR.
HOUT DISMM 'MRP类型' 2 CHAR.
HOUT LGPRO '生产仓储地' 4 CHAR.
HOUT YCXX1 '异常信息1' 100 CHAR.
HOUT YCXX2 '生产订单创建' 100 CHAR.
HOUT YCXX3 '生产订单下达' 100 CHAR.
HOUT YCXX4 '生产订单报工' 100 CHAR.
HOUT YCXX5 '生产订单收货' 100 CHAR.
* title = '泵送清单打印报表'.
WS_LAYOUT-ZEBRA = 'X'.
WS_LAYOUT-GET_SELINFOS = ''.
WS_LAYOUT-COLWIDTH_OPTIMIZE = 'X'.
WS_LAYOUT-DETAIL_POPUP = 'X'.
WS_LAYOUT-NO_KEYFIX = 'X'.
WS_LAYOUT-BOX_FIELDNAME = 'CHKID'.
V_REPID = SY-REPID.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = V_REPID
I_CALLBACK_PF_STATUS_SET = 'MENU_SET'
I_CALLBACK_USER_COMMAND = 'EXECUTE_COMMAND'
IS_LAYOUT = WS_LAYOUT
IT_FIELDCAT = WS_FIELDCAT[]
IT_SPECIAL_GROUPS = WS_FIELDGROUPS_TAB[]
IT_SORT = WS_SORTFIELDS_TAB[]
IT_EVENTS = WS_EVENTS[]
I_GRID_TITLE = TITLE
TABLES
T_OUTTAB = ITAB_SHOW
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2.
ENDFORM. " SHOW
*&---------------------------------------------------------------------*
*& Form AUTHORITY_CHECK
*&---------------------------------------------------------------------*
FORM AUTHORITY_CHECK .
AUTHORITY-CHECK OBJECT 'M_MATE_WRK'
ID 'ACTVT' FIELD '03'
ID 'WERKS' FIELD P_WERKS.
IF SY-SUBRC <> 0.
MESSAGE '没有工厂的权限!' TYPE 'I'.
STOP.
ENDIF.
ENDFORM. " AUTHORITY_CHECK
*---------------------------------------------------------------------*
* FORM MENU_SET *
*---------------------------------------------------------------------*
FORM MENU_SET USING RT_EXTAB TYPE SLIS_T_EXTAB.
SET PF-STATUS 'S001' .
ENDFORM. "menu_set
*---------------------------------------------------------------------*
* FORM EXECUTE_COMMAND *
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
* --> R_UCOMM *
* --> RS_SELFIELD *
*---------------------------------------------------------------------*
FORM EXECUTE_COMMAND USING R_UCOMM LIKE SY-UCOMM
RS_SELFIELD TYPE SLIS_SELFIELD.
*从ALV读取更新数据
READ TABLE ITAB_SHOW INDEX RS_SELFIELD-TABINDEX.
DATA: LR_GRID TYPE REF TO CL_GUI_ALV_GRID.
DATA: ERR(1).
CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
IMPORTING E_GRID = LR_GRID.
CALL METHOD LR_GRID->CHECK_CHANGED_DATA.
RS_SELFIELD-REFRESH = 'X'. "自动刷新
CASE R_UCOMM.
WHEN 'DDPCL'.
CLEAR : R_MATNR,R_MATNR[].
LOOP AT ITAB_SHOW WHERE CHKID = 'X'.
* 选中的物料 ADD BY LIURB 20110720
R_MATNR-SIGN = 'I'.
R_MATNR-OPTION = 'EQ'.
R_MATNR-LOW = ITAB_SHOW-MATNR.
APPEND R_MATNR.
CLEAR R_MATNR.
* 生成生产订单-CO01/CO02
PERFORM CREAT_PO.
SELECT * INTO CORRESPONDING FIELDS OF TABLE IN_ZGLDDCL
FROM ZGLDDCL
WHERE MATNR = ITAB_SHOW-MATNR
AND WERKS = ITAB_SHOW-WERKS
AND SCDDH = ITAB_SHOW-SCDDH.
READ TABLE IN_ZGLDDCL INDEX 1.
* 订单下达
IF SY-SUBRC = 0.
IF IN_ZGLDDCL-FLAG2 = 'X'.
ITAB_SHOW-YCXX3 = '订单已下达,不能重复下达'.
ELSE.
WAIT UP TO 1 SECONDS.
PERFORM CALL_BDC_DDXD.
ENDIF.
*订单工序报工-CO15
IF IN_ZGLDDCL-FLAG3 = 'X'.
ITAB_SHOW-YCXX4 = '工序已报工,不能重复报工'.
ELSE.
WAIT UP TO 1 SECONDS.
PERFORM GET_GXBG.
ENDIF.
* 订单收货 - MB31
IF IN_ZGLDDCL-FLAG4 = 'X'.
ITAB_SHOW-YCXX5 = '订单已收货,不能重复收货'.
ELSE.
WAIT UP TO 1 SECONDS.
PERFORM GET_DDSH.
ENDIF.
ENDIF.
MODIFY ITAB_SHOW.
ENDLOOP.
* 订单投料 - MB1A
WAIT UP TO 1 SECONDS.
PERFORM GET_DDTL.
* 投料信息显示
WHEN 'XSDDTLJG'.
PERFORM SHOW_DDTLXX.
WHEN 'EXIT'.
LEAVE PROGRAM.
WHEN 'BACK1' OR 'CANCEL'.
SUBMIT ZR_MM_GLDDCL VIA SELECTION-SCREEN.
ENDCASE.
ENDFORM. "execute_command
*&---------------------------------------------------------------------*
*& Form CREAT_PO
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM CREAT_PO .
DATA: I_ORDDATA LIKE BAPI_PP_ORDER_CREATE OCCURS 0 WITH HEADER LINE,
I_RETURN LIKE BAPIRET2,
I_ORDER_NUMBER LIKE BAPI_ORDER_KEY-ORDER_NUMBER,
I_ORDER_TYPE LIKE BAPI_ORDER_COPY-ORDER_TYPE.
DATA: TEMP_AUFNR LIKE AFPO-AUFNR.
DATA: FLAG(1),
FLAG_RSNUM LIKE RESB-RSNUM,
FLAG_MATNR LIKE RESB-MATNR,
FLAG_AUFNR LIKE AFKO-AUFNR,
FLAG_BDMNG LIKE RESB-BDMNG,
CL_BDMNG LIKE RESB-BDMNG.
* 判断是否已经对该订单的物料生成了生产订单
CLEAR : FLAG,FLAG_RSNUM,FLAG_MATNR,FLAG_AUFNR,FLAG_BDMNG.
CLEAR : GT_ZGLDDCL,GT_ZGLDDCL[].
SELECT * INTO CORRESPONDING FIELDS OF TABLE GT_ZGLDDCL
FROM ZGLDDCL
WHERE MATNR = ITAB_SHOW-MATNR
AND WERKS = ITAB_SHOW-WERKS.
LOOP AT GT_ZGLDDCL WHERE MATNR = ITAB_SHOW-MATNR
AND WERKS = ITAB_SHOW-WERKS.
IF GT_ZGLDDCL-RSNUM IN R_RSNUM.
FLAG_BDMNG = FLAG_BDMNG + GT_ZGLDDCL-BDMNG.
IF GT_ZGLDDCL-SCDDH IS NOT INITIAL.
FLAG = 'X'.
FLAG_AUFNR = GT_ZGLDDCL-SCDDH.
ELSE.
FLAG_RSNUM = GT_ZGLDDCL-RSNUM.
ENDIF.
ENDIF.
ENDLOOP.
* 判断需求数量与已下单的数量是否相同,
* 如果小于大于下单数量,则允许下单,数量为差异量
* ADD BY LIURB 20110720
CL_BDMNG = ITAB_SHOW-BDMNG.
IF FLAG_BDMNG <> ITAB_SHOW-BDMNG.
CL_BDMNG = ITAB_SHOW-BDMNG - FLAG_BDMNG.
FLAG = ''.
ITAB_SHOW-BDMNG = CL_BDMNG.
ENDIF.
CLEAR : I_ORDDATA ,I_ORDDATA[].
I_ORDDATA-MATERIAL = ITAB_SHOW-MATNR.
I_ORDDATA-PLANT = ITAB_SHOW-WERKS.
I_ORDDATA-PLANNING_PLANT = ITAB_SHOW-WERKS.
I_ORDDATA-ORDER_TYPE = 'PP51'.
I_ORDDATA-QUANTITY = CL_BDMNG.
I_ORDDATA-BASIC_START_DATE = SY-DATUM.
I_ORDDATA-BASIC_END_DATE = SY-DATUM.
I_ORDDATA-QUANTITY_UOM = ITAB_SHOW-MEINS.
APPEND I_ORDDATA.
IF FLAG = 'X'.
ITAB_SHOW-YCXX2 = '订单已创建,不能重复创建'.
ITAB_SHOW-SCDDH = FLAG_AUFNR.
ELSE.
CLEAR: I_RETURN.
CALL FUNCTION 'BAPI_PRODORD_CREATE'
EXPORTING
ORDERDATA = I_ORDDATA
IMPORTING
RETURN = I_RETURN
ORDER_NUMBER = I_ORDER_NUMBER
ORDER_TYPE = I_ORDER_TYPE.
IF I_RETURN-TYPE <> 'E'.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
WAIT = 'X'.
ITAB_SHOW-SCDDH = I_ORDER_NUMBER.
ITAB_SHOW-YCXX2 = '订单创建成功'.
*** 更新自定义表
FLAG_MATNR = ITAB_SHOW-MATNR.
PERFORM UPDATE_ZGLDDCL USING
FLAG_RSNUM I_ORDER_NUMBER FLAG_MATNR.
ELSE.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
FLAG_SUCCESS = ''.
WAIT UP TO 1 SECONDS.
ITAB_SHOW-YCXX2 = I_RETURN-MESSAGE.
ENDIF.
ENDIF.
ENDFORM. " CREAT_PO
*&---------------------------------------------------------------------*
*& Form INPUT_CHECK
*&---------------------------------------------------------------------*
FORM INPUT_CHECK .
IF S_AUFNR IS INITIAL.
MESSAGE '该订单预留不存在!' TYPE 'S'.
STOP.
ENDIF.
IF P_DISPO IS INITIAL.
MESSAGE 'MRP控制者不能为空!' TYPE 'S'.
STOP.
ENDIF.
*钢管的MRP控制者为168,胶管的MRP控制者为170
*目前只处理钢管2011.7.14
IF P_DISPO <> '168'.
MESSAGE 'MRP控制者必须为168!' TYPE 'S'.
STOP.
ENDIF.
ENDFORM. " INPUT_CHECK
*&---------------------------------------------------------------------*
*& Form CALL_BDC_DDXD
*&---------------------------------------------------------------------*
* 订单下达
*----------------------------------------------------------------------*
FORM CALL_BDC_DDXD.
* START BDC
DO 2 TIMES.
CLEAR: BDCDATA,BDCDATA[],BDCMESS,BDCMESS[].
PERFORM BDC_DYNPRO USING 'SAPLCOKO1' '0110'.
PERFORM BDC_FIELD USING 'BDC_OKCODE' '/00'.
PERFORM BDC_FIELD USING 'CAUFVD-AUFNR'
ITAB_SHOW-SCDDH.
PERFORM BDC_FIELD USING 'R62CLORD-FLG_OVIEW'
'X'.
PERFORM BDC_DYNPRO USING 'SAPLCOKO1' '0115'.
PERFORM BDC_FIELD USING 'BDC_OKCODE' '=FREI'.
PERFORM BDC_DYNPRO USING 'SAPLCOKO1' '0115'.
PERFORM BDC_FIELD USING 'BDC_OKCODE'
'=BU'.
BDC_MODE = P_MODE.
WAIT UP TO 1 SECONDS.
CALL TRANSACTION 'CO02' USING BDCDATA
UPDATE 'S' MODE BDC_MODE
MESSAGES INTO BDCMESS.
IF SY-SUBRC = 0.
COMMIT WORK.
ITAB_SHOW-YCXX3 = '下达成功'.
UPDATE ZGLDDCL SET FLAG2 = 'X'
WHERE SCDDH = ITAB_SHOW-SCDDH
AND MATNR = ITAB_SHOW-MATNR.
EXIT.
ELSE.
ROLLBACK WORK.
ITAB_SHOW-YCXX3 = '下达失败,请手动下达'.
ENDIF.
ENDDO.
* END BDC
ENDFORM. " CALL_BDC_DDXD
*&---------------------------------------------------------------------*
*& Form bdc_dynpro
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM BDC_DYNPRO USING PROGRAM DYNPRO.
CLEAR BDCDATA.
BDCDATA-PROGRAM = PROGRAM.
BDCDATA-DYNPRO = DYNPRO.
BDCDATA-DYNBEGIN = 'X'.
APPEND BDCDATA.
ENDFORM. "bdc_dynpro
*&---------------------------------------------------------------------*
*& Form bdc_dynpro
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM BDC_FIELD USING FNAM FVAL.
CLEAR BDCDATA.
BDCDATA-FNAM = FNAM.
BDCDATA-FVAL = FVAL.
APPEND BDCDATA.
ENDFORM. "bdc_field
*&---------------------------------------------------------------------*
*& Form GET_GXBG
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM GET_GXBG.
* START BDC
CLEAR: BDCDATA,BDCDATA[],BDCMESS,BDCMESS[].
PERFORM BDC_DYNPRO USING 'SAPLCORU' '0400'.
PERFORM BDC_FIELD USING 'BDC_OKCODE' '/00'.
PERFORM BDC_FIELD USING 'CORUF-AUFNR' ITAB_SHOW-SCDDH.
PERFORM BDC_DYNPRO USING 'SAPLCORU' '0410'.
PERFORM BDC_FIELD USING 'BDC_OKCODE' '=BU'.
PERFORM BDC_FIELD USING 'CORUF-AUTER' 'X'.
PERFORM BDC_FIELD USING 'CORUF-AUSBU' ''.
BDC_MODE = P_MODE.
CALL TRANSACTION 'CO15' USING BDCDATA
UPDATE 'S' MODE BDC_MODE
MESSAGES INTO BDCMESS.
IF SY-SUBRC = 0.
COMMIT WORK.
UPDATE ZGLDDCL SET FLAG3 = 'X'
WHERE SCDDH = ITAB_SHOW-SCDDH
AND MATNR = ITAB_SHOW-MATNR.
ITAB_SHOW-YCXX4 = '报工成功'.
ELSE.
ROLLBACK WORK.
ITAB_SHOW-YCXX4 = '报工失败,请手动报工'.
ENDIF.
* END BDC
ENDFORM. " GET_GXBG
*&---------------------------------------------------------------------*
*& Form GET_DDSH
*&---------------------------------------------------------------------*
* 订单收货
*----------------------------------------------------------------------*
FORM GET_DDSH .
DATA:
LW_AUFNR TYPE AUFNR,
LW_MATNR TYPE MATNR,
LW_MESSAGE(100).
DATA:
I_GHEADER TYPE BAPI2017_GM_HEAD_01,
I_MDOCUMENT TYPE BAPI2017_GM_HEAD_RET-MAT_DOC,
I_MDOCYEAR TYPE BAPI2017_GM_HEAD_RET-DOC_YEAR,
I_GITEM TYPE TABLE OF BAPI2017_GM_ITEM_CREATE WITH HEADER LINE,
I_RETURN TYPE TABLE OF BAPIRET2 WITH HEADER LINE.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
INPUT = ITAB_SHOW-SCDDH
IMPORTING
OUTPUT = LW_AUFNR.
I_GHEADER-DOC_DATE = SY-DATUM.
I_GHEADER-PSTNG_DATE = SY-DATUM.
SELECT MATNR
INTO LW_MATNR
FROM AFPO
UP TO 1 ROWS
WHERE AUFNR = LW_AUFNR.
ENDSELECT.
I_GITEM-MOVE_TYPE = '101'.
I_GITEM-MVT_IND = 'F'. "有关生产单的货物移动
I_GITEM-PLANT = ITAB_SHOW-WERKS.
I_GITEM-STGE_LOC = ITAB_SHOW-LGPRO.
I_GITEM-MATERIAL = LW_MATNR.
I_GITEM-ENTRY_QNT = ITAB_SHOW-BDMNG.
I_GITEM-ORDERID = LW_AUFNR.
APPEND I_GITEM.
CLEAR : I_RETURN,I_RETURN[].
CALL FUNCTION 'BAPI_GOODSMVT_CREATE'
EXPORTING
GOODSMVT_HEADER = I_GHEADER
GOODSMVT_CODE = '02' "MB31
IMPORTING
MATERIALDOCUMENT = I_MDOCUMENT
MATDOCUMENTYEAR = I_MDOCYEAR
TABLES
GOODSMVT_ITEM = I_GITEM
RETURN = I_RETURN.
IF I_MDOCUMENT IS NOT INITIAL.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
WAIT = 'X'.
UPDATE ZGLDDCL SET FLAG4 = 'X'
WHERE SCDDH = ITAB_SHOW-SCDDH
AND MATNR = ITAB_SHOW-MATNR.
ITAB_SHOW-YCXX5 = '收货成功'.
ELSE.
ITAB_SHOW-YCXX5 = I_RETURN-MESSAGE.
ENDIF.
ENDFORM. " GET_DDSH
*&---------------------------------------------------------------------*
*& Form GET_DDTL
*&---------------------------------------------------------------------*
* 订单投料
*----------------------------------------------------------------------*
FORM GET_DDTL .
DATA:
LV_ERRFLG TYPE CHAR1,
LV_XCHPF TYPE MARA-XCHPF,
LV_BDMNG TYPE RESBD-BDMNG,
LT_MCHB TYPE MCHB OCCURS 0 WITH HEADER LINE,
I_GHEADER TYPE TABLE OF BAPI2017_GM_HEAD_01 WITH HEADER LINE ,
I_GHEADRET TYPE TABLE OF BAPI2017_GM_HEAD_RET WITH HEADER LINE ,
I_MDOCUMENT TYPE BAPI2017_GM_HEAD_RET-MAT_DOC,
I_MDOCYEAR TYPE BAPI2017_GM_HEAD_RET-DOC_YEAR,
I_GITEM TYPE TABLE OF BAPI2017_GM_ITEM_CREATE WITH HEADER LINE ,
I_GSNUMBER TYPE TABLE OF BAPI2017_GM_SERIALNUMBER WITH HEADER LINE,
I_RETURN TYPE TABLE OF BAPIRET2 WITH HEADER LINE,
LS_MSEG TYPE MSEG,
TLSL LIKE RESB-BDMNG.
CONCATENATE SY-UNAME ' ' SY-TCODE INTO I_GHEADER-HEADER_TXT.
I_GHEADER-DOC_DATE = SY-DATUM.
I_GHEADER-PSTNG_DATE = SY-DATUM.
APPEND I_GHEADER.
CLEAR : GT_DDTL,GT_DDTL[],TL_ZGLDDCL,TL_ZGLDDCL[].
* 比较ITAB_SHOW和GT_RESB,删除GT_RESB中不满足条件的物料
DELETE GT_RESB WHERE MATNR NOT IN R_MATNR.
IF GT_RESB[] IS NOT INITIAL.
SELECT * INTO CORRESPONDING FIELDS OF TABLE GT_DDTL
FROM RESB
FOR ALL ENTRIES IN GT_RESB
WHERE MATNR = GT_RESB-MATNR
AND RSNUM IN R_RSNUM
AND XLOEK <> 'X' "删除的
AND DUMPS <> 'X' "虚拟件
AND DBSKZ <> 'E' "父子订单物料,排除
AND BDMNG <> '0'.
ENDIF.
IF GT_DDTL[] IS NOT INITIAL.
SELECT * INTO CORRESPONDING FIELDS OF TABLE TL_ZGLDDCL
FROM ZGLDDCL
FOR ALL ENTRIES IN GT_DDTL
WHERE MATNR = GT_DDTL-MATNR
AND WERKS = GT_DDTL-WERKS
AND AUFNR = GT_DDTL-AUFNR.
ENDIF.
SORT ITAB_SHOW BY MATNR.
SORT TL_ZGLDDCL BY AUFNR MATNR WERKS.
LOOP AT GT_DDTL.
READ TABLE GT_MARC WITH KEY
MATNR = GT_DDTL-MATNR BINARY SEARCH.
IF SY-SUBRC = 0.
GT_DDTL-LGPRO = GT_MARC-LGPRO.
MODIFY GT_DDTL.
ENDIF.
READ TABLE TL_ZGLDDCL WITH KEY
AUFNR = GT_DDTL-AUFNR
MATNR = GT_DDTL-MATNR
FLAG1 = 'X'
FLAG2 = 'X'
FLAG3 = 'X'
FLAG4 = 'X'
BINARY SEARCH.
*如果该物料的所有操作没有成功,则不对该物料投料
IF SY-SUBRC <> 0.
GT_DDTL-YCXX1 = '订单物料异常,不能投料'.
MODIFY GT_DDTL.
CONTINUE.
ENDIF.
CLEAR: I_RETURN,I_RETURN[],I_GITEM,I_GITEM[],LV_ERRFLG,TLSL.
TLSL = GT_DDTL-BDMNG - GT_DDTL-ENMNG.
*如果已经投过料,则不投
IF TL_ZGLDDCL-FLAG5 = 'X' AND TLSL = 0.
GT_DDTL-YCXX1 = '订单已投料,不能重复投料'.
MODIFY GT_DDTL.
CONTINUE.
ENDIF.
I_GITEM-MATERIAL = GT_DDTL-MATNR.
I_GITEM-STGE_LOC = GT_DDTL-LGPRO.
I_GITEM-ENTRY_QNT = TLSL.
I_GITEM-ENTRY_UOM = GT_DDTL-MEINS.
I_GITEM-MOVE_TYPE = '261'.
I_GITEM-PLANT = GT_DDTL-WERKS.
I_GITEM-ORDERID = GT_DDTL-AUFNR.
I_GITEM-RESERV_NO = GT_DDTL-RSNUM.
I_GITEM-RES_ITEM = GT_DDTL-RSPOS.
APPEND I_GITEM.
* 向生产订单的预留发料
CALL FUNCTION 'BAPI_GOODSMVT_CREATE'
EXPORTING
GOODSMVT_HEADER = I_GHEADER
GOODSMVT_CODE = '03' "MB1A
IMPORTING
GOODSMVT_HEADRET = I_GHEADRET
MATERIALDOCUMENT = I_MDOCUMENT
MATDOCUMENTYEAR = I_MDOCYEAR
TABLES
GOODSMVT_ITEM = I_GITEM
GOODSMVT_SERIALNUMBER = I_GSNUMBER
RETURN = I_RETURN.
LOOP AT I_RETURN.
IF I_RETURN-TYPE = 'E' OR
I_RETURN-TYPE = 'A'.
LV_ERRFLG = 'X'.
ENDIF.
ENDLOOP.
IF LV_ERRFLG = 'X'.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
WAIT UP TO 1 SECONDS.
GT_DDTL-YCXX1 = I_RETURN-MESSAGE.
ELSE.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
WAIT = 'X'.
UPDATE ZGLDDCL SET FLAG5 = 'X'
ENMNG = TLSL
WHERE AUFNR = GT_DDTL-AUFNR
AND MATNR = GT_DDTL-MATNR
AND WERKS = GT_DDTL-WERKS.
GT_DDTL-YCXX1 = '订单投料成功'.
ENDIF.
MODIFY GT_DDTL.
ENDLOOP.
ENDFORM. " GET_DDTL
*&---------------------------------------------------------------------*
*& Form UPDATE_ZGLDDCL
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM UPDATE_ZGLDDCL USING P_FLAG_RSNUM
P_O_ORDER_NUMBER
P_FLAG_MATNR.
* 比较ITAB_SHOW和GT_RESB,删除GT_RESB中不满足条件的物料
DELETE GT_RESB WHERE MATNR NOT IN R_MATNR.
CLEAR : GT_ZGLDDCL,GT_ZGLDDCL[].
LOOP AT GT_RESB WHERE MATNR = P_FLAG_MATNR.
MOVE-CORRESPONDING GT_RESB TO GT_ZGLDDCL.
COLLECT GT_ZGLDDCL.
ENDLOOP.
* 删除重复项
SORT GT_ZGLDDCL BY AUFNR MATNR.
DELETE ADJACENT DUPLICATES FROM GT_ZGLDDCL.
LOOP AT GT_ZGLDDCL.
IF GT_ZGLDDCL-RSNUM = P_FLAG_RSNUM.
GT_ZGLDDCL-SCDDH = P_O_ORDER_NUMBER.
ELSE.
IF GT_ZGLDDCL-SCDDH IS INITIAL.
GT_ZGLDDCL-SCDDH = P_O_ORDER_NUMBER.
ENDIF.
ENDIF.
GT_ZGLDDCL-FLAG1 = 'X'."订单创建成功
MODIFY GT_ZGLDDCL.
ENDLOOP.
* 将数据插入自定义表中
IF GT_ZGLDDCL[] IS NOT INITIAL.
MODIFY ZGLDDCL FROM TABLE GT_ZGLDDCL.
ENDIF.
ENDFORM. " UPDATE_ZGLDDCL
*&---------------------------------------------------------------------*
*& Form SHOW_DDTLXX
*&---------------------------------------------------------------------*
FORM SHOW_DDTLXX .
TYPE-POOLS SLIS.
DATA: WS_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV WITH HEADER LINE,
WS_FIELDGROUPS_TAB TYPE SLIS_T_SP_GROUP_ALV,
WS_LAYOUT TYPE SLIS_LAYOUT_ALV,
WS_SORTFIELDS_TAB TYPE SLIS_T_SORTINFO_ALV WITH HEADER LINE,
WS_EVENTS TYPE SLIS_T_EVENT.
DATA: V_REPID LIKE SY-REPID.
DATA: NN TYPE I VALUE 0.
DATA: TITLE TYPE LVC_TITLE.
DEFINE HOUT.
NN = NN + 1.
WS_FIELDCAT-TABNAME = 'GT_DDTL'.
WS_FIELDCAT-FIELDNAME = '&1'.
WS_FIELDCAT-SELTEXT_M = &2.
WS_FIELDCAT-COL_POS = NN.
WS_FIELDCAT-OUTPUTLEN = &3.
WS_FIELDCAT-DATATYPE = '&4'.
* ws_fieldcat-do_sum = '&5'.
WS_FIELDCAT-LZERO = 'X'.
IF WS_FIELDCAT-FIELDNAME = 'AUFNR'.
WS_FIELDCAT-REF_FIELDNAME = 'AUFNR' .
WS_FIELDCAT-REF_TABNAME = 'AFPO'.
ENDIF.
APPEND WS_FIELDCAT.
CLEAR WS_FIELDCAT.
END-OF-DEFINITION.
HOUT AUFNR '订单' 12 CHAR.
HOUT MATNR '物料' 15 CHAR.
HOUT MEINS '单位' 6 CHAR.
HOUT BDMNG '需求数量' 13 QUAN.
HOUT ENMNG '提货数量' 13 QUAN.
HOUT LGPRO '生产仓储地' 4 CHAR.
HOUT YCXX1 '异常信息1' 100 CHAR.
* title = ''.
WS_LAYOUT-ZEBRA = 'X'.
WS_LAYOUT-GET_SELINFOS = ''.
WS_LAYOUT-COLWIDTH_OPTIMIZE = 'X'.
WS_LAYOUT-DETAIL_POPUP = 'X'.
WS_LAYOUT-NO_KEYFIX = 'X'.
* WS_LAYOUT-BOX_FIELDNAME = 'CHKID'.
V_REPID = SY-REPID.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = V_REPID
* i_callback_pf_status_set = 'MENU_SET'
* i_callback_user_command = 'EXECUTE_COMMAND'
IS_LAYOUT = WS_LAYOUT
IT_FIELDCAT = WS_FIELDCAT[]
IT_SPECIAL_GROUPS = WS_FIELDGROUPS_TAB[]
IT_SORT = WS_SORTFIELDS_TAB[]
IT_EVENTS = WS_EVENTS[]
I_GRID_TITLE = TITLE
TABLES
T_OUTTAB = GT_DDTL
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2.
ENDFORM. " SHOW_DDTLXX
PP生产订单创建、下达、报工、收货、投料的更多相关文章
- PP生产订单成本的计划、控制和结算
SAP系统成本分析功能关注订单的成本,通过对计划成本和实际成本的比较分析,可以发现成本控制上的问题,以便及时解决问题.1.订单成本计划在基础数据齐全的基础上,系统可以自动滚算生产订单的成本.生产订单计 ...
- 【PP系列】SAP 取消报工后修改日期
公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[PP系列]SAP 取消报工后修改日期 前言 ...
- 关于web开发中订单自动超时和自动收货的简单方法(window server)
最近做一个订单自动超时和自动收货的功能,因为以前是用的mysql 存储过程和定时器来完成,这次的业务逻辑相对复杂用以前的方式就不太合适,本来是准备使用定时执行php脚本来实现的,后来发现业务逻辑中使用 ...
- SAP PP 生产订单变更记录保存
*&---------------------------------------------------------------------* *& 包括 ZXCO1U01 *&am ...
- 为什么S/4HANA的生产订单创建后会自动release
在S/4HANA系统里我们观察到通过函数CO_61_ORDER_EDIT创建的生产订单会自动释放Release: 通过第86行的IF语句的条件检测不难找到原因. 变量PROFILE_TMP的类型为TC ...
- SAP S/4HANA生产订单创建时使用的工厂数据是从什么地方带出来的
大家如果使用我github上的这段代码创建S/4HANA的生产订单时,一定会发现,我在代码里并没有硬编码来指定生产订单的ID,然而运行时会发现我在系统里配置的这个2800被自动使用了,这是怎么做到的呢 ...
- PP生产订单的BADI增强 WORKORDER_UPDATE
METHOD if_ex_workorder_update~before_update. *---------------------->增强1 开始* "当生产订单类型为PP01时, ...
- SAP生产订单状态
SAP系统的常见订单状态如下: · CRTD (创建):标识生产订单刚刚创建,此时禁止做后续发料和报工确认等操作: · PREL (部分下达):当生产订单部分下达时,如仅下 ...
- PP-判断生产订单状态(关闭)
方法一.工单号通过 resb找到对象号 然后找到状态为I0045利用表JEST与TJ02T . 方法二.函数'STATU_CHECK' 检查工单状态为'I0045' 则为已做技术性关闭. READ T ...
随机推荐
- Win7搭建nginx+php+mysql开发环境以及websocket聊天实例测试
Win7搭建nginx+php+mysql开发环境以及websocket聊天实例测试一.下载相关安装包 1.下载nginx最新版本(nginx1.3.13版之后才支持websocket协议) 下载地址 ...
- Codeforces Round #380 (Div. 1, Rated, Based on Technocup 2017 - Elimination Round 2)
http://codeforces.com/contest/737 A: 题目大意: 有n辆车,每辆车有一个价钱ci和油箱容量vi.在x轴上,起点为0,终点为s,中途有k个加油站,坐标分别是pi,到每 ...
- Bestcoder Round 47 && 48
1.Senior's Array(hdu 5280) 题目大意:给出大小为N的数组和P,求将数组中的某个元素替换为P后的最大连续子段和.N<=1000 题解: 1.送分题,比赛的时候只想到枚举替 ...
- java 配置环境变量
使用java编程首先需要安装jdk,然后还需要给你的电脑配置环境变量,下面就用图文演示如何配置环境变量: 1.右键我的电脑 -> 属性 2.点击“高级系统设置” 3.点击“环境变量” 4.在系统 ...
- RBAC类的方法
rbac类的 方法 authenticate($map,$model='')方法 传入查询用户的条件和用户表的MODEL 返回数组包含用户的信息 saveAccessList($authId=null ...
- css3中transition和animation的回调处理
弱鸡最近在准备面试,网上找了一些题,发现一些基础题也完全答不好(┬_┬)看来还是要再接再励啊w(゚Д゚)w 言归正传,今天的主题是CSS3中的动画回调处理,这里动画执行完毕后触发的事件是transit ...
- [DNS-BIND]网络初始化
1.创建ns_g_socketmgr: 首先,套接字管理器是全局唯一的,与有多少个网络接口无关,全局变量定义在/bin/named/include/named/globals.h: EXTERN is ...
- JAVA第三周作业(从键盘输入若干数求和)
JAVA第三周作业(从键盘输入若干数求和) 在新的一周,我学习了JAVA的IO编程.下面的代码实现了从键盘输入若干数求和的目标.import java.util.Scanner; public cla ...
- HBase查找一条数据的过程
HBase中的Client如何路由到正确的RegionServer 在HBase中,大部分的操作都是在RegionServer完成的,Client端想要插入,删除,查询数据都需要先找到相应的 Regi ...
- Hadoop:输入,输出,key,value格式
map: (K1, V1) → list(K2, V2) reduce: (K2, list(V2)) → list(K3, V3) (K1, V1): jobConf.setInputKeyClas ...