Create Customer Master Data Using FM SD_CUSTOMER_MAINTAIN_ALL

Saya pernah menggunakan FM SD_CUSTOMER_MAINTAIN_ALL untuk create master data, karena belum menemukan BAPI yang tepat untuk create master data. Tapi harus agak hati-hati dalam menggunakan BAPI ini, karena pada bila ada mandatory field yang tidak terisi, tidak ada error message yang ditampung dan customer baru tetap terbentuk. Jadi ada baiknya lakukan validasi data sebelum memanggil FM ini.

Berikut adalah contoh penggunaan FM SD_CUSTOMER_MAINTAIN_ALL untuk create customer master data.

REPORT  ycustomer.

DATA: lx_kna1 TYPE kna1,
      lx_ikna1 TYPE kna1,
      lx_knvv TYPE knvv,
      lx_addr TYPE bapiaddr1,
      lt_knvi TYPE TABLE OF fknvi WITH HEADER LINE,
      ld_kunnr TYPE kunnr,
      ld_done TYPE c.

lx_kna1-land1   = 'ID'. "country id
lx_kna1-name1   = 'Company Name'.
lx_kna1-ort01   = 'Jakarta'.
lx_kna1-pstlz   = '16123'.
lx_kna1-regio   = 'JK'.
lx_kna1-sortl   = 'Comp'.
lx_kna1-stras   = 'Jalanan Ibu Kota'.
lx_kna1-anred   = 'PT.'.
lx_kna1-ktokd   = 'ZZZZ'.       "Customer Account Group
lx_kna1-spras   = sy-langu.
lx_kna1-stcd1   = 'NON WAPU'.   "tax number
lx_kna1-lzone   = 'Z000000001'. "transportation zone
lx_kna1-erdat   = sy-datum.
lx_kna1-ernam   = sy-uname.

lx_knvv-vkorg = 'S111'. "sales org
lx_knvv-vtweg = 'D1'.   "dist channel
lx_knvv-spart = '11'.   "division
lx_knvv-kalks = 'A'.    "Pricing procedure
lx_knvv-kdgrp = '01'.   "customer group
lx_knvv-waers = 'IDR'.  "currency
lx_knvv-ktgrd = '01'.   "acc assignment group

lx_addr-name        = 'Company Name'.
lx_addr-city        = 'Jakarta'.
lx_addr-postl_cod1  = '16123'.
lx_addr-street      = 'Jalanan Ibu Kota'.
lx_addr-country     = 'ID'.
lx_addr-langu       = sy-langu.
lx_addr-region      = 'JK'.
lx_addr-sort1       = 'Comp'.
lx_addr-time_zone   = 'UTC+7'.
lx_addr-transpzone  = 'Z000000001'. "transportation zone
lx_addr-title       = 'PT.'.

lt_knvi-aland = 'ID'.   "tax country
lt_knvi-tatyp = 'MWST'. "tax category
lt_knvi-taxkd = '1'.    "tax classification
APPEND lt_knvi.

CALL FUNCTION 'SD_CUSTOMER_MAINTAIN_ALL'
  EXPORTING
    i_kna1                  = lx_kna1
    i_knvv                  = lx_knvv
    i_bapiaddr1             = lx_addr
    i_no_bank_master_update = 'X'
    pi_postflag             = 'X'
  IMPORTING
    e_kunnr                 = ld_kunnr
    o_kna1                  = lx_ikna1
    e_sd_cust_1321_done     = ld_done
  TABLES
    t_xknvi                 = lt_knvi
  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 AND WAIT.
  WRITE: 'Customer No.', ld_kunnr, 'was created'.
ENDIF.

Hope it helps 🙂

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s