CO02生产订单新增组件

    LOOP AT it_in.

        ls_storage_location-werks = it_in-werks."工厂
        ls_storage_locationx-werks = 'X'.

        ls_storage_location-lgort = it_in-lgort."库存地点
        ls_storage_locationx-lgort = 'X'.

        lv_kdauf = it_in-kdauf."销售订单
        lv_kdaufx = 'X'."
        lv_kdpos  = it_in-kdpos."销售订单中的条款数
        lv_kdposx = 'X'."

        CLEAR:lv_operation,lv_sequence,lv_gamng.
        READ TABLE lt_afko INTO DATA(ls_afko) WITH KEY aufnr = it_in-aufnr.
        IF sy-subrc EQ 0.
          lv_operation = ls_afko-aplzl.
          lv_sequence = ls_afko-plnfl.
          lv_gamng = ls_afko-gamng.
        ENDIF.

        ls_requ_quan-quantity = lv_gamng * it_in-menge."数量
        ls_requ_quan-uom = it_in-meins."基本计量单位
        lv_postp = 'L'."项目类别(物料单)
        lv_material = it_in-matnr."物料编号
        lv_order_number = it_in-aufnr.


        CALL FUNCTION 'CONVERSION_EXIT_ABPSP_INPUT'
          EXPORTING
            input  = it_in-posid "(WBS 要素)
          IMPORTING
            output = lv_pspel.

        lv_pspelx = 'X'."

        CLEAR:lv_sobkz,lv_sobkzx.
        READ TABLE lt_marc INTO DATA(ls_marc) WITH KEY matnr = it_in-matnr werks = it_in-werks.
        IF sy-subrc EQ 0.
          IF ls_marc-sbdkz = '2'.
            CLEAR:it_in-kdauf."销售订单
            CLEAR:it_in-kdpos."销售订单中的条款数
            CLEAR:it_in-posid. "(WBS 要素)
            CLEAR:lv_kdauf,lv_kdaufx,lv_kdpos,lv_kdposx,lv_pspel,lv_pspelx.
          ELSE.
            IF lv_kdauf IS NOT INITIAL AND lv_pspel IS NOT INITIAL.
              gs_in_pp072-msgty = 'E'.
              gs_in_pp072-message = '组件需求不能同时绑定销售订单和WBS'.
            ELSEIF lv_kdauf IS INITIAL AND lv_pspel IS NOT INITIAL.
              lv_sobkz  = 'Q'.
              it_in-sobkz = 'Q'.
              lv_sobkzx = 'X'.
            ELSEIF lv_kdauf IS NOT INITIAL AND lv_pspel IS INITIAL.
              lv_sobkz  = 'E'.
              it_in-sobkz = 'E'.
              lv_sobkzx = 'X'.
            ENDIF.
          ENDIF.ENDIF.

* BAPI to add components to Production Order
        CALL FUNCTION 'CO_XT_COMPONENT_ADD'
          EXPORTING
            is_order_key         = lv_order_number
            i_material           = lv_material
            is_requ_quan         = ls_requ_quan
            i_operation          = lv_operation
            i_sequence           = lv_sequence
            is_storage_location  = ls_storage_location
            is_storage_locationx = ls_storage_locationx
            i_batch              = lv_batch
            i_batchx             = lv_batchx
            i_postp              = lv_postp
            i_kdauf              = lv_kdauf
            i_kdaufx             = lv_kdaufx
            i_kdpos              = lv_kdpos
            i_kdposx             = lv_kdposx
            i_pspel              = lv_pspel
            i_pspelx             = lv_pspelx
            i_posno              = lv_positionno
            i_sobkz              = lv_sobkz
            i_sobkzx             = lv_sobkzx
          IMPORTING
            es_bapireturn        = ls_return
            e_error_occurred     = lv_error.

        IF lv_error = space.
          CLEAR: lv_numc,
                 ls_return.

* Modify POSNR via ASSIGN before DB update to correct the blank
* item number in Components due to incompatible types of I_POSNO
* (type CIF_R3RES-POSITIONNO) and RESB-POSNR
          ASSIGN ('(SAPLCOBC)RESB_BT[]') TO <ft_resb_bt>.
          DATA(line) = lines( <ft_resb_bt> ).
          LOOP AT <ft_resb_bt> ASSIGNING <fs_resb_bt>.
*          lv_numc = sy-tabix * 10.
*          <fs_resb_bt>-posnr = lv_numc.
*          CLEAR lv_numc.
            "新增行数据处理
            IF sy-tabix = line.

              IF it_in-posnr IS NOT INITIAL.
                <fs_resb_bt>-posnr = it_in-posnr.
              ELSE.

                SELECT SINGLE MAX( posnr )
                INTO @DATA(lv_posnr)
                FROM resb
                WHERE aufnr EQ @it_in-aufnr.
                lv_posnr = lv_posnr + 10.
                <fs_resb_bt>-posnr = lv_posnr.

              ENDIF.

              CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
                EXPORTING
                  input  = <fs_resb_bt>-posnr
                IMPORTING
                  output = <fs_resb_bt>-posnr.

              "排序字符串
              IF it_in-sortf IS NOT INITIAL.
                <fs_resb_bt>-sortf = it_in-sortf.
              ENDIF.

              "收货方
              IF it_in-wempf IS NOT INITIAL.
                <fs_resb_bt>-wempf = it_in-wempf.
              ENDIF.

              "活动号
              IF it_in-vornr IS NOT INITIAL.
                <fs_resb_bt>-vornr = it_in-vornr.
              ENDIF.
*            IF <fs_resb_bt>-xwaok IS INITIAL.
*              <fs_resb_bt>-xwaok = 'X'.
*            ENDIF.

            ENDIF.
          ENDLOOP.

sy-batch = 'X'."设置为后台模式 CALL FUNCTION 'CO_ZV_ORDER_POST' EXPORTING commit_flag = space ext_flg = 'X' trans_typ = 'V' no_dialog = 'X' "不弹出窗口 iv_commit_work_and_wait = 'X' EXCEPTIONS no_change = 01 update_reject = 02 error_message = 03. IF sy-subrc = 0. * commit dataCALL FUNCTION 'BAPI_TRANSACTION_COMMIT'. CALL FUNCTION 'CO_XT_ORDER_INITIALIZE'.

ELSE.* Data Rollback CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'. ENDIF.
ELSE.
CLEAR:lv_error,ls_return. CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'. ENDIF.
ENDLOOP.

 

上一篇:项目更改版本号之后打包失败(resolution will not be reattempted until the update interval of nexus has elapsed or u


下一篇:大数据之-Hadoop3.x_Hadoop_HDFS_掉线时限参数设置---大数据之hadoop3.x工作笔记0079