正文部分
生产完成后,需要对产品进行完工确认(也叫 报工确认); 一般情况下,可以通过事务码(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 报工确认
相关操作示例(包括倒冲料操作):
代码语言:javascript复制
* 定义数据内表
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.