Recently I had to create a Program for Vendor Master Create with Control Data, Company and Purchase Organization data.
With few search in SDN it was clear that VMD_EI_API class would solve this purpose….this is a small example of how this could be achieved using this class.
There are basically three methods of this class which will help us in creating Vendor Master…
1. MAINTAIN_DIRECT_INPUT
2. MAINTAIN
3. MAINTAIN_BAPI
Methods 2 and 3 are very similar i.e. both allows to create multiple vendors by calling the respective method (MAINTAIN_SINGLE method is called internally by looping at the Vendor data passed as parameters)…..however the only difference is in the export parameters.
MAINTAIN_BAPI acts very similar to a BAPI call wherein you get the return data of what was created along with comprehensive error messages.
MAINTAIN only provides us return messages stating whether the Vendor was created successfully or not.
The below example provides an overview of how MAINTAIN_BAPI can be used:
CLASS lcl_data DEFINITION.
PUBLIC SECTION.
METHODS: constructor
IMPORTING
i_ccode TYPE bukrs
i_ktokk TYPE ktokk
i_akont TYPE akont
i_name TYPE ad_name1,
create_vendor_data
EXPORTING
e_lifnr TYPE lifnr.PRIVATE SECTION.
METHODS: prepare_data
RETURNING value(re_flag) TYPE i.
* Data Declarations
DATA: gs_vmds_extern TYPE vmds_ei_main,
gs_succ_messages TYPE cvis_message,
gs_vmds_error TYPE vmds_ei_main,
gs_err_messages TYPE cvis_message,
gs_vmds_succ TYPE vmds_ei_main,
gv_ktokk TYPE ktokk,
gv_ccode TYPE bukrs,
gv_akont TYPE akont,
gv_name TYPE name1.
ENDCLASS. “lcl_data*———————————————————————-*
* CLASS lcl_data IMPLEMENTATION
*———————————————————————-*
*
*———————————————————————-*
CLASS lcl_data IMPLEMENTATION.METHOD constructor.
me->gv_ccode = i_ccode.
me->gv_ktokk = i_ktokk.
me->gv_akont = i_akont.
me->gv_name = i_name.
ENDMETHOD. “constructorMETHOD prepare_data.
* Local Data Declaration
DATA: lt_contacts TYPE vmds_ei_contacts_t,
ls_contacts TYPE vmds_ei_contacts,
lt_vendors TYPE vmds_ei_extern_t,
ls_vendors TYPE vmds_ei_extern,
ls_address TYPE cvis_ei_address1,
lt_company TYPE vmds_ei_company_t,
ls_company TYPE vmds_ei_company,
ls_company_data TYPE vmds_ei_vmd_company,
ls_purchas_data TYPE vmds_ei_vmd_purchasing,
lt_purchasing TYPE vmds_ei_purchasing_t,
ls_purchasing TYPE vmds_ei_purchasing,
lt_purch_func TYPE vmds_ei_functions_t,
ls_purch_func TYPE vmds_ei_functions,
ls_message TYPE cvis_message,
lv_contactid TYPE bapicontact_01-contact.* Clear the work area initially.
CLEAR gs_vmds_extern.* Set the creation flag for Vendor and obtain a Vendor Number.
* This is an optional step….you can also leave the vendor number as empty.
* If the Vendor Number is kept empty then MAINTAIN_BAPI would call this method
* internally and obtain a Vendor Number.
* This explicit call was required in our case, as Purchasing Data mandatory partner
* function of ordering party was supposed to be the same Vendor being created
CALL METHOD vmd_ei_api=>get_number
EXPORTING
iv_ktokk = gv_ktokk
IMPORTING
ev_lifnr = ls_vendors-header-object_instance-lifnr
es_error = ls_message.
ls_vendors-header-object_task = ‘I’. “Represents Insert or Create* Set the Name
ls_address-postal-data-name = gv_name. “Name of the Vendor
ls_address-postal-data-street = ‘Flat 101, ABS Road’.
ls_address-postal-data-postl_cod1 = ‘400062’.
ls_address-postal-data-region = ’13’.
ls_address-postal-data–country = ‘IN’.
ls_address-postal-data-sort1 = gv_name.
ls_address-postal-data-langu = sy-langu.
* For all the fields where value was provided, set the flag value also to be ‘X’
ls_address-postal-datax-name = ‘X’.
ls_address-postal-datax-street = ‘X’.
ls_address-postal-datax-postl_cod1 = ‘X’.
ls_address-postal-datax-region = ‘X’.
ls_address-postal-datax-sort1 = ‘X’.
ls_address-postal-datax-country = ‘X’.
ls_address-postal-datax-langu = ‘X’.
ls_address-task = ‘I’.* Set the Address for the Vendor
ls_vendors-central_data-address = ls_address.* Set Contact Person
REFRESH: lt_contacts[].
CLEAR ls_contacts.
ls_contacts-task = ‘I’. “Represents Creation of Contact person
ls_contacts-address_type_3-task = ‘I’. “Represents Creation of Address for CP
* Specify how many Contact Person numbers are to be obtained
* This will simply provide us a contact person number
* NOTE: If the note 1749700 is present in the system, then the contact person number can be left empty
CALL FUNCTION ‘BAPI_PARTNEREMPLOYEE_GETINTNUM’
EXPORTING
quantity = ‘1’
IMPORTING
contactid = lv_contactid.ls_contacts-data_key-parnr = lv_contactid. “Contact Person Number
* Set the Name for Contact person
ls_contacts-address_type_3-postal-data-fullname = ‘John Doe’.
ls_contacts-address_type_3-postal-data-firstname = ‘John’.
ls_contacts-address_type_3-postal-data-lastname = ‘Doe’.
APPEND ls_contacts TO lt_contacts.* Set the Contact Person details for the Vendor
ls_vendors-central_data-contact-contacts = lt_contacts[].* Set the Account Group
ls_vendors-central_data-central-data-ktokk = gv_ktokk.
ls_vendors-central_data-central-data-stcd1 = ‘VAT 1’.
ls_vendors-central_data-central-data-brsch = ’18’. “Industry Key
* Set the DATAX flags
ls_vendors-central_data-central-datax-ktokk = ‘X’.
ls_vendors-central_data-central-datax-stcd1 = ‘X’.
ls_vendors-central_data-central-datax-brsch = ‘X’.* Set the Company Code and GL Account
REFRESH: lt_company[].
CLEAR ls_company.
ls_company-task = ‘I’.
ls_company-data_key-bukrs = gv_ccode.
ls_company-data-akont = gv_akont. “Reconciliation Account
ls_company-data-zuawa = ‘018‘. “Sort Key
ls_company-data-fdgrv = ‘M1′. “Cash Management Group
ls_company-data-zterm = ‘0001’. “Payment Terms
ls_company-datax-akont = ‘X’.
ls_company-datax-zuawa = ‘X’.
ls_company-datax-fdgrv = ‘X’.
ls_company-datax-zterm = ‘X’.
APPEND ls_company TO lt_company.
ls_company_data-company = lt_company[].
ls_vendors-company_data = ls_company_data.* Set the Purchasing Data
ls_purchasing-task = ‘I’.
ls_purchasing-data_key-ekorg = ‘LU01’. “Purchasing Organization
ls_purchasing-data-kalsk = ’01’. “Schema Group, Vendor
ls_purchasing-data-webre = ‘X’. “GR Based Invoice Verification
ls_purchasing-datax-kalsk = ‘X’.
ls_purchasing-datax-webre = ‘X’.* Set the Partner function for Purchase Organization Data
* Ordering Address
REFRESH: lt_purchasing[],
lt_purch_func[].
CLEAR ls_purch_func.
ls_purch_func-task = ‘I’.
ls_purch_func-data_key-parvw = ‘BA’.
* We set the Vendor being created as “Ordering Address”
ls_purch_func-data-partner = ls_vendors-header-object_instance-lifnr.
ls_purch_func-datax-partner = ‘X’.
APPEND ls_purch_func TO lt_purch_func[].* Invoicing Party
CLEAR ls_purch_func.
ls_purch_func-task = ‘I’.
ls_purch_func-data_key-parvw = ‘RS’.
* We set the Vendor being created as “Invoicing Party”
ls_purch_func-data-partner = ls_vendors-header-object_instance-lifnr.
ls_purch_func-datax-partner = ‘X’.
APPEND ls_purch_func TO lt_purch_func[].* Vendor
CLEAR ls_purch_func.
ls_purch_func-task = ‘I’.
ls_purch_func-data_key-parvw = ‘LF’.
* We set the Vendor being created as “Vendor in Purchasing Partner Function”
ls_purch_func-data-partner = ls_vendors-header-object_instance-lifnr.
ls_purch_func-datax-partner = ‘X’.
APPEND ls_purch_func TO lt_purch_func[].* Set the Purchasing Data – Partner functions
ls_purchasing-functions-functions = lt_purch_func[].
APPEND ls_purchasing TO lt_purchasing.* Set the Purchasing Data
ls_purchas_data-purchasing = lt_purchasing[].
ls_vendors-purchasing_data = ls_purchas_data.
APPEND ls_vendors TO lt_vendors.* Set the Final Vendor Data based on which it has to be created
* Note if multiple vendors are to be created…please maintain multiple entries in LT_VENDORS
gs_vmds_extern-vendors = lt_vendors[].
ENDMETHOD. “prepare_dataMETHOD create_vendor_data.
* Local Data Declaration
DATA: lv_return TYPE i.* Prepare the data to be used for Vendor Creation
lv_return = me->prepare_data( ).* Do not proceed if the Vendor Data for creation was not prepared
IF lv_return IS NOT INITIAL.
EXIT.
ENDIF.* Initialize all the data
vmd_ei_api=>initialize( ).* Call the Method for creation of Vendor.
CALL METHOD vmd_ei_api=>maintain_bapi
EXPORTING
is_master_data = gs_vmds_extern
IMPORTING
es_master_data_correct = gs_vmds_succ
es_message_correct = gs_succ_messages
es_master_data_defective = gs_vmds_error
es_message_defective = gs_err_messages.IF gs_err_messages-is_error IS INITIAL.
COMMIT WORK.
* Set the Vendor Number to be returned
ENDIF.
ENDMETHOD. “create_vendor_data
ENDCLASS. “lcl_data IMPLEMENTATIONSELECTION-SCREEN BEGIN OF BLOCK tb1.
PARAMETERS: p_ccode TYPE bukrs,
p_akont TYPE akont,
p_ktokk TYPE ktokk,
p_name TYPE ad_name1.
SELECTION-SCREEN END OF BLOCK tb1.DATA: lo_data TYPE REF TO lcl_data,
gv_lifnr TYPE lifnr.START-OF-SELECTION.
* Create an instance of our class
CREATE OBJECT lo_data
EXPORTING
i_ccode = p_ccode
i_akont = p_akont
i_ktokk = p_ktokk
i_name = p_name.* Create Vendor and obtain the resultant error message and Vendor number
CALL METHOD lo_data->create_vendor_data
IMPORTING
e_lifnr = gv_lifnr.
NOTE: Most of the values have been hard coded…This is only a test program created for testing purpose.
Nice one….
Thanks.
code is not working, i want to insert the vendor details using this api.
What is the error that you receive?
Usually a bit of debugging resolves most of the issue….
Nice post! this gives a good understanding on how to use the maintain_bapi method which is very useful if you want to create and maintain vendor data. important field is the “TASK” field.
Thanks for this!
Very informative and better approach to use class & methods for Vendor creation instead of using procedural approach.
Nice one!
However, some customizing items are hard coded.
e.g) Industry key, Cash Management Group, Purchasing Organization.
It need to to be changed for each environment.
Hi,
Getting dump error while updating contact person address.
Without contact person vendor is created successfully.
Regards
goudham
Brother,
i am unable to add/insert/update contact person’s details.
could you help me….
i tried your code also no contact person is added,
you could also reply to my thread
Brilliant
Nice Work
Regards,
Hitesh Kamboj
Hello All,
I am facing a problem with updating vendor master data via (vmd_ei_api=>maintain_bapi).
Here Is my code:
DATA:
ls_vem TYPE vmds_ei_main,
lt_vendor TYPE vmds_ei_extern_t,
ls_vendor TYPE vmds_ei_extern.
* bapi data
DATA:
ls_master_data_correct TYPE vmds_ei_main,
ls_message_correct TYPE cvis_message,
ls_master_data_defective TYPE vmds_ei_main,
ls_message_defective TYPE cvis_message,
ls_return TYPE bapiret2.
ls_vendor-header-object_task = ‘U’.
ls_vendor-header-object_instance = ‘001003605’.
* address data in central_data
ls_vendor-central_data-address-task = ‘U’.
ls_vendor-central_data-address-postal-data-name = ‘Packaging Corp. of America – 01’.
ls_vendor-central_data-address-postal-datax-name = ‘X’.
************************************************ SET STRUCTURE.
APPEND ls_vendor TO lt_vendor.
ls_vem-vendors = lt_vendor.
************************************************ EXECUTING BAPI.
break hamziak.
* Initialize all the data
vmd_ei_api=>initialize( ).
CALL METHOD vmd_ei_api=>maintain_bapi
EXPORTING
is_master_data = ls_vem
IMPORTING
es_master_data_correct = ls_master_data_correct
es_message_correct = ls_message_correct
es_master_data_defective = ls_master_data_defective
es_message_defective = ls_message_defective.
break hamziak.
* Vendor was updated
IF ls_message_defective-is_error IS INITIAL.
COMMIT WORK.
ENDIF.
Please replay asap.
Regards Hamzi.
Hello All,
I Have used vmd_ei_api=>maintain_bapi to create a vendor but here I didn’t find any field to insert SWIFT code. So anyone helps me to add the SWIFT code of Bank details.
Regards Venu.