批量创建客户

【转自http://blog.163.com/arhao_h/blog/static/125169020122266922956/】
批量创建客户

方式一:
REPORT z_test NO STANDARD PAGE HEADING .
 
DATA:ls_kna1 TYPE kna1,
     ls_knb1 TYPE knb1.
DATA:lt_upd_txt TYPE STANDARD TABLE OF fkuntxt.
DATA:lv_kunnr TYPE kunnr .
 
ls_kna1-kunnr = 'A20100918'.
ls_kna1-land1 = 'CN'.
ls_kna1-name1 = 'Calste'.
ls_kna1-ktokd = 'JD09'.
ls_kna1-anred = '先生'.
ls_kna1-civve = 'X'.
ls_kna1-spras = sy-langu.
 
*ls_knb1-kunnr = 'A20100918'.
*ls_knb1-bukrs = 'JNPC'.
*ls_knb1-akont = '2211020600'.
*ls_knb1-zuawa = '001'.
 
CALL FUNCTION 'SD_CUSTOMER_MAINTAIN_ALL'
  EXPORTING
    i_kna1                              = ls_kna1
*    i_knb1                              = ls_knb1
     I_MAINTAIN_ADDRESS_BY_KNA1         = 'X'
    pi_postflag                         = 'X'
 EXCEPTIONS
   client_error                        = 1
   kna1_incomplete                     = 2
   knb1_incomplete                     = 3
   knb5_incomplete                     = 4
   knvv_incomplete                     = 5
   kunnr_not_unique                    = 6
   sales_area_not_unique               = 7
   sales_area_not_valid                = 8
   insert_update_conflict              = 9
   number_assignment_error             = 10
   number_not_in_range                 = 11
   number_range_not_extern             = 12
   number_range_not_intern             = 13
   account_group_not_valid             = 14
   parnr_invalid                       = 15
   bank_address_invalid                = 16
   tax_data_not_valid                  = 17
   no_authority                        = 18
   company_code_not_unique             = 19
   dunning_data_not_valid              = 20
   knb1_reference_invalid              = 21
   cam_error                           = 22
   OTHERS                              = 23         .
IF sy-subrc <> 0.
  ROLLBACK WORK.
  MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
          WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ELSE.
  COMMIT WORK.
ENDIF.
 
方式二:
(class CMD_EI_API (Customer) and VMD_EI_API (Vendor))
REPORT  z_create_customer.
 
DATA:lv_flg.
DATA:ls_main TYPE cmds_ei_main,
     ls_mesg TYPE cvis_message,
     lt_msg TYPE bapiret2_t,
     lwa_msg TYPE bapiret2,
     lt_cust TYPE cmds_ei_extern_t,
     lwa_cust TYPE cmds_ei_extern,
     lt_company TYPE cmds_ei_company_t,
     lwa_company TYPE cmds_ei_company.
 
* 主数据
lwa_cust-header-object_task = 'I'.
lwa_cust-header-object_instance-kunnr = 'A20101241'.
lwa_cust-central_data-central-data-ktokd = 'JD09'.
lwa_cust-central_data-central-data-civve = 'X'.
lwa_cust-central_data-central-datax-ktokd = 'X'.
lwa_cust-central_data-central-datax-civve = 'X'.
* 地址数据
lwa_cust-central_data-address-task = 'I'.
lwa_cust-central_data-address-postal-data-title = '0002'.
lwa_cust-central_data-address-postal-data-name = 'JIARUI.Lv'.
lwa_cust-central_data-address-postal-data-langu = sy-langu.
lwa_cust-central_data-address-postal-data-country = 'CN'.
lwa_cust-central_data-address-postal-datax-title = 'X'.
lwa_cust-central_data-address-postal-datax-name = 'X'.
lwa_cust-central_data-address-postal-datax-langu = 'X'.
lwa_cust-central_data-address-postal-datax-country = 'X'.
* 公司代码数据
*lwa_cust-COMPANY_DATA-CURRENT_STATE = 'X'.
lwa_company-task = 'I'.
lwa_company-data_key-bukrs = 'JNPC'.
lwa_company-data-zuawa = '001'.
lwa_company-data-akont = '2211020600'.
lwa_company-datax-zuawa = 'X'.
lwa_company-datax-akont = 'X'.
APPEND lwa_company TO lt_company.
lwa_cust-company_data-company = lt_company.
 
APPEND lwa_cust TO lt_cust.
ls_main-customers = lt_cust.
CALL METHOD cmd_ei_api=>maintain
  EXPORTING
*    iv_test_run    = SPACE
    is_master_data = ls_main
  IMPORTING
    es_error       = ls_mesg    .
lt_msg = ls_mesg-messages.
LOOP AT lt_msg INTO lwa_msg.
  WRITE: / lwa_msg-type,lwa_msg-message.
  IF lwa_msg-type = 'E' OR lwa_msg-type = 'A'.
    lv_flg = 'X'.
  ENDIF.
ENDLOOP.
IF lv_flg IS INITIAL.
  COMMIT WORK.
ELSE.
  ROLLBACK WORK.
ENDIF.

转载于:https://www.cnblogs.com/rainysblog/p/4013878.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值