【ABAP】CO11N生产订单完工确认

本文详细介绍了在SAP环境下,如何通过事务码CO11或CO11N进行产品完工确认,特别是针对大量零配件生产的批量报工,包括使用BDC录制和调用系统标准BAPIBAPIPRODORDCONFCREATETT进行操作,以及涉及倒冲料扣料时调用BAPIPRODORDCONFGETTTPROP和BAPI链接操作的示例。
摘要由CSDN通过智能技术生成

生产完成后,需要对产品进行完工确认(也叫 报工确认);
般情况下,可以通过事务码(T-Code)CO11 或 CO11N 进行确认。
对于一些零配件的生产时,往往需要确认大量的数量,因而有些用户就会有批量报工的需求。
批量报工可以通过两种方式实现:录制BDC 或者 Call 系统标准 BAPI。
1)录制BDC这里就不讲述了,直接在CO11N上录屏即可;
2)Call 系统标准 BAPI:BAPI PRODORDCONF CREATE TT.
在报工时,当涉及到 倒冲料扣料 的操作时,则需要 call 两个BAPI来操作:
1.BAPI PRODORDCONF GET TT PROP 获取生产订单相关属性
2.BAPI PRODORDCONF CREATE TT 报工确认
相关操作示例(包括倒冲料操作): 

​
* 定义数据内表
DATA: gt_afko TYPE STANDARD TABLE OF afko.
 
* Work Area 定义
DATA: gw_afko  TYPE afko,
      gw_afpo  TYPE afpo,
      gw_afvc  TYPE afvc,
      gw_afvv  TYPE afvv.
 
DATA: gv_index  TYPE sy-tabix,
      gv_result TYPE c.
 
DATA:
*BAPI相关定义
      propose             LIKE bapi_pp_conf_prop,
      timetickets         LIKE bapi_pp_timeticket       OCCURS 0 WITH HEADER LINE,
      goodsmovements      LIKE bapi2017_gm_item_create  OCCURS 0 WITH HEADER LINE,
      link_conf_goodsmov  LIKE bapi_link_conf_goodsmov  OCCURS 0 WITH HEADER LINE,
      return_detail       LIKE bapi_coru_return         OCCURS 0 WITH HEADER LINE,
      return              LIKE bapiret1                 OCCURS 0 WITH HEADER LINE.
 
CONSTANTS:
      cn_flagx TYPE c VALUE 'X'.
 
* Get Data...
* Header
CLEAR gt_afko[].
SELECT aufnr rsnum aufpl
  INTO CORRESPONDING FIELDS OF TABLE gt_afko
  FROM afko
  WHERE aufnr IN so_aufnr  "生产工单号
  .
 
* Data Proccess...
CLEAR gw_afko.
LOOP AT gt_afko INTO gw_afko.
 
  IF sy-subrc = 0.
 
    CLEAR gw_afvc.
    SELECT SINGLE
      aufpl       "订单工序的工艺路线号
      aplzl       "订单的通用计数器
      vornr       "工序
      plnfl       "顺序
      arbid
      aplfl       "序列(新) 有值
      INTO CORRESPONDING FIELDS OF gw_afvc
      FROM afvc
      WHERE aufpl = gw_afko-aufpl.
 
    IF sy-subrc = 0.
 
* 1.需要更新的数据设置
      CLEAR propose.
      propose-quantity          = cn_flagx.   "更新数量
      propose-date_and_time     = cn_flagx.   "更新作业时间
      propose-goodsmovement     = cn_flagx.   "更新货物移动
 
* 2.作业时间
      CLEAR: timetickets,timetickets[].
      timetickets-orderid       = gw_print-aufnr. "工单号
      timetickets-operation     = gw_afvc-vornr.  "工序号
      timetickets-yield         = gw_print-lmnga. "工单生产数量
      timetickets-sequence      = gw_afvc-aplfl.  "
      APPEND timetickets.
      CLEAR  timetickets.
 
* 3.货物移动属性
* 第一次赋值,用于获取相关默认属性值
      CLEAR: goodsmovements,goodsmovements[].
      goodsmovements-orderid    = gw_print-aufnr.  "生产订单号
      goodsmovements-order_itno = gw_afvc-vornr.   "工序号
      APPEND goodsmovements.
      CLEAR  goodsmovements.
 
* 4.调用BAPI,获取默认属性值
      CALL FUNCTION 'BAPI_PRODORDCONF_GET_TT_PROP'
        EXPORTING
          propose            = propose
        IMPORTING
          return             = return
        TABLES
          timetickets        = timetickets
          goodsmovements     = goodsmovements
          link_conf_goodsmov = link_conf_goodsmov
          detail_return      = return_detail.
 
* 5.输出异常信息
      IF return-type = 'E' OR return-type = 'A'.
 
        CONCATENATE '错误:' return-message INTO return-message.
        gv_result = cn_flagx.
 
      ENDIF.
 
      LOOP AT return_detail WHERE type IS NOT INITIAL.
 
        IF return_detail-type = 'E' OR return_detail-type = 'A'.
 
          CONCATENATE '错误:' return_detail-message INTO return-message.
          gv_result = cn_flagx.
 
        ENDIF.
 
      ENDLOOP.
 
* 6. 如若需要更新相关信息,可在此修改
* -- 这里修改作业时间 --
      IF gv_result NE cn_flagx.
 
        CLEAR gv_index.
        LOOP AT timetickets.
 
          gv_index = sy-tabix.    "索引
          CLEAR gw_afvv.
          SELECT SINGLE * FROM afvv
            INTO CORRESPONDING FIELDS OF gw_afvv
            WHERE aufpl = gw_afvc-aufpl
              AND aplzl = gw_afvc-aplzl.
 
          IF sy-subrc = 0.
 
            IF NOT gw_afvv-bmsch = 0.
              IF timetickets-conf_acti_unit1 NE 'S'.
                timetickets-conf_activity1 = timetickets-yield * gw_afvv-vgw01 / gw_afvv-bmsch.
              ELSE.
                timetickets-conf_activity1 = timetickets-yield * gw_afvv-vgw01 DIV gw_afvv-bmsch.
              ENDIF.
 
              IF timetickets-conf_acti_unit2 NE 'S'.
                timetickets-conf_activity2 = timetickets-yield * gw_afvv-vgw02 / gw_afvv-bmsch.
              ELSE.
                timetickets-conf_activity2 = timetickets-yield * gw_afvv-vgw02 DIV gw_afvv-bmsch.
              ENDIF.
 
              IF timetickets-conf_acti_unit3 NE 'S'.
                timetickets-conf_activity3 = timetickets-yield * gw_afvv-vgw03 / gw_afvv-bmsch.
              ELSE.
                timetickets-conf_activity3 = timetickets-yield * gw_afvv-vgw03 DIV gw_afvv-bmsch.
              ENDIF.
 
              IF timetickets-conf_acti_unit4 NE 'S'.
                timetickets-conf_activity4 = timetickets-yield * gw_afvv-vgw04 / gw_afvv-bmsch.
              ELSE.
                timetickets-conf_activity4 = timetickets-yield * gw_afvv-vgw04 DIV gw_afvv-bmsch.
              ENDIF.
 
              IF timetickets-conf_acti_unit5 NE 'S'.
                timetickets-conf_activity5 = timetickets-yield * gw_afvv-vgw05 / gw_afvv-bmsch.
              ELSE.
                timetickets-conf_activity5 = timetickets-yield * gw_afvv-vgw05 DIV gw_afvv-bmsch.
              ENDIF.
 
              IF timetickets-conf_acti_unit6 NE 'S'.
                timetickets-conf_activity6 = timetickets-yield * gw_afvv-vgw06 / gw_afvv-bmsch.
              ELSE.
                timetickets-conf_activity6 = timetickets-yield * gw_afvv-vgw06 DIV gw_afvv-bmsch.
              ENDIF.
 
            ENDIF.
 
          ENDIF.
 
          timetickets-yield  = 200.    "待确认的产量(用户输入确认值)
 
          IF gw_afvv IS NOT INITIAL.
 
            MODIFY timetickets INDEX gv_index TRANSPORTING yield
              conf_activity1 conf_acti_unit1 conf_activity2 conf_acti_unit2
              conf_activity3 conf_acti_unit3 conf_activity4 conf_acti_unit4
              conf_activity5 conf_acti_unit5 conf_activity6 conf_acti_unit6.
 
          ELSE.
 
            MODIFY timetickets INDEX gv_index TRANSPORTING yield.
 
          ENDIF.
 
          CLEAR timetickets.
        ENDLOOP.
 
        CLEAR gw_afvv.
      ENDIF.
 
 
* 7. 调用BAPI,报工确认
      CLEAR: return, return[].
      CLEAR: return_detail, return_detail[].
      CALL FUNCTION 'BAPI_PRODORDCONF_CREATE_TT'
        EXPORTING
          post_wrong_entries = '1'
          testrun            = ''      "标识为 X,则为试运行 不提交至系统
        IMPORTING
          return             = return
        TABLES
          timetickets        = timetickets
          goodsmovements     = goodsmovements
          link_conf_goodsmov = link_conf_goodsmov
          detail_return      = return_detail.
 
      CLEAR gv_result.
      READ TABLE return WITH KEY type = 'E'.
      IF sy-subrc = 0.
 
        CONCATENATE '错误:' return-message INTO return-message.
        gv_result = cn_flagx.
 
      ENDIF.
      LOOP AT return_detail WHERE type IS NOT INITIAL.
        IF return_detail-type = 'E' OR return_detail-type = 'A'.
 
          CONCATENATE '错误:' return_detail-message INTO return-message.
          gv_result = cn_flagx.
 
        ENDIF.
      ENDLOOP.
 
      IF gv_result NE cn_flagx.
        CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
          EXPORTING
            wait = cn_flagx.
      ENDIF.
 
    ENDIF.
  ENDIF.
 
  CLEAR gw_afko.
ENDLOOP.

​

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值