调用BAPI_MATERIAL_SAVEDATA批量创建/修改物料

report  ytest_savemat.
data: headdata                type bapimathead,     "表头数据
      clientdata              type bapi_mara,       "基本数据
      clientdatax             type bapi_marax.
data: materialdescription type table of bapi_makt with header line."描述
data: unitsofmeasure type table of bapi_marm with header line."
data: unitsofmeasurex type table of bapi_marmx with header line."
  data pr_unit type meins."基本单位
  data pr_unit2 type meins."重量单位
  data return type bapiret2.
data: begin of msg occurs 0,
material type matnr,
description type maktx,
message(97) type c,
end of msg.
data:begin of itab occurs 0,
  head_material type matnr,"物料号
  head_ind_sector type mbrsh,"行业领域
  head_matl_type type mtart,"物料类型
  t_makt_matl_desc type maktx,"物料描述
  mara_base_uom type meins,"基本计量单位
  mara_matl_group type matkl,"物料组
  t_old_mat_no type bismt,"型号
  mara_division type spart,"产品组
  t_dsn_office type labor,"实验室/办公室
  mara_item_cat type mtpos_mara,"普通项目组类别
  t_marm_gross_wt type brgew,"毛重
  mara_unit_of_wt type gewei,"重量单位
  mara_net_weight type ntgew,"净重
  mara_size_dim type groes,"大小/量纲
end of itab.
data itab1 type itab occurs 0 with header line.
perform putdata.
perform run.
form run.
loop at itab.
  clear headdata.
  headdata-material       = itab-head_material.
  headdata-matl_type      = itab-head_matl_type.
  headdata-ind_sector     = itab-head_ind_sector.
  headdata-basic_view     = 'X'.  "基本数据视图
  clear pr_unit.
  clear pr_unit2.
  perform frm_unit using itab-mara_base_uom changing pr_unit."基本单位
  perform frm_unit using itab-mara_unit_of_wt changing pr_unit2."重量单位
  clear clientdata.
  clientdata-base_uom = pr_unit."基本计量单位
  clientdata-matl_group = itab-mara_matl_group."物料组
  clientdata-old_mat_no = itab-t_old_mat_no."型号
  clientdata-division = itab-mara_division."产品组
  clientdata-dsn_office = itab-t_dsn_office."实验室/办公室
  clientdata-item_cat = itab-mara_item_cat."普通项目组类别
  clientdata-unit_of_wt = pr_unit2."重量单位
  clientdata-net_weight = itab-mara_net_weight."净重
  clientdata-size_dim = itab-mara_size_dim."大小/量纲
  "bapi_mara 的复选框结构
  clear clientdatax.
  clientdatax-base_uom = 'X'."基本计量单位
  clientdatax-matl_group = 'X'."物料组
  clientdatax-old_mat_no = 'X'."型号
  clientdatax-division = 'X'."产品组
  clientdatax-dsn_office = 'X'."实验室/办公室
  clientdatax-item_cat = 'X'."普通项目组类别
  clientdatax-unit_of_wt = 'X'."重量单位
  clientdatax-net_weight = 'X'."净重
  clientdatax-size_dim = 'X'."大小/量纲
  "计量单位
  unitsofmeasure-alt_unit = pr_unit.    "替换单位(必须为基本计量单位,否则会报错,说没有转换因子什么的)
  unitsofmeasure-numerator = 1.    "分子
  unitsofmeasure-denominatr = 1.    "分母
  unitsofmeasure-gross_wt = itab-t_marm_gross_wt."毛重
  unitsofmeasure-unit_of_wt = pr_unit2."需要填充毛重的话,注意此处需要添加重量单位,否则会一直提示你没有指定单位
  append unitsofmeasure.
  clear unitsofmeasure.
  unitsofmeasurex-alt_unit = pr_unit."注意此处不是填充'X'
  unitsofmeasurex-numerator = 'X'.
  unitsofmeasurex-denominatr = 'X'.
  unitsofmeasurex-gross_wt = 'X'.
  unitsofmeasurex-unit_of_wt = 'X'."此处填充'X'
  if unitsofmeasurex-alt_unit is not initial and unitsofmeasurex-numerator is not initial and unitsofmeasurex-denominatr is not initial.
    append unitsofmeasurex.
  endif.
  clear unitsofmeasurex.
  "物料描述
  clear materialdescription[].
  materialdescription-langu_iso = 'ZH'.
  materialdescription-matl_desc = itab-t_makt_matl_desc.
  append materialdescription.
  clear return.
    call function 'BAPI_MATERIAL_SAVEDATA'
      exporting
        headdata            = headdata
        clientdata          = clientdata
        clientdatax         = clientdatax
      importing
        return              = return
      tables
        materialdescription = materialdescription[]
        unitsofmeasure = unitsofmeasure[]
        unitsofmeasurex = unitsofmeasurex[].
    if return-type ne 'E'.
      call function 'BAPI_TRANSACTION_COMMIT'
      exporting
        wait          = 'X' .
    else.
      call function 'bapi_transaction_rollback'.
    endif.
endloop.
write : return-type,return-message.
endform.
form putdata.
  itab-head_material = '10101010105'.
  itab-head_ind_sector = 'M'.
  itab-head_matl_type = 'zroh'.
  itab-mara_base_uom = '个'."基本计量单位
  itab-mara_matl_group = '10235'."物料组
  itab-t_old_mat_no = 'testbapi05'."型号
  itab-mara_division = '00'."产品组
  itab-t_dsn_office = '001'."实验室/办公室
  itab-mara_item_cat = 'NORM'."普通项目组类别
  itab-mara_net_weight = 2."净重
*  itab-mara_normt = ''."行业标准描述
  itab-mara_size_dim = '2*3'."大小/量纲
  itab-t_marm_gross_wt = 22 / 10."毛重
  itab-mara_unit_of_wt = 'KG'."重量单位
  itab-t_makt_matl_desc = 'test mat 0005'.
    call function 'CONVERSION_EXIT_ALPHA_INPUT'"
      exporting
        input  = itab-head_material
      importing
        output = itab-head_material.
  append itab.
endform.
*获取基本计量单位内码
form frm_unit using unit1 changing unit2.
  call function 'CONVERSION_EXIT_CUNIT_INPUT'
    exporting      input          = unit1
                   language       = sy-langu
    importing      output         = unit2
    exceptions      unit_not_found = 1
    others         = 2.
  if sy-subrc <> 0.
*   message id sy-msgid type sy-msgty number sy-msgno
*           with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  endif.
endform.                    "frm_unit 
  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
提供的源码资源涵盖了Java应用等多个领域,每个领域都包含了丰富的实例和项目。这些源码都是基于各自平台的最新技术和标准编写,确保了在对应环境下能够无缝运行。同时,源码中配备了详细的注释和文档,帮助用户快速理解代码结构和实现逻辑。 适用人群: 适合毕业设计、课程设计作业。这些源码资源特别适合大学生群体。无论你是计算机相关专业的学生,还是对其他领域编程感兴趣的学生,这些资源都能为你提供宝贵的学习和实践机会。通过学习和运行这些源码,你可以掌握各平台开发的基础知识,提升编程能力和项目实战经验。 使用场景及目标: 在学习阶段,你可以利用这些源码资源进行课程实践、课外项目或毕业设计。通过分析和运行源码,你将深入了解各平台开发的技术细节和最佳实践,逐步培养起自己的项目开发和问题解决能力。此外,在求职或创业过程中,具备跨平台开发能力的大学生将更具竞争力。 其他说明: 为了确保源码资源的可运行性和易用性,特别注意了以下几点:首先,每份源码都提供了详细的运行环境和依赖说明,确保用户能够轻松搭建起开发环境;其次,源码中的注释和文档都非常完善,方便用户快速上手和理解代码;最后,我会定期更新这些源码资源,以适应各平台技术的最新发展和市场需求。 所有源码均经过严格测试,可以直接运行,可以放心下载使用。有任何使用问题欢迎随时与博主沟通,第一时间进行解答!

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值