SAP 批量修改或添加BOM组件

导语:前面【SAP 批量BOM创建BAPI : BAPI_MATERIAL_BOM_GROUP_CREATE】说到了如何通过BAPI创建BOM,这里简单说一下如何批量修改或添加BOM组件,他的实现形式和BAPI基本是一致的,通过RFC函数进行实现,这里主要实现过程有三步,打开BOM,修改/添加,关闭BOM。

👉【BAPI记录清单…】


    CASE e_salv_function.
      WHEN 'UPLOAD'.

        gr_selections = gr_table->get_selections( ).
        it_rows = gr_selections->get_selected_rows( ).   "取到选择行

        CLEAR it_selection.
        CLEAR h_disp.

        LOOP AT it_rows INTO h_rows.
          READ TABLE it_disp INDEX h_rows INTO h_disp.
          APPEND h_disp TO it_selection.
        ENDLOOP.

        CLEAR h_disp.

        LOOP AT it_selection INTO h_disp .
          DATA:lv_stlnr TYPE mast-stlnr.
          DATA:lv_stlal TYPE mast-stlal.
          SELECT SINGLE stlnr , stlal FROM mast INTO (@lv_stlnr ,@lv_stlal  ) WHERE matnr  = @h_disp-matnr.
          SELECT SINGLE  stlkn FROM stpo INTO @DATA(lv_stlkn) WHERE stlnr  = @lv_stlnr AND  idnrk =  @h_disp-idnrk .
*                    OPEN BOM
          CLEAR t_stpo.
          REFRESH t_stpo.
          DATA:lv_valid TYPE char10.
          CLEAR lv_valid.
*          lv_valid  = sy-datum+0(4) && '.' && sy-datum+4(2) && '.' && sy-datum+6(2).
          lv_valid  = sy-datum+0(4) && sy-datum+4(2)  && sy-datum+6(2).
       
          "打开 BOM
          CALL FUNCTION 'CSAP_MAT_BOM_OPEN'
            EXPORTING
              material    = h_disp-matnr
              plant       = h_disp-werks
              bom_usage   = '1'
              alternative = lv_stlal  "P_ALT
              valid_from  = lv_valid
              change_no   = h_disp-aennr
*             REVISION_LEVEL         =
*             FL_NO_CHANGE_DOC       = ' '
*                     IMPORTING
*             O_STKO      =
*             FL_WARNING  =
            TABLES
              t_stpo      = t_stpo[]
*             T_DEP_DATA  =
*             T_DEP_DESCR =
*             T_DEP_ORDER =
*             T_DEP_SOURCE           =
*             T_DEP_DOC   =
            EXCEPTIONS
              error       = 1
              OTHERS      = 2.
          DATA:lv_exit .
          CLEAR lv_exit.
          
          "如果可以找到就进行修改
          LOOP AT t_stpo ASSIGNING FIELD-SYMBOL(<fs>)  WHERE  component   = h_disp-idnrk.
            <fs>-change_no  = h_disp-aennr.
            <fs>-comp_qty   = h_disp-menge.
            <fs>-comp_unit  = h_disp-meins.

*                    维护BOM
            CALL FUNCTION 'CSAP_BOM_ITEM_MAINTAIN'
              EXPORTING
                i_stpo = <fs> "HEADLINE
              EXCEPTIONS
                error  = 1
                OTHERS = 2.
            IF  sy-subrc  = 0.
              r_code = 'OK'.
            ELSE.
              r_code = 'ERROR'.
            ENDIF.
            lv_exit = 'X'.
          ENDLOOP.
          "如果物料不存在,就新增一行
          DATA: i_stpo TYPE stpo_api02.
          IF sy-subrc <> 0.
            SORT t_stpo BY item_no DESCENDING.
            READ TABLE t_stpo INTO DATA(gs_stpo) INDEX 1.
            i_stpo-item_categ = gs_stpo-item_categ.
            i_stpo-item_no    = gs_stpo-item_no + 10.
            i_stpo-itm_ident  = gs_stpo-itm_ident + 1.
            i_stpo-component  = h_disp-idnrk.
            i_stpo-change_no  = h_disp-aennr.
            i_stpo-comp_qty   = h_disp-menge.
            i_stpo-comp_unit  = h_disp-meins.

            CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
              EXPORTING
                input  = i_stpo-item_no
              IMPORTING
                output = i_stpo-item_no.

* 维护bom
            CALL FUNCTION 'CSAP_BOM_ITEM_MAINTAIN'
              EXPORTING
                i_stpo = i_stpo "HEADLINE
              EXCEPTIONS
                error  = 1
                OTHERS = 2.
            IF  sy-subrc  = 0.
              r_code = 'OK'.
            ELSE.
              r_code = 'ERROR'.
            ENDIF.
            lv_exit = 'X'.
          ENDIF.



         " 关闭BOM
          CALL FUNCTION 'CSAP_MAT_BOM_CLOSE'
            EXCEPTIONS
              error  = 1
              OTHERS = 2.
          IF sy-subrc = 0.

          ENDIF.

          h_disp-v_msg = r_code.
          IF  r_code IS INITIAL.
            h_disp-v_msg = '组件不存在'.
          ENDIF.
          MODIFY TABLE it_disp  FROM h_disp.
          CLEAR r_code.
          gr_table->refresh( ).

        ENDLOOP .
    ENDCASE.

作者:小飞猪猪猪猪猪猪猪–CSDN

  • 6
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小飞猪猪猪猪猪猪猪

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值