CRM创建物料FM1

这是在中联混凝土那边搞的。。。。

method create_prd.
  data: lt_return type bapiret2_tab,
        ls_return like line of lt_return.
  data: gt_maintain_ext type comt_product_maintain_api_extt,
        gs_maintain_ext like line of gt_maintain_ext.
  data ls_product_api  type comt_product_maintain_api.
  data:lt_short_text type comt_pr_shtext_maintain_tab,
       ls_short_text type comt_pr_shtext_maintain.
  data:lt_categories type comt_prod_cat_rel_maintain_tab,
       ls_categories type line of comt_prod_cat_rel_maintain_tab,
       ls_category type comt_category.
  data gv_logical_system type tbdls-logsys.

*  data lt_price type table of comm_il_prcmpt.
*  data ls_price type comm_il_prcmpt.

*& 获取客户端
  call function 'OWN_LOGICAL_SYSTEM_GET'
    importing
      own_logical_system             = gv_logical_system
    exceptions
      own_logical_system_not_defined = 1
      others                         = 2.
  if sy-subrc <> 0.
  endif.

*& 产品抬头信息
  ls_product_api-com_product-competitor_prod = '1'.     "标记是否是竞争产品
  ls_product_api-com_product-product_type  = '01'.
  ls_product_api-com_product-product_guid  = cl_com_product=>guid_create( ).
  ls_product_api-com_product-product_id    = iv_product_id.
  ls_product_api-com_product-logsys        = gv_logical_system.
  ls_product_api-update_type               = 'I'.

  select single * into ls_category from comm_category where category_id = 'MAT_WETT'.
*
  ls_categories-data-client         = sy-mandt.
  ls_categories-update_type         = 'I'.
  ls_categories-data-category_guid  = ls_category-category_guid.
  ls_categories-data-category_id    = 'MAT_WETT'.
  ls_categories-data-hierarchy_guid = ls_category-hierarchy_guid.
  ls_categories-data-logsys         = gv_logical_system.
  insert ls_categories into table lt_categories.
  ls_product_api-categories = lt_categories.

*& 产品描述
  ls_short_text-data-product_guid = ls_product_api-com_product-product_guid.
  ls_short_text-data-langu        = sy-langu.
  ls_short_text-update_type       = 'I'.
  ls_short_text-data-short_text   = iv_product_desc.
  ls_short_text-data-logsys       = gv_logical_system.
  ls_short_text-data_x-short_text = 'X'.
  append ls_short_text to lt_short_text.
  ls_product_api-short_texts = lt_short_text.

**& 竞品供价
*  ls_price-data-product_guid = ls_product_api-com_product-product_guid.
*  ls_price-data-langu        = sy-langu.
*  ls_price-update_type       = 'I'.
*  ls_price-data-short_text   = iv_product_desc.
*  ls_price-data-logsys       = gv_logical_system.
*  ls_price-data_x-short_text = 'X'.
*  append ls_price to lt_price.
*  ls_product_api-price = lt_price.

  refresh gt_maintain_ext.
  gs_maintain_ext-header = ls_product_api.
  append gs_maintain_ext to gt_maintain_ext.


  call function 'COM_PRODUCT_MAINTAIN_MULT_API'
    exporting
      iv_check_only  = ''
    importing
      et_bapireturn  = lt_return
    changing
      ct_product     = gt_maintain_ext
    exceptions
      internal_error = 1
      others         = 2.

  read table lt_return into ls_return with key type = 'E'.
  if sy-subrc = 0.
    call function 'BAPI_TRANSACTION_ROLLBACK'.
    call function 'COM_PRODUCT_FREE_API'.
    ev_msg = 'E'.
    et_return[] = lt_return[].
    exit.
  else.
    call function 'COM_PRODUCT_SAVE_API'
      exporting
        iv_update_task   = 'X'
      exceptions
        internal_error   = 1
        save_not_allowed = 2
        others           = 3.
    if sy-subrc <> 0.
      call function 'BAPI_TRANSACTION_ROLLBACK'.
      call function 'COM_PRODUCT_FREE_API'.
      ev_msg = 'E'.
      et_return[] = lt_return[].
      exit.
    else.
      call function 'BAPI_TRANSACTION_COMMIT'.
      call function 'COM_PRODUCT_FREE_API'.
      ev_msg = 'S'.
      et_return[] = lt_return[].
    endif.
  endif.

endmethod.

原文地址:https://www.cnblogs.com/sapSB/p/3347178.html