添加生产订单组件——CO_XT_COMPONENT_ADD

效果:

代码:

DATA: ls_requ     TYPE coxt_s_quantity,
      ls_storage  TYPE coxt_s_storage_location,
      ls_storagex TYPE coxt_s_storage_locationx,
      ls_return   TYPE coxt_bapireturn,
      lt_return   TYPE coxt_t_bapireturn,
      lv_msg      TYPE string.

TYPES: BEGIN OF ty_resb_bt.
    INCLUDE TYPE resbb.
TYPES: indold     LIKE sy-tabix,
       no_req_upd LIKE sy-datar,
       END OF ty_resb_bt.

TYPES: lt_resb_bt TYPE TABLE OF ty_resb_bt.
FIELD-SYMBOLS: <lt_resb_bt> TYPE lt_resb_bt,
               <ls_resb_bt> TYPE ty_resb_bt.

ls_requ-quantity = 228.
ls_requ-uom = 'PCS'.

ls_storage-werks = '2000'.
ls_storage-lgort = '2101'.

ls_storagex-werks = 'X'.
ls_storagex-lgort = 'X'.

CALL FUNCTION 'CO_XT_ORDER_INITIALIZE'.

CALL FUNCTION 'CO_XT_COMPONENT_ADD'
  EXPORTING
    is_order_key         = '000020030749'   "生产订单
    i_material           = 'CTXB0056-S2V-1' "组件
    is_requ_quan         = ls_requ          "组件需求数量和单位
    i_operation          = '00000007'       "工艺工序节点计数器
    is_storage_location  = ls_storage       "工厂和仓库
    is_storage_locationx = ls_storagex
    i_postp              = 'L'              "项目种类
    i_posno              = '000000'         "BOM项目计数器
  IMPORTING
    es_bapireturn        = ls_return.

IF ls_return-type NE 'E'.

  ASSIGN ('(SAPLCOBC)RESB_BT[]') TO <lt_resb_bt>.

  LOOP AT <lt_resb_bt> ASSIGNING <ls_resb_bt> WHERE posnr IS INITIAL.
    <ls_resb_bt>-posnr = '0020'.  "组件项目编号
    <ls_resb_bt>-nomng = 228.     "输入数量
  ENDLOOP.

  CALL FUNCTION 'CO_XT_ORDER_PREPARE_COMMIT'
    TABLES
      et_bapireturn = lt_return.
  IF sy-subrc = 0.

    COMMIT WORK AND WAIT.

    "如果组件缺少状态对象则需要创建
    "PERFORM frm_create_status_object.
    lv_msg = '添加成功'.
    cl_demo_output=>write( lv_msg ).
  ELSE.
    cl_demo_output=>write( lt_return ).
  ENDIF.
ELSE.
  cl_demo_output=>write( ls_return ).
ENDIF.
cl_demo_output=>display(  ).

*&---------------------------------------------------------------------*
*& Form FRM_CREATE_STATUS_OBJECT
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM frm_create_status_object .

  DATA: lv_objnr TYPE resb-objnr.

  DO 10 TIMES.
    SELECT SINGLE objnr INTO lv_objnr FROM resb
           WHERE aufnr = '000020030749' "生产订单号码
           AND posnr = '0020'.          "组件项目号码
    IF sy-subrc = 0.
      EXIT.
    ENDIF.

    WAIT UP TO 1 SECONDS.
  ENDDO.

  IF lv_objnr IS NOT INITIAL.
    CALL FUNCTION 'STATUS_OBJECT_CREATE'
      EXPORTING
        objnr                        = lv_objnr
        obtyp                        = 'OKP'
      EXCEPTIONS
        obtyp_invalid                = 1
        status_object_already_exists = 2
        stsma_invalid                = 3
        stsma_obtyp_invalid          = 4
        OTHERS                       = 5.

    IF sy-subrc NE 0.
      ROLLBACK WORK.
    ELSE.
      COMMIT WORK.
    ENDIF.

  ENDIF.
ENDFORM.

于2022年9月9日发现直接使用这个函数添加的组件有些情况下会造成业务问题

正常来说,对生产订单"技术性完成"和"删除旗标设置"时,会对所有的组件上"已删除"标识,但是用这个函数加的组件不会。

然后有注意到用这个函数添加的组件缺少状态对象

根据错误消息BS001查到Note 1835087有说可以使用程序RISTEQ03来修复设备的错误或缺失的状态,然后有看下了程序的源代码

然后我在执行完增加生产订单组件的函数后执行了函数STATUS_OBJECT_CREATE,去测试上面说的问题,居然可以了

 

下面代码解决添加的组件没有因相同工序而排列在一起的问题

DATA: ls_requ     TYPE coxt_s_quantity,
      ls_storage  TYPE coxt_s_storage_location,
      ls_storagex TYPE coxt_s_storage_locationx,
      ls_return   TYPE coxt_bapireturn,
      lt_return   TYPE coxt_t_bapireturn,
      lv_aufnr    TYPE aufnr,
      lv_msg      TYPE string.

TYPES: BEGIN OF ty_resb_bt.
    INCLUDE TYPE resbb.
TYPES: indold     LIKE sy-tabix,
       no_req_upd LIKE sy-datar,
       END OF ty_resb_bt.

TYPES: lt_resb_bt TYPE TABLE OF ty_resb_bt.
FIELD-SYMBOLS: <lt_resb_bt> TYPE lt_resb_bt,
               <ls_resb_bt> TYPE ty_resb_bt.

"添加第1个组件
lv_aufnr = '000021063941'.

ls_requ-quantity = 2.
ls_requ-uom = 'PCS'.

ls_storage-werks = '2000'.
ls_storage-lgort = '2102'.

ls_storagex-werks = 'X'.
ls_storagex-lgort = 'X'.

CALL FUNCTION 'CO_XT_COMPONENT_ADD'
  EXPORTING
    is_order_key         = lv_aufnr      "生产订单
    i_material           = 'CTYB0734-XX' "子件
    is_requ_quan         = ls_requ       "子件需求数量和单位
    i_operation          = '00000003'    "工艺工序节点计数器
    is_storage_location  = ls_storage    "工厂和仓库
    is_storage_locationx = ls_storagex
    i_postp              = 'L'           "项目种类
    i_posno              = '000000'      "BOM项目计数器
  IMPORTING
    es_bapireturn        = ls_return.

"添加第2个组件
ls_requ-quantity = 186 / 1000 * -1.
ls_requ-uom = 'KG'.

ls_storage-werks = '2000'.
ls_storage-lgort = '211A'.

ls_storagex-werks = 'X'.
ls_storagex-lgort = 'X'.

CALL FUNCTION 'CO_XT_COMPONENT_ADD'
  EXPORTING
    is_order_key         = lv_aufnr      "生产订单
    i_material           = 'MTBB-PGX008' "子件
    is_requ_quan         = ls_requ       "子件需求数量和单位
    i_operation          = '00000001'    "工艺工序节点计数器
    is_storage_location  = ls_storage    "工厂和仓库
    is_storage_locationx = ls_storagex
    i_postp              = 'L'           "项目种类
    i_posno              = '000000'      "BOM项目计数器
  IMPORTING
    es_bapireturn        = ls_return.

IF ls_return-type NE 'E'.

  ASSIGN ('(SAPLCOBC)RESB_BT[]') TO <lt_resb_bt>.

  "按工序节点排序完再给组件项目号
  SORT <lt_resb_bt> BY aplzl.

  LOOP AT <lt_resb_bt> ASSIGNING <ls_resb_bt>.
    "组件项目编号
    <ls_resb_bt>-posnr = 10 * sy-tabix.
    <ls_resb_bt>-posnr = |{ <ls_resb_bt>-posnr ALPHA = IN }|.
  ENDLOOP.

  CALL FUNCTION 'CO_XT_ORDER_PREPARE_COMMIT'
    TABLES
      et_bapireturn = lt_return.
  IF sy-subrc = 0.
    COMMIT WORK AND WAIT.

    "如果组件缺少状态对象则需要创建
*    LOOP AT <lt_resb_bt> ASSIGNING <ls_resb_bt>.
*      PERFORM frm_create_status_object USING lv_aufnr <ls_resb_bt>-posnr.
*    ENDLOOP.

    lv_msg = '添加成功'.
    cl_demo_output=>write( lv_msg ).
  ELSE.
    cl_demo_output=>write( lt_return ).
  ENDIF.
ELSE.
  cl_demo_output=>write( ls_return ).
ENDIF.
cl_demo_output=>display(  ).

*&---------------------------------------------------------------------*
*& Form FRM_CREATE_STATUS_OBJECT
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*&      --> LV_AUFNR
*&      --> <LS_RESB_BT>_POSNR
*&---------------------------------------------------------------------*
FORM frm_create_status_object  USING    iv_aufnr
                                            iv_posnr.
  DATA: lv_objnr TYPE resb-objnr.

  DO 10 TIMES.
    SELECT SINGLE objnr INTO lv_objnr FROM resb
           WHERE aufnr = iv_aufnr "生产订单号码
           AND posnr = iv_posnr.  "组件项目号码
    IF sy-subrc = 0.
      EXIT.
    ENDIF.

    WAIT UP TO 1 SECONDS.
  ENDDO.

  IF lv_objnr IS NOT INITIAL.
    CALL FUNCTION 'STATUS_OBJECT_CREATE'
      EXPORTING
        objnr                        = lv_objnr
        obtyp                        = 'OKP'
      EXCEPTIONS
        obtyp_invalid                = 1
        status_object_already_exists = 2
        stsma_invalid                = 3
        stsma_obtyp_invalid          = 4
        OTHERS                       = 5.

    IF sy-subrc NE 0.
      ROLLBACK WORK.
    ELSE.
      COMMIT WORK.
    ENDIF.

  ENDIF.
ENDFORM.

 

posted @ 2020-06-03 22:14  鲸与海  阅读(3376)  评论(1编辑  收藏  举报