The 3 ways to Mass Update Contacts of Customer in SAP

domino 163522 1280 e1442441105680

Update Contacts of Customer: One of recurrent business requirement in SAP ECC is mass update Contacts for Customer in SAP.

The Standard way with Batch input is tricky and has low performance. In this post, I will give a technical overview of Customer’s Contacts then go through different method to Update Contacts of Customer.

This article covers :

Overview of Customer’s Contacts

Technical Side of Customer’s Contacts

Important Tables and tcodes for Customer’s Contact

The main table for Customer in SAP SD is KNA1 for Master Data Centrally.
and The table KNVV handle the Sales Area opened for Customer.

The table KNVP is for function Partner.

TableDescription
KNA1General Data in Customer Master
KNB1Customer Master (Company Code)
KNVVCustomer Master Sales Data
KNVPCustomer Master Partner Functions
KNVPCustomer Master Partner Functions

The VD0* and XD0* are the main tcode to maintain Customer.
Contact Persons are maintained through VAP*

TcodeDescription
XD01Create Customer (Centrally)
XD02Change Customer (Centrally)
XD03Display Customer (Centrally)
VD01Create Customer (Sales)
VD02Change Customer (Sales)
VD03Display Customer (Sales)
VAP1Create Contact Person
VAP2Change Contact Person
VAP3Display Contact Person


Important Tables and tcodes for Partner Function

The Partner Function (PARVW) pilots the type of Relation between Customer and Partner.

The main table for Function Partner Type are: TPAR.
In this table TPAR, Partner function are defined and typed ( NRART ).

The whole list of Partner function Type are (TVPA):

TableDescription
KNA1General Data in Customer Master
KNB1Customer Master (Company Code)
KNVVCustomer Master Sales Data
KNVPCustomer Master Partner Functions
KNVPCustomer Master Partner Functions

Once the Partner Function are defined, it has to be maintain and associated to Partner Determination Procedure.
To access the Partner Determination Procedure with SPRO, go to
Sales and Distribution > Basic Functions > Partner Determination > Set Up Partner Determination.
Select the activity Set Up Partner Determination for Customer Master

If you want to retrieve the allowed Function Partner from A Customer Account Group follows these steps:
1- Retrieve the Customer Account Group KTOKD from KNA1.
2- Retrieve the Partner Determination Procedure PARGR from TKUPA
3- Retrieve the list of Partner Function PARVW from TPAER
4- the description of functions are in TPART.

The main tables for Function Partner configuration are:

TableDescription
TKUPABusiness Partners: Customer Master Groups
TPARBusiness Partner: Functions
TPARTBusiness Partner Functions: Texts
TPAERBusiness Partner: Functions in Partner Determination Proceed.
update contacts of customer

Check this book about SAP CRM Technical Principles and Programming.

Mass Update Contacts of Customer

Batch-Input

Batch Input is the most standard way to Update Contacts of Customer in ECC including updating Partner functions.
Use SHDB to make a Transaction Record from XD02/01 or VD01/02
Then generate the Program and updated to your need.

Cons
When it comes to manage multiple partner function with Batch Input, it becomes harsh ( difficult ).
Actually you have to manage the position of Cursor because the view is based on Tab component in the Customer DynPro.

This is a simple way to handle cursor:

Manage Cursor for Deleting

    perform bdc_dynpro      using 'SAPMF02D'    '0324'.
    perform bdc_field       using 'BDC_CURSOR'  '*RF02D-KTONR'.
    perform bdc_field       using 'BDC_OKCODE'  '=ENTR' .

    perform bdc_field       using '*KNVP-PARVW'  iv_parvw.
    perform bdc_field       using '*RF02D-KTONR' iv_kunn2.

    perform bdc_dynpro      using 'SAPMF02D'    '0324'.
    perform bdc_field       using 'BDC_CURSOR'  'KNVP-PARVW(01)'.
    perform bdc_field       using 'BDC_OKCODE'  '=LDEL' .

Manage Cursor for Inserting

1- Count of existing function partners for Customer/ Sales Area
DESCRIBE TABLE pt_knvp LINES lv_count.

2- Get Number of last page when you can add the Relation
pv_page_new = lv_count DIV 15.

Why 15 ?
Because, in the standard dynpro used in Batch Input for Update Contacts of Customer, the table control has 15 lines.

3- Get the position of inserting within this page
lv_last_numb = lv_count MOD 15.
ADD 1 TO lv_last_numb.

4- Build the cursor position

The 4th step to update contacts of customer is to to build the cursor position:

IF lv_last_numb LT 10.
    MOVE lv_last_numb TO  pv_cursor_new.
    CONCATENATE '0' pv_cursor_new INTO pv_cursor_new.
  ELSE.
    MOVE lv_last_numb TO pv_cursor_new.
  ENDIF.

5- Scroll to the insertion page

  
  DO lv_page_modif TIMES.
    perform bdc_field       using 'BDC_OKCODE'  '=P+'.
  ENDDO.

6- Set the Cursor and the value

 set_cursor 'KNVP-PARVW' lv_cursor_modif lv_cursor.
    condense  lv_cursor no-gaps.
    perform bdc_field       using 'BDC_CURSOR'  lv_cursor.
    perform bdc_field       using 'BDC_OKCODE'  '=ENTR' .
    perform bdc_field       using lv_cursor iv_parvw.
    set_cursor 'RF02D-KTONR' lv_cursor_modif lv_cursor.
    condense  lv_cursor no-gaps.
    perform bdc_field       using 'BDC_CURSOR'  lv_cursor.
    perform bdc_field       using lv_cursor iv_kunn2.

CMD_EI_API

CMD_EI_API is the SAP standard Class build as Customer Processing APIs.
It proposes by SAP as a replacement for the Batch Input of Customer handling.

The main methods for this class are:

  • cmd_ei_api=>initialize( ) : initialize the class API
  • cmd_ei_api=>lock( iv_kunnr) : Lock the customer.
  • cmd_ei_api=>maintain_bapi : Create/Update/Delete Customer General Data/Sales Data.
  • cmd_ei_api=>unlock(iv_kunnr): Unlock the customer.

A Sample example for uploading Contacts with CMD_EI_API Class is in this link Update Customer with CMD_EI_API

Direct Table Update ( not recommended )

It is not the standard way to Update Contacts of Customer but it can be a solution for

  • mass uploading contacts
  • improving performance
  • bypassing standard control.

This method stands on direct update the KNVP table.

MODIFY KNVP FROM TABLE LT_KNVP_NEW[].

First, the data must be prepared in order to prevent errors.
a Special care goes to PARZA field ( Partner counter ).

Actually, if the function partner appears more than one time for KUNNR/VKORG ( Customer / Commercial Organization), the counter of this role must be incremented.

Here a sample Code to to mass upload “Personnel Numbers” (PERNR) for customer: Mass Update Personal Numbers of Customer KNVP