转自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