Assign Sales Partner Function of Customer Master Data using FM

Berikut adalah contoh program yang bisa digunakan untuk assign sales partner function pada customer master data (VD02):

REPORT  zassignpatner.

PARAMETERS: p_kunnr1 TYPE kunnr OBLIGATORY,
            p_vkorg	 TYPE knvp-vkorg OBLIGATORY,
            p_vtweg	 TYPE knvp-vtweg OBLIGATORY,
            p_spart	 TYPE knvp-spart OBLIGATORY,
            p_parvw  TYPE knvp-parvw OBLIGATORY,
            p_kunnr2 TYPE kunnr OBLIGATORY.

DATA: lt_knvp TYPE TABLE OF knvp WITH HEADER LINE,
      lt_xknvp TYPE TABLE OF fknvp WITH HEADER LINE,
      lx_kna1 TYPE kna1,
      lx_ikna1 TYPE kna1,
      ld_kunnr TYPE kunnr,
      ld_done TYPE c,
      ld_parza TYPE knvp-parza.

SELECT SINGLE mandt kunnr name1 ort01 sortl ktokd FROM kna1
  INTO CORRESPONDING FIELDS OF lx_kna1
  WHERE kunnr = p_kunnr1.

SELECT * FROM knvp INTO TABLE lt_knvp
  WHERE kunnr = p_kunnr1
    AND vkorg = p_vkorg
    AND vtweg = p_vtweg
    AND spart = p_spart
    AND parvw = p_parvw.


SORT lt_knvp BY parza DESCENDING.
READ TABLE lt_knvp INDEX 1.
IF sy-subrc = 0.
  ld_parza = lt_knvp-parza + 1.
ELSE.
  ld_parza = 0.
ENDIF.

READ TABLE lt_knvp WITH KEY kunn2 = p_kunnr2.
IF sy-subrc = 0.
  MESSAGE e006(aq) WITH p_kunnr2 'is already assigned to' p_kunnr1.
ELSE.
  CLEAR lt_xknvp.
  lt_xknvp-kunnr = p_kunnr1.
  lt_xknvp-vkorg = p_vkorg.
  lt_xknvp-vtweg = p_vtweg.
  lt_xknvp-spart = p_spart.
  lt_xknvp-parvw = p_parvw.
  lt_xknvp-parza = ld_parza.
  lt_xknvp-kunn2 = p_kunnr2.
  APPEND lt_xknvp.
ENDIF.

CALL FUNCTION 'SD_CUSTOMER_MAINTAIN_ALL'
  EXPORTING
    i_kna1                  = lx_kna1
    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_xknvp                 = lt_xknvp
  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.
ENDIF.
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