背景

对于使用PLM系统 或 CAPP系统的企业,SAP 需要承接上游对于BOM的数据,包括 创建、更改、删除等操作。

因管理要求不同,SAP端更新逻辑由原先的 先删除,再创建,改成直接更改,实现SAP端的ECN管理。

目前SAP中可用变更BOM的函数只有 CSAP_MAT_BOM_MAINTAIN函数,但是在使用过程中出现一些莫名其妙的报错。

这里对函数CSAP_MAT_BOM_MAINTAIN规范使用做下总结。

官方文档

(官方解释很重要,认真阅读可以少走很多弯路)

You can use function module CSAP_MAT_BOM_MAINTAIN to process simple material BOMs.
This function module is intended mainly as a tool for changing BOMs. However, it can also be used to create BOMs.

If you only want to create BOMs, use function module CSAP_MAT_BOM_CREATE.

To change BOMs, you can also use the following function modules:
CSAP_MAT_BOM_OPEN
CSAP_BOM_ITEM_MAINTAIN
CSAP_MAT_BOM_CLOSE

For more information and examples, see the documentation of the individual function modules.

Restrictions:

  • To date, you can only process one alternative or variant with this function module. This means that, if you do not enter an alternative for function module CSAP_MAT_BOM_MAINTAIN, the system assumes that you want to process alternative 01.
  • To date, changes to the BOM header are not yet supported.

Please note:(Important)

  • The item to be changed can be identified in two ways:

    • via the fields item category, item number, sort string, and object (depending on the item category, this can be material, document data, or class data).
      The names of these identifying fields begin with 'ID_' and are contained in structure CSIDENT_02. Structure CSIDENT_02 is part of structure STPO_API03.
      You can use any combination of these fields to identify the item, provided the fields identify the item uniquely. Otherwise you see the error message 'Item cannot be identified uniquely'.
    • via the BOM node and BOM item counter
      These fields are only known to the system if you have read the BOM before. If you identify the item in this way, you should therefore use function modules CSAP_MAT_BOM_OPEN, CSAP_BOM_ITEM_MAINTAIN, or CSAP_MAT_BOM_CLOSE to change the BOM.
  • If the error message 'Item cannot be changed' appears in the log, this can be for the following reasons:
    - The item is not valid on the valid-from date - it becomes valid at a
      later date.
    - The item has already been changed on the same valid-from date
      with a different change number.
  • You cannot change the item category of an item that exists already in the system.
  • To delete an item, you must identify it as described above for the change function and set the deletion indicator.
  • FL_BOM_CREATE (default ' ')
    If you set this indicator to 'X', the system creates a new BOM if it cannot find the BOM you want to change and there is no other error.
    Items can only be created if sufficient data exists to do this.
    The system ignores items with a deletion indicator when creating a BOM.
  • FL_NEW_ITEM (default ' ')
    If you set this indicator to 'X', the system creates a new item if it cannot find the item with the identification entered.
    The system ignores items with a deletion indicator.

官方传参Demo:

Example
*---- BOM header data structure
data: begin of tstk2.include structure stko_api02.
data: end of tstk2.
*---- BOM items table
data: begin of tstp3 occurs 0.include structure stpo_api03.
data: end of tstp3.*---- Object dependencies table
*     Basis data
data: begin of tdep2_data occurs 0.include structure dep_data.
data: end of tdep2_data.
*     Description
data: begin of tdep2_descr occurs 0.include structure dep_descr.
data: end of tdep2_descr.
*     Source
data: begin of tdep2_source occurs 0.include structure dep_source.
data: end of tdep2_source.
*     Sequence
data: begin of tdep2_order occurs 0.include structure dep_order.
data: end of tdep2_order.
*     Documentation
data: begin of tdep2_doc occurs 0.include structure dep_doc.
data: end of tdep2_doc.data: flg_warning like capiflag-warning.*- Initialize database logcall function 'CALO_INIT_API'exceptionslog_object_not_found     = 1log_sub_object_not_found = 2other_error              = 3others                   = 4.*- Fill item data
*  Exception: items that can be identified uniquely via their item
*             number
*  1. Item 0010: change quantityclear tstp3.tstp3-id_item_no = '0010'.                    "Item identificationtstp3-comp_qty   = '5.000'.append tstp3.
*  2. Item 0020: deleteclear tstp3.tstp3-id_item_no = '0020'.                    "Item identification.tstp3-fldelete   = 'X'.append tstp3.
*- 3. New item 0030 (stock material)
*  For new items, the ID_ fields, BOM nodes, and BOM item counters are
*  initial unless they use
*  FLG_NEW_ITEMclear tstp3.tstp3-item_no    = '0030'.tstp3-component  = 'MAT200'.tstp3-item_categ = 'L'.tstp3-comp_qty   = '1'.tstp3-rel_prod   = 'X'.tstp3-sortstring = 'A1'.append tstp3.
*  3. Item 0040: change componentclear tstp3.tstp3-id_item_no = '0040'.                    "Item identificationtstp3-component  = 'MAT500'.append tstp3.*- Change BOMcall function 'CSAP_MAT_BOM_MAINTAIN'exportingmaterial   = 'MAT100'plant      = '0001'bom_usage  = '1'valid_from = '14.10.1996'fl_bom_create = ' 'fl_new_item = ' 'i_stko  = tstkoimportingfl_warning = flg_warningo_stko     = tstk2tablest_stpo       = tstp3exceptionsothers  = 1.if sy-subrc eq 1.
*---- Error
*     Please see logendif.if flg_warning eq 'X'.
*---- Please see log for information, warning messages, and success
*     messages.Endif.

实际案例

本例中由外围系统全量同步完整BOM,但是一般仅修改个别行的某些信息,所以,添加了比对逻辑,无需变更的会跳过修改;同时,由于上游系统不传行的删除或新建标识,导致只能根据 行号、物料号为组合的识别ID判断(已存在的BOM信息),如果识别ID既没有被新物料占用,也没用在新的报文中出现,则认为被删除,标记上删除标识。

    TYPES: BEGIN OF ty_bom_h,activity TYPE string,matnr    TYPE marc-matnr,werks    TYPE marc-werks,stlan    TYPE mast-stlan,stlal    TYPE mast-stlal,bmeng    TYPE bicsk-bmeng,bmein    TYPE bicsk-bmein,aennr    TYPE string,datuv    TYPE string,aetxt    TYPE string,aegru    TYPE string,ausss    TYPE string,stktx    TYPE string,  "可选文本item     LIKE lt_bom_i,END OF ty_bom_h.DATA: wa_bom_h TYPE ty_bom_h.  TYPES: BEGIN OF ty_bom_i,posnr TYPE string,postp TYPE string,idnrk TYPE string,menge TYPE bicsp-menge,meins TYPE bicsp-meins,ausch TYPE string,lgort TYPE string,alpgr TYPE string,alprf TYPE string,alpst TYPE string,ewahr TYPE string,sortf TYPE string,potx1 TYPE string,potx2 TYPE string,ausss TYPE string,zyzd1 TYPE string,zyzd2 TYPE string,zyzd3 TYPE string,END OF ty_bom_i.DATA: lt_bom_i TYPE TABLE OF ty_bom_i,wa_bom_i TYPE ty_bom_i.
*******   以上为补充定义 *******
********************************************************DATA: lv_comp_qty TYPE p LENGTH 15 DECIMALS 3,lv_menge    TYPE p LENGTH 15 DECIMALS 3,lv_ausss    TYPE p LENGTH 5 DECIMALS 2,lv_tabix    TYPE sy-tabix.  DATA:lv_warning TYPE capiflag-flwarning,    "出错标识ls_mbom    TYPE csap_mbom,             "BOM key信息ls_stko_i  TYPE stko_api01,            "BOM头部信息-输入ls_stko_o  TYPE stko_api02.            "BOM头部信息-输出DATA:lv_datuv TYPE csap_mbom-datuv,lv_aennr TYPE csap_mbom-aennr.DATA:lv_datum     TYPE csap_mbom-datuv,lv_base_quan TYPE p  DECIMALS 3,lv_bmeng     TYPE p  DECIMALS 3,lt_stpo_read TYPE TABLE OF stpo_api02,ls_stpo_read TYPE stpo_api02,lt_stko_read TYPE TABLE OF stko_api02,ls_stko_read TYPE stko_api02.*   wa_bom_h、lt_bom_i为接口报文传输数据,数据根据实际需求自行填充CLEAR: lv_datum.CALL FUNCTION 'CONVERT_DATE_TO_EXTERNAL'EXPORTINGdate_internal            = sy-datumIMPORTINGdate_external            = lv_datumEXCEPTIONSdate_internal_is_invalid = 1OTHERS                   = 2.CLEAR:lt_stpo_read.CALL FUNCTION 'CSAP_MAT_BOM_READ'EXPORTINGmaterial    = wa_bom_h-matnrplant       = wa_bom_h-werksbom_usage   = wa_bom_h-stlanalternative = wa_bom_h-stlalvalid_from  = lv_datumvalid_to    = lv_datum
*     IMPORTING
*       FL_WARNING  =TABLESt_stpo      = lt_stpo_readt_stko      = lt_stko_readEXCEPTIONSerror       = 1OTHERS      = 2.READ TABLE lt_stko_read INTO ls_stko_read INDEX 1.CLEAR :lv_base_quan,lv_bmeng.PERFORM frm_units_string_convert USING ls_stko_read-base_quan CHANGING lv_base_quan  .PERFORM frm_units_string_convert USING wa_bom_h-bmeng  CHANGING lv_bmeng  .IF  lv_base_quan <> lv_bmeng OR ls_stko_read-base_unit <> wa_bom_h-bmein OR ls_stko_read-alt_text <> wa_bom_h-stktx .ls_stko_i-base_quan = wa_bom_h-bmeng.   "父项基本数量ls_stko_i-base_unit = wa_bom_h-bmein.   "基本单位ls_stko_i-alt_text  = wa_bom_h-stktx.   "可选文本ENDIF.CLEAR:lv_datuv,lv_aennr.lv_aennr = wa_bom_h-aennr.IF  wa_bom_h-datuv IS NOT INITIAL.lv_datuv = wa_bom_h-datuv+0(4) && '-' && wa_bom_h-datuv+4(2) && '-' && wa_bom_h-datuv+6(2).ENDIF.LOOP AT wa_bom_h-item INTO wa_bom_i."检查行项目是否需要变更READ TABLE lt_stpo_read INTO ls_stpo_read WITH KEY item_no   = wa_bom_i-posnrcomponent = wa_bom_i-idnrk.IF sy-subrc = 0."处理字符串型的数值"IFUSER用户默认: 2,222.222 格式REPLACE ALL OCCURRENCES OF ',' IN ls_stpo_read-comp_qty WITH space.REPLACE ALL OCCURRENCES OF ',' IN ls_stpo_read-op_scrap WITH space."清楚字符串的空格CONDENSE: ls_stpo_read-comp_qty,ls_stpo_read-op_scrap,ls_stpo_read-comp_unit,ls_stpo_read-comp_scrap,ls_stpo_read-issue_loc,ls_stpo_read-ai_group,ls_stpo_read-ai_strateg,ls_stpo_read-sortstring,ls_stpo_read-ai_prio,ls_stpo_read-usage_prob ."转换格式CLEAR: lv_comp_qty,lv_menge,lv_ausss.lv_comp_qty = ls_stpo_read-comp_qty.lv_menge = wa_bom_i-menge."比较行数据是否变更IF lv_comp_qty  = lv_menge   AND ls_stpo_read-op_scrap = wa_bom_i-ausss ANDls_stpo_read-comp_unit = wa_bom_i-meins  AND ls_stpo_read-comp_scrap = wa_bom_i-ausch ANDls_stpo_read-issue_loc  = wa_bom_i-lgort AND ls_stpo_read-ai_group   = wa_bom_i-alpgr ANDls_stpo_read-ai_strateg = wa_bom_i-alpst ANDls_stpo_read-sortstring = wa_bom_i-sortf AND ls_stpo_read-item_text1 = wa_bom_i-potx1.IF ls_stpo_read-ai_prio = '00'.CLEAR:ls_stpo_read-ai_prio.ENDIF.IF ls_stpo_read-ai_prio    = wa_bom_i-alprf AND ls_stpo_read-usage_prob = wa_bom_i-ewahr.CONTINUE.ENDIF.ENDIF.CLEAR:lv_tabix.ENDIF."原项目ls_stpo-id_comp    = wa_bom_i-idnrk.  "识别ID-BOM 组件ls_stpo-id_item_no = wa_bom_i-posnr.  "识别ID-BOM 项目号ls_stpo-id_itm_ctg = wa_bom_i-postp.  "识别ID-BOM 项目类别"已使用的识别号,不需要删除READ TABLE lt_stpo_read INTO ls_stpo_read WITH KEY item_no   = wa_bom_i-posnrcomponent = wa_bom_i-idnrk.IF sy-subrc = 0.lv_tabix = sy-tabix.DELETE lt_stpo_read INDEX lv_tabix.CLEAR:lv_tabix.ENDIF."新项目ls_stpo-item_no    = wa_bom_i-posnr.  "识别ID-BOM 项目号ls_stpo-item_categ = wa_bom_i-postp.  "项目类别ls_stpo-component  = wa_bom_i-idnrk.  "组件物料号ls_stpo-comp_qty   = wa_bom_i-menge.  "数量IF wa_bom_i-ausss IS NOT INITIAL AND ls_stpo_read-op_scrap <> wa_bom_i-ausss.ls_stpo-op_scrap   = wa_bom_i-ausss.  "装配报废率ls_stpo-op_net_ind = 'X'.             "净废品标识ENDIF.ls_stpo-comp_unit  = wa_bom_i-meins.  "单位ls_stpo-comp_scrap = wa_bom_i-ausch.  "损耗率ls_stpo-issue_loc  = wa_bom_i-lgort.  "仓储地点ls_stpo-rel_cost  = 'X'.  "标识:与成本核算相关的项目ls_stpo-REL_PROD  = 'X'.  "标识:与生产相关项目ls_stpo-ai_group   = wa_bom_i-alpgr.  "替代组ls_stpo-ai_prio    = wa_bom_i-alprf.  "优先级ls_stpo-ai_strateg = wa_bom_i-alpst . "策略ls_stpo-usage_prob = wa_bom_i-ewahr . "使用比例IF ls_stpo-usage_prob = '0'."在更改模式中,如果usage_prob等于0,则不会更新CLEAR:ls_stpo-usage_prob.ENDIF.ls_stpo-sortstring = wa_bom_i-sortf.  "排序字符串ls_stpo-item_text1 = wa_bom_i-potx1.  "项目文本"新增关联关系,更新ITEM 的Change No.ls_stpo-valid_from = lv_datuv.        "项目文本ls_stpo-change_no  = lv_aennr.        "变更编号ls_stpo-identifier = wa_bom_i-posnr.  "标识符APPEND ls_stpo TO lt_stpo.CLEAR: ls_stpo.ENDLOOP."MDM BOM 全量下发,如果下发与系统中不一致,直接删除IF lt_stpo_read[] IS NOT INITIAL.LOOP AT lt_stpo_read INTO ls_stpo_read.MOVE-CORRESPONDING ls_stpo_read TO ls_stpo.ls_stpo-fldelete   = 'X'.""'删除标识APPEND ls_stpo TO lt_stpo.CLEAR: ls_stpo.ENDLOOP.ENDIF."调用BAPI创建BOMCALL FUNCTION 'CSAP_MAT_BOM_MAINTAIN'EXPORTINGmaterial           = wa_bom_h-matnrplant              = wa_bom_h-werksbom_usage          = wa_bom_h-stlanalternative        = wa_bom_h-stlalvalid_from         = lv_datuvchange_no          = lv_aennri_stko             = ls_stko_ifl_commit_and_wait = 'X'fl_bom_create      = 'X'fl_new_item        = 'X'fl_complete        = 'X'
*       fl_default_values  = spaceIMPORTINGfl_warning         = lv_warningo_stko             = ls_stko_oTABLESt_stpo             = lt_stpoEXCEPTIONSerror              = 1OTHERS             = 2.IF sy-subrc <> 0.gs_return-type = 'E'.CALL FUNCTION 'MESSAGE_TEXT_BUILD'EXPORTINGmsgid               = sy-msgidmsgnr               = sy-msgnomsgv1               = sy-msgv1msgv2               = sy-msgv2msgv3               = sy-msgv3msgv4               = sy-msgv4IMPORTINGmessage_text_output = gs_return-message.CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.ELSE.gs_return-type = 'S'.CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'EXPORTINGwait = 'X'.gs_return-message = 'BOM修改成功'.ENDIF.
*&---------------------------------------------------------------------*
*& Form frm_units_string_convert
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*&      --> LS_STKO_READ_BASE_QUAN
*&      <-- LV_BASE_QUAN
*&---------------------------------------------------------------------*
FORM frm_units_string_convert  USING    pv_quan1CHANGING pv_quan2.DATA: lv_clabs TYPE p  DECIMALS 3,lv_dcpfm LIKE usr01-dcpfm.SELECT SINGLE dcpfm INTO lv_dcpfmFROM usr01WHERE bname = sy-uname.CLEAR lv_clabs.CALL FUNCTION 'UNITS_STRING_CONVERT'EXPORTINGunits_string = pv_quan1dcpfm        = lv_dcpfm      "此时为X
*     MLLN         = 'M'
*     TSND         = 'T'IMPORTINGunits        = lv_clabsEXCEPTIONSinvalid_type = 1OTHERS       = 2.IF  sy-subrc = 0.pv_quan2 = lv_clabs.ENDIF.ENDFORM.

本例中使用行号、物料号为组合的识别ID,所以无需搭配CSAP_MAT_BOM_OPEN、CSAP_MAT_BOM_CLOSE。

如有问题,欢迎留言交流!

SAP ABAP BOM 更新函数 CSAP_MAT_BOM_MAINTAIN使用相关推荐

  1. SAP ABAP BOM 创建 CSAP_MAT_BOM_CREATE 多备选BOM

    SAP标准的BOM创建函数CSAP_MAT_BOM_CREATE创建备选BOM,报错 .具体原因如下: 此处没有指定备选BOM . 解决方法:拷贝标准函数,更改如图代码如下或者使用CSAP_MAT_B ...

  2. SAP ABAP BOM 生产相关 成本核算标识相关

    当用BAPI或者函数创建BOM时候,如果图1相关字段都为空,则会根据配置表的默认值填充相关的字段.

  3. 【SAP Abap】BOM多级展开函数 CS_BOM_EXPL_MAT_V2 使用详解

    SAP ABAP BOM多级展开函数 CS_BOM_EXPL_MAT_V2 使用详解 1.函数入参说明 2.函数出参说明 1.函数入参说明 CALL FUNCTION 'CS_BOM_EXPL_MAT ...

  4. SAP ABAP 查找更改文档对象(SCDO)和表关系的在线字典1/2(全)

    SAP ABAP 查找更改文档对象(SCDO)和表关系的在线字典1/2(全) 简介: 一个 SAP 更改文档对象(SCDO:SAP Change Document Object )由一组更改表和更改设 ...

  5. SAP ABAP 业务对象 BUS2044 CostEstimate 成本估价 BAPI 清单和相关 TCODE

    SAP ABAP 业务对象 BUS2044 CostEstimate 成本估价 BAPI 清单和相关 TCODE 简介: SAP ABAP 业务对象 BUS2044 CostEstimate 成本估价 ...

  6. SAP ABAP 查找更改文档对象(SCDO)和表关系的在线字典2/2(全)

    SAP ABAP 查找更改文档对象(SCDO)和表关系的在线字典2/2(全) 简介: 一个 SAP 更改文档对象(SCDO:SAP Change Document Object )由一组更改表和更改设 ...

  7. SAP ABAP 因系统维护使ABAP语法不再被支持导致使用很久的程序报错问题之分析

    SAP ABAP 因系统维护使ABAP语法不再被支持导致使用很久的程序报错问题之分析 所在项目客户的一家工厂上线已经超过半年,其业务部门提出一个使用了半年的RF枪程序,突然不能使用了.程序直接Dump ...

  8. SAP ABAP FM AC_DOCUMENT_RECORD 研习

    SAP ABAP FM AC_DOCUMENT_RECORD 研习 如下物料凭证号4904373511/2018,对应的财务凭证号32000006184如下: 如何从ABAP的角度用某个functio ...

  9. 《SAP ABAP 开发入门》课程正式发布

    首先,课程还没有全部做完,这次课程采用的是连载的方式,目前已经完成第二章共计8个课时.以后打算每周至少更新2个课时,在每周三和周六必定更新.当然如果时间允许的话,我会加快课程的制作. 课程购买地址 & ...

最新文章

  1. EOS从入门到精通-设计背景与DPOS算法(文字稿)
  2. Mac中IDEA在配置tomcat时一直出现404的错误
  3. Linux学习之CentOS(二)--初识linux的一些常用命令
  4. 组合数据类型综合练习
  5. Struts1之Action小结
  6. BGP——Route-map扩展(讲解+配置)@
  7. 《linux核心应用命令速查》连载四:at:定时运行命令
  8. python汽车租赁系统django
  9. 思考模式之“5W1H“
  10. 计算机管理打不开路径不存在,电脑打不开软件提示路径不正确如何解决
  11. 百度地图 截图java_我从百度地图静态图API中通过url获取到的图片,用java有没有什么办法可以把图片上的百度logo去掉呢...
  12. HDU 4415 Assassin’s Creed 苦逼的贪心
  13. 怎么在添加为知笔记编辑器/为知笔记怎么用其他编辑器编辑/为知笔记怎么才能用Word/notepad++编辑
  14. 【2019-CVPR-3D人体姿态估计】Fast and Robust Multi-Person 3D Pose Estimation from Multiple Views
  15. linux eda软件下载,立创EDA V6.4.7 Linux版
  16. MATLAB基本语法详解
  17. 做一个社区配送的小程序 利用小程序搭建自己的社区配送营销商城,小程序社区O2O,社区网络超市微信小程序开发
  18. Unity小游戏2D(见缝插针)
  19. Sparrow RecSys 源码阅读
  20. Unity HybridRender 视锥体裁剪

热门文章

  1. 02 AP AUTOSAR 与 面向服务的架构SOA
  2. 经典规划PDDL-飞机运货问题
  3. Processing 分形之二—— Peter de Jong Attractor
  4. 从网瘾少年逆袭拿到微软 、字节等offer(下)
  5. php 侧边栏效果,侧边栏效果:如何在跳转后保持侧边栏已有的展开状态
  6. 远程控制(向日葵)实现的原理
  7. 【Tryhackme】Hacker+of+the+Hill+#1
  8. 链接neo4j图形数据库的图像化显示(基于d3.js/neovis.js/neod3.js)
  9. 浅谈智能小车的控制策略
  10. 新手必备的几个常用恶意软件检测分析平台