MDG维护物料分类和特性(参考代码)

18 篇文章 6 订阅
16 篇文章 0 订阅

Background

MDG maintain MM classfication and valuation data via governace API

Code reference

parameters:p_cr    type usmd_crequest,
           p_matnr type matnr obligatory,
           p_class type klasse_d,
           p_sub   as checkbox.

try.
    data(lo_api_instance) = cl_usmd_gov_api=>get_instance( if_mdg_bs_mat_gen_c=>gc_model_mm ).

    lo_api_instance->refresh_buffers( ).
  catch cx_usmd_gov_api into data(lo_api_error).
    data(ls_error_message) = lo_api_error->e_message.
    cl_demo_output=>display_data( ls_error_message ).
    return.
endtry.

if ls_error_message-msgty ca 'AEX'.
  lo_api_instance->refresh_buffers( ).
  cl_demo_output=>display_data( ls_error_message ).
  return.
endif.

if p_cr is initial.
  data(lv_change_text) = 'create material attachment'.
  try.
      data(lv_crequest_id) = lo_api_instance->create_crequest(
      exporting
        iv_crequest_type = 'ZMM1T1'
        iv_description = conv usmd_txtlg( lv_change_text )
        ).
    catch cx_usmd_gov_api into lo_api_error.
      ls_error_message = lo_api_error->e_message.
  endtry.
else.
  lv_crequest_id = p_cr.
endif.

if ls_error_message-msgty ca 'AEX'.
  lo_api_instance->refresh_buffers( ).
  cl_demo_output=>display_data( ls_error_message ).
  return.
endif.

data:lr_data_key type ref to data,
     lr_data     type ref to data.
field-symbols:<ft_key> type index table.

lo_api_instance->create_data_reference(
exporting
  iv_entity_name =  if_mdg_bs_mat_gen_c=>gc_entity_material
  iv_struct = if_usmd_gov_api_entity=>gc_struct_key
importing
  er_table = lr_data_key
  er_structure = lr_data
  ).

assign lr_data_key->* to <ft_key>.
assign lr_data->* to field-symbol(<fs_key>).
<fs_key> = p_matnr.
insert <fs_key> into table <ft_key>.

data:lr_mat_class      type ref to data,
     lr_mat_class_line type ref to data.
lo_api_instance->create_data_reference(
exporting
  iv_entity_name = if_mdg_bs_mat_gen_c=>gc_entity_classasgn
  iv_struct = if_usmd_gov_api_entity=>gc_struct_key_attr
importing
  er_table = lr_mat_class
  er_structure = lr_mat_class_line
).

field-symbols:<fs_class_table> type any table.
assign lr_mat_class->* to <fs_class_table>.
assign lr_mat_class_line->* to field-symbol(<fs_class_line>).
assign component 'MATERIAL' of structure <fs_class_line> to field-symbol(<fs_field>).
<fs_field> = p_matnr.
assign component 'CLASS' of structure <fs_class_line> to <fs_field>.
<fs_field> = p_class.
assign component 'CLASSTYPE' of structure <fs_class_line> to <fs_field>.
<fs_field> = '001'.
insert <fs_class_line> into table <fs_class_table>.

data:lr_mat_valuation      type ref to data,
     lr_mat_valuation_line type ref to data.
lo_api_instance->create_data_reference(
exporting
  iv_entity_name = if_mdg_bs_mat_gen_c=>gc_entity_valuation
  iv_struct = if_usmd_gov_api_entity=>gc_struct_key_attr
importing
  er_table = lr_mat_valuation
  er_structure = lr_mat_valuation_line
  ).

field-symbols:<fs_valuation_table> type any table.
assign lr_mat_valuation->* to <fs_valuation_table>.
assign lr_mat_valuation_line->* to field-symbol(<fs_valuation_line>).

data(lv_class_conditon) = 'Z' && p_class && '%'.
select atinn,
       adzhl,
       atnam
  from cabn
  where atnam like @lv_class_conditon
  into table @data(lt_valuation_fields).

loop at lt_valuation_fields into data(ls_valuation_field).
  clear <fs_valuation_line>.
  assign component 'CHARID' of structure <fs_valuation_line> to <fs_field>.
  <fs_field> = ls_valuation_field-atinn.
  assign component 'CLASSTYPE' of structure <fs_valuation_line> to <fs_field>.
  <fs_field> = '001'.
  assign component 'MATERIAL' of structure <fs_valuation_line> to <fs_field>.
  <fs_field> = p_matnr.
  assign component 'VALCNT' of structure <fs_valuation_line> to <fs_field>.
  <fs_field> = '001'.
  assign component 'ATWRT' of structure <fs_valuation_line> to <fs_field>.
  <fs_field> = '1'.
   assign component 'ATCOD' of structure <fs_valuation_line> to <fs_field>.
  <fs_field> = '1'.
  insert <fs_valuation_line> into table <fs_valuation_table>.
endloop.


try.
    lo_api_instance->enqueue_entity(
    exporting
      iv_crequest_id = lv_crequest_id
      iv_entity_name = if_mdg_bs_mat_gen_c=>gc_entity_material
      it_data = <ft_key>
      ).

  catch cx_usmd_gov_api_core_error into data(lo_core_error).  "
    ls_error_message = lo_core_error->e_message.
  catch cx_usmd_gov_api_entity_lock into data(lo_entity_lock).  "
    ls_error_message = lo_entity_lock->e_message.
  catch cx_usmd_gov_api into lo_api_error.
    ls_error_message = lo_api_error->e_message.
endtry.

if ls_error_message-msgty ca 'AEX'.
  lo_api_instance->refresh_buffers( ).
  cl_demo_output=>display_data( ls_error_message ).
  return.
endif.

try.

    if <fs_class_table> is not initial.
      lo_api_instance->write_entity(
      exporting
        iv_crequest_id = lv_crequest_id
        iv_entity_name = if_mdg_bs_mat_gen_c=>gc_entity_classasgn
        it_data = <fs_class_table> ).
    endif.

    if <fs_valuation_table> is not initial.
      lo_api_instance->write_entity(
      exporting
        iv_crequest_id = lv_crequest_id
        iv_entity_name = if_mdg_bs_mat_gen_c=>gc_entity_valuation
        it_data = <fs_valuation_table> ).
    endif.

  catch cx_usmd_gov_api_core_error into lo_core_error.  "
    ls_error_message = lo_core_error->e_message.
    return.
  catch cx_usmd_gov_api_entity_write into data(lo_entity_write).  "
    ls_error_message = lo_entity_write->e_message.
  catch cx_usmd_gov_api into lo_api_error.
    ls_error_message = lo_api_error->e_message.
endtry.

if ls_error_message-msgty ca 'AEX'.
  lo_api_instance->refresh_buffers( ).
  cl_demo_output=>display_data( ls_error_message ).
  return.
endif.

try.
    lo_api_instance->check_crequest_data( iv_crequest_id = lv_crequest_id ).

    lo_api_instance->check_complete_data(
    exporting
      iv_crequest_id = lv_crequest_id
      "    it_key = lt_entity
      ).

  catch cx_usmd_gov_api_core_error into lo_core_error.  "
    ls_error_message = lo_core_error->e_message.
  catch cx_usmd_gov_api into lo_api_error.
    ls_error_message = lo_api_error->e_message.
endtry.

if ls_error_message-msgty ca 'AEX'.
  lo_api_instance->refresh_buffers( ).
  cl_demo_output=>display_data( ls_error_message ).
  return.
endif.

try.
    lo_api_instance->save( ).
  catch cx_usmd_gov_api_core_error into lo_core_error.  "
    ls_error_message = lo_core_error->e_message.
endtry.

if ls_error_message-msgty ca 'AEX'.
  lo_api_instance->refresh_buffers( ).
  cl_demo_output=>display_data( ls_error_message ).
  return.
endif.

commit work and wait.

try.
    lo_api_instance->dequeue_entity(
    exporting
      iv_crequest_id = lv_crequest_id
      iv_entity_name = if_mdg_bs_mat_gen_c=>gc_entity_material
      it_data = <ft_key> ).

    lo_api_instance->dequeue_crequest(
    exporting
      iv_crequest_id = lv_crequest_id ).

  catch cx_usmd_gov_api into lo_api_error.
    ls_error_message = lo_api_error->e_message.
endtry.

if ls_error_message-msgty ca 'AEX'.
  lo_api_instance->refresh_buffers( ).
  cl_demo_output=>display_data( ls_error_message ).
  return.
endif.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值