XK01 创建供应商

vmd_ei_api=>maintain_direct_input

 

* 供应商表头

  ls_vendors-header-object_instance-lifnr = lv_vendor.  "供应商

  ls_vendors-header-object_task = 'M'.              "创建/更改

* 通用数据

  ls_vendors-central_data-central-data-stceg       = stceg.      "增值税登记号

  ls_vendors-central_data-central-data-ktokk       = '0001'.     "账户组

  ls_vendors-central_data-central-data-j_1kfrepre  = j_1kfrepre. "代表名称

  ls_vendors-central_data-central-datax-stceg      = 'X'.        "增值税登记号

  ls_vendors-central_data-central-datax-ktokk      = 'X'.        "账户组

  ls_vendors-central_data-central-datax-j_1kfrepre = 'X'.        "代表名称

* 电话

  ls_phone-contact-data-telephone = phone.

  append ls_phone to ls_vendors-central_data-address-communication-phone-phone.

  clear ls_phone.

* 邮箱

  ls_smtp-contact-data-e_mail      = smtp.

  append ls_smtp to ls_vendors-central_data-address-communication-smtp-smtp.

  clear ls_smtp.

 

  ls_vendors-central_data-address-postal-data-name         = name.       "名称

  ls_vendors-central_data-address-postal-data-name_2       = name.       "名称

  ls_vendors-central_data-address-postal-data-sort1        = sort1.      "属性(SAP为搜索项 1)

  ls_vendors-central_data-address-postal-data-street       = street.     "街道/门牌号

  ls_vendors-central_data-address-postal-data-postl_cod1   = postl_cod1. "邮政编码

  ls_vendors-central_data-address-postal-data-city         = city.       "城市

  ls_vendors-central_data-address-postal-data-country      = country.    "国家

  ls_vendors-central_data-address-postal-data-region       = region.     "地区

  ls_vendors-central_data-address-postal-data-langu        = '1'.        "语言

  ls_vendors-central_data-address-postal-datax-name        = 'X'.

  ls_vendors-central_data-address-postal-datax-name_2      = 'X'.

  ls_vendors-central_data-address-postal-datax-sort1       = 'X'.

  ls_vendors-central_data-address-postal-datax-street      = 'X'.

  ls_vendors-central_data-address-postal-datax-postl_cod1  = 'X'.

  ls_vendors-central_data-address-postal-datax-city        = 'X'.

  ls_vendors-central_data-address-postal-datax-country     = 'X'.

  ls_vendors-central_data-address-postal-datax-region      = 'X'.

  ls_vendors-central_data-address-postal-datax-langu       = 'X'.

* 采购组织数据

  ls_purchasing-task = 'M'.

  ls_purchasing-data_key-ekorg = '1000'.

  ls_purchasing-data-waers = waers.

  ls_purchasing-data-verkf = verkf.

  ls_purchasing-data-telf1 = telf1.

  ls_purchasing-data-eikto = eikto.

  ls_purchasing-data-webre  = 'X'.

  ls_purchasing-datax-waers = 'X'.

  ls_purchasing-datax-verkf = 'X'.

  ls_purchasing-datax-telf1 = 'X'.

  ls_purchasing-datax-webre = 'X'.

  ls_purchasing-datax-eikto = 'X'.

 

  if requesttype = 'CREATE'.

    ls_functions-task = 'I'.

    ls_functions-data_key-parvw = 'BA'.

    ls_functions-data-defpa = ''.

    ls_functions-data-partner = lv_vendor.

    ls_functions-datax-defpa = 'X'.

    ls_functions-datax-partner = 'X'.

    append ls_functions to lt_functions.

    ls_functions-data_key-parvw = 'LF'.

    ls_functions-data-defpa = ''.

    ls_functions-data-partner = lv_vendor.

    ls_functions-datax-defpa = 'X'.

    ls_functions-datax-partner = 'X'.

    append ls_functions to lt_functions.

    ls_functions-data_key-parvw = 'RS'.

    ls_functions-data-defpa = ''.

    ls_functions-data-partner = lv_vendor.

    ls_functions-datax-defpa = 'X'.

    ls_functions-datax-partner = 'X'.

    append ls_functions to lt_functions.

    ls_purchasing-functions-functions = lt_functions.

  endif.

  append ls_purchasing to ls_vendors-purchasing_data-purchasing.

  clear ls_purchasing.

 

  append ls_vendors to lt_vendors.

  clear ls_vendors.

  ls_main-vendors = lt_vendors.

 

* 创建或者更新供应商

  call method vmd_ei_api=>maintain_direct_input

    exporting

      is_master_data           = ls_main

    importing

      es_master_data_correct   = l1

      es_message_correct       = l2

      es_master_data_defective = l3

      es_message_defective     = l4.

  if l4-is_error = ''.

    call function 'BAPI_TRANSACTION_COMMIT'

      exporting

        wait = 'X'.

    return_status = 'S'.

    if requesttype = 'CREATE'.

      return_value = '供应商创建成功!'.

    elseif requesttype = 'UPDATE'.

      return_value = '供应商更新成功!'.

    endif.

    sapcode = lv_vendor.

  else.

    call function 'BAPI_TRANSACTION_ROLLBACK'.

    return_status = 'F'.

    clear ls_message.

    read table l4-messages into ls_message with key type = 'E'.

    if sy-subrc = 0.

      message id ls_message-id

              type ls_message-type

              number ls_message-number

              with  ls_message-message_v1

                    ls_message-message_v2

                    ls_message-message_v3

                    ls_message-message_v4

              into return_value.

    endif.

  endif.

 

猜你喜欢

转载自blog.csdn.net/cylcylcylcylwo/article/details/113929619