Skip to Content
Technical Articles
Author's profile photo Geeta Bhavani Valluri

How to Create Business Partner and Assign Multiple Customer Roles By Using ODATA in S4 HANA

Introduction

I would like to explain about creation of the BP and assign customer roles using Class by step by step procedure.This blog Post is mainly useful for beginners.

Business Partners ( BP ) Business Partner can be created as a person, organization or a group in which we has some business interest.

The Business Partner is a cross application master record in SAP. It allows for one master record (one account number) to identify the people and/or companies with which we have some kind of business relationship. This could consist of one, or several, relationships.

Some examples of Business Partners are:

  • Customers
  • Vendors
  • Employees
  • Prospects
  • Agents
  • Borrowers
  • Multiple addresses for a single Business Partner
  • Time dependency of attributes
  • A single Business Partner as both a customer and a vendor

All the popular T codes such as XK01, MK01, XD01, FD01,etc have now become obsolete

In S/4 HANA, there is only 1 t code to create customers as well as vendors ,i.e, BP.

Maintaining with different roles in a business partner for supplier and customer.

Ideally, for a customer- it will be FLCUXX(FLCU00/FLCU01)

As below: FLCU00 will be accounting and FLCU01 will be sales.

About O Data: This service is used for build the services through URI in XML format.It is the back end development system for getting the data from SAP.It accesses through Restful API.

I need to create business partner with customer role in S/4 HANA use the class CL_MD_BP_MAINTAIN ,

Method CL_MD_BP_MAINTAIN=>VALIDATE_SINGLE is used to validate the data.

If data is validated then method CL_MD_BP_MAINTAIN=>MAINTAIN is called to create the BP.

Please follow the below steps  to create BP and assign customer roles.

Step: 1 Go to SEGW T-code and create new project.

 Click on Create button .The Popup will open.

Step:2 Give the ‘Project name’ and ‘Description’ ‘Package’ and click on Continue.

 

 

 

 

 

 

 

 

 

 

 

 

Step:3 Right click on Data Model ->create->Entity Type

Step: 4 Give the Entity type name and check Create Default Entity set and click on ‘Continue’.

Step: 5 Now Create properties for the above Entity Type and must Select the key for your structure .

Step:6  Click on ‘Generate runtime objects‘ button and the message shows generated successfully as below.

Note: we can see the created entity type and entity set.

Get:

Step:7.Now Goto Service implementation and right click on ‘Get entity(Read).

Note:We can create order only after getting the data through set.

Step: 8.Click on methods–>inherited–>Redefine and write the logic.

it’s time for Some Coding. implemented GET_ENTITY

Method BP_CREATIONSET_GET_ENTITY.

method BP_CREATIONSET_GET_ENTITY.
er_entity-partner = ' '.
er_entity-category = '2'.
er_entity-grouping = 'BP01'.
er_entity-customer = ' '.
er_entity-role    = 'FLCU01'.
er_entity-name1 = 'Airtel'.
er_entity-street = 'ABCDEFGH'.
er_entity-postl_cod1 = '123456'.
er_entity-city = 'XYZ'.
er_entity-country = 'IN'.
er_entity-region = 'TG'.
er_entity-langu = 'EN'.
er_entity-telephone = '1234567890'.
er_entity-fax = '1589568956'.
er_entity-email = 'Test@gmail.com'.
er_entity-customerrole = 'FLCU00'.
er_entity-salesorg = 'ZTM1'.
er_entity-distribution = 'TM'.
er_entity-division = 'TM'.
er_entity-currency = 'USD'.
er_entity-inco1 = 'CIF'.
er_entity-inco2 = 'Costs,Insurance&Freight'.
er_entity-tax = '1'.
er_entity-taxcategory = 'IN2'.
er_entity-taxnumber = '12345678956'.
er_entity-companycode = '6000'.
er_entity-recaccount = '0000031020'.
er_entity-payterm = '0001'.
endmethod.

CREATE:

Step: 9 Follow the same steps to Create entity.

 

Step: 10 Redefine the function and write the Logic for Create entity.

 

 .

 method BP_CREATIONSET_CREATE_ENTITY.

************************Data Declarations**************************
DATA:  ls_payload TYPE zcl_z_business_partner_mpc=>ts_bp_details,
ls_return_map TYPE mdg_bs_bp_msgmap_t,
lt_data       TYPE cvis_ei_extern_t,
lt_return     TYPE bapiretm,
ls_return     TYPE bapireti,
ls_retmsg     TYPE LINE OF bapiretct,
lv_text       TYPE string,
lt_errors     TYPE STANDARD TABLE OF bapiret2,
ls_errors     TYPE bapiret2,
ls_data_new   TYPE REF TO data.

DATA: ls_data     LIKE LINE OF lt_data,
ls_role     TYPE bus_ei_bupa_roles,
ls_relation TYPE burs_ei_extern,
ls_company  TYPE cmds_ei_company,
ls_addr     TYPE bus_ei_bupa_address,
lt_phone    TYPE bus_ei_bupa_telephone_t,
lt_fax      TYPE bus_ei_bupa_fax_t,
lt_email    TYPE bus_ei_bupa_smtp_t,
lt_tax      TYPE bus_ei_bupa_taxnumber_t,
lt_tax1     TYPE cmds_ei_tax_ind_t.

DATA: lv_guid    TYPE guid_32,
lv_pguid   TYPE but000-partner_guid,
lv_partner LIKE ls_data-partner-header-object_instance-bpartner.

DATA: lt_role_cat     TYPE fsbp_tb003a_tty,
lt_cvi_role_cat TYPE cvis_role_category_t,
ls_cvi_role_cat TYPE cvis_role_category.

DATA: ls_functions_st    TYPE cmds_ei_functions,
ls_functions_t     TYPE cmds_ei_functions_t,
ls_functions       TYPE cmds_ei_cmd_functions,
ls_sales_data_st   TYPE cmds_ei_sales,
ls_sales_data      TYPE cmds_ei_cmd_sales,
ls_customer        TYPE cmds_ei_extern,
ls_customers       TYPE cmds_ei_main,
ls_company_code_st TYPE cmds_ei_company,
ls_company_code    TYPE cmds_ei_cmd_company.

******************************Payload******************************
io_data_provider->read_entry_data( IMPORTING es_data = ls_payload ).

******************************Guid*********************************
CALL METHOD cl_system_uuid=>if_system_uuid_static~create_uuid_c32
RECEIVING
uuid = lv_guid.

******************************Create customer**********************
ls_data-partner-header-object_task = 'I'.
ls_data-partner-header-object_instance-bpartnerguid = lv_guid.

***************** Partner / Central data / common *****************
ls_data-partner-central_data-common-data-bp_control-category = ls_payload-category. "3group "2 Organization
ls_data-partner-central_data-common-data-bp_control-grouping = ls_payload-grouping. "Grouping
ls_data-partner-central_data-common-data-bp_organization-name1 = ls_payload-name1.
ls_data-partner-central_data-common-datax-bp_organization-name1 = abap_true.

*****************Partner / Central data / Address *****************
***-------------------Telephone number--------------------------***
APPEND INITIAL LINE TO  lt_phone ASSIGNING FIELD-SYMBOL(<ls_phone>).
<ls_phone>-contact-task = 'I'.
<ls_phone>-contact-data-telephone = ls_payload-telephone.
<ls_phone>-contact-data-country  = 'IN'.
<ls_phone>-contact-data-countryiso = '40'.
<ls_phone>-contact-data-r_3_user = ' '.
<ls_phone>-contact-data-consnumber = '001'.

<ls_phone>-contact-datax-country = abap_true.
<ls_phone>-contact-datax-telephone = abap_true.
<ls_phone>-contact-datax-countryiso = abap_true.
<ls_phone>-contact-datax-r_3_user = abap_true.
<ls_phone>-contact-datax-consnumber = abap_true.
<ls_phone>-currently_valid = abap_true.

***---------------------- fax number------------------------***
APPEND INITIAL LINE TO lt_fax ASSIGNING FIELD-SYMBOL(<ls_fax>).
<ls_fax>-contact-task = 'I'.
<ls_fax>-contact-data-fax  = ls_payload-fax.
<ls_fax>-contact-data-country  = 'IN'.
<ls_fax>-contact-data-countryiso = '40'.
<ls_fax>-contact-data-r_3_user = 'X'.
<ls_fax>-contact-data-consnumber = '001'.

<ls_fax>-contact-datax-country = abap_true.
<ls_fax>-contact-datax-fax = abap_true.
<ls_fax>-contact-datax-countryiso = abap_true.
<ls_fax>-contact-datax-r_3_user = abap_true.
<ls_fax>-contact-datax-consnumber = abap_true.
<ls_fax>-currently_valid = abap_true.

***--------------------------Email------------------------***
APPEND INITIAL LINE TO lt_email ASSIGNING FIELD-SYMBOL(<ls_email>).
<ls_email>-contact-task = 'I'.
<ls_email>-contact-data-e_mail = ls_payload-email.
<ls_email>-contact-data-consnumber = '001'.

<ls_email>-contact-datax-e_mail = abap_true.
<ls_email>-contact-datax-consnumber = abap_true.
<ls_email>-currently_valid = abap_true.

ls_addr-task = 'I'.
ls_addr-data_key-operation = 'XXDFLT'.
ls_addr-data-postal-data-city = ls_payload-city.
ls_addr-data-postal-data-postl_cod1 = ls_payload-postl_cod1.
ls_addr-data-postal-data-street = ls_payload-street.
ls_addr-data-postal-data-country = ls_payload-country.
ls_addr-data-postal-data-countryiso = '40'.
ls_addr-data-postal-data-region = ls_payload-region.
ls_addr-data-postal-data-langu = ls_payload-langu.
ls_addr-data-communication-phone-phone = lt_phone.
ls_addr-data-communication-fax-fax = lt_fax.
ls_addr-data-communication-smtp-smtp = lt_email.

ls_addr-data-postal-datax-city = abap_true.
ls_addr-data-postal-datax-postl_cod1 = abap_true.
ls_addr-data-postal-datax-street = abap_true.
ls_addr-data-postal-datax-country = abap_true.
ls_addr-data-postal-datax-countryiso = abap_true.
ls_addr-data-postal-datax-region = abap_true.
ls_addr-data-postal-datax-langu = abap_true.
ls_addr-currently_valid = abap_true.

APPEND ls_addr TO ls_data-partner-central_data-address-addresses.

**--------------------------Tax----------------------------***
APPEND INITIAL LINE TO lt_tax ASSIGNING FIELD-SYMBOL(<ls_tax>).
<ls_tax>-task = 'I'.
<ls_tax>-data_key-taxtype = ls_payload-taxcategory. "'IN2'.
<ls_tax>-data_key-taxnumxl = ls_payload-taxnumber.  "'12345678956'.

ls_data-partner-central_data-taxnumber-taxnumbers = lt_tax.

********************* Partner / Central data / role****************
ls_role-task = 'I'.
ls_role-data_key = 'FLCU01'.
ls_role-data-rolecategory = ls_payload-role.  "'FLCU01'.
ls_role-data-valid_from = sy-datum.
ls_role-data-valid_to = '99991231'.
ls_role-currently_valid = abap_true.

ls_role-datax-valid_from = abap_true.
ls_role-datax-valid_to = abap_true.

APPEND ls_role TO ls_data-partner-central_data-role-roles.
ls_data-partner-central_data-role-current_state = abap_true.

*********************Partner / Central data / role*****************
ls_role-task = 'I'.
ls_role-data_key = 'FLCU00'.
ls_role-data-rolecategory = ls_payload-customerrole.  "'FLCU00'.
ls_role-data-valid_from = sy-datum.
ls_role-data-valid_to = '99991231'.
ls_role-currently_valid = abap_true.

ls_role-datax-valid_from = abap_true.
ls_role-datax-valid_to = abap_true.

APPEND ls_role TO ls_data-partner-central_data-role-roles.
ls_data-partner-central_data-role-current_state = abap_true.

*******************Partner relation / header **********************
ls_relation-header-object_instance-partner1-identificationcategory = 'FLCU01'.
APPEND ls_relation TO ls_data-partner_relation.
ls_relation-header-object_task = 'I'.

******************** Customer / Company data **********************

ls_company-task = 'I'.
ls_company-data_key = ls_payload-companycode.  "'6000' . " company code
ls_company-data-akont = ls_payload-recaccount.  "'0000031020'.
ls_company-data-zterm = ls_payload-payterm.  "'0001'. " terms of payment
ls_company-datax-zterm = 'X'.

ls_company-datax-akont = abap_true.
ls_company-datax-zterm = abap_true.
APPEND ls_company TO ls_data-customer-company_data-company.

************************* Customer / Header ***********************
ls_data-customer-header-object_task = 'I'.
ls_data-ensure_create-create_customer = abap_true.

ls_cvi_role_cat-category = 'FLCU01'.
APPEND ls_cvi_role_cat TO lt_cvi_role_cat.

*************SALES ORG AND DIST & DIVISION MANDATORY FIELDS********

ls_sales_data_st-task = 'I'.
ls_sales_data_st-data_key-vkorg = ls_payload-salesorg.   "''ZTM1'.
ls_sales_data_st-data_key-vtweg = ls_payload-distribution.  "'TM'.
ls_sales_data_st-data_key-spart = ls_payload-division.  "'TM'.
ls_sales_data_st-data-waers = ls_payload-currency.  "'USD'.
ls_sales_data_st-data-inco1 = ls_payload-inco1.  "'CIF'.
ls_sales_data_st-data-inco2 = ls_payload-inco2.  "'Costs,Insurance&Freight'.
ls_sales_data_st-data-kzazu = 'X'.

ls_sales_data_st-datax-waers = abap_true.
ls_sales_data_st-datax-inco1 = abap_true.
ls_sales_data_st-datax-inco2 = abap_true.
ls_sales_data_st-datax-kzazu = abap_true.

APPEND ls_sales_data_st TO ls_sales_data-sales.
ls_data-customer-sales_data = ls_sales_data.

********************** GL Account ledger *************************
ls_company_code_st-task = 'I'.
APPEND ls_company_code_st TO ls_company_code-company.

**********************Account Group Assignemnt ******************

APPEND INITIAL LINE TO lt_tax1 ASSIGNING FIELD-SYMBOL(<fs_tax1>).
<fs_tax1>-task = 'I'.
<fs_tax1>-data_key-aland = 'US'.
<fs_tax1>-data_key-tatyp = 'MWST'.
<fs_tax1>-data-taxkd = ls_payload-tax.  "'1'.
<fs_tax1>-datax-taxkd = abap_true.
ls_data-customer-central_data-tax_ind-tax_ind = lt_tax1.

ls_customer-central_data-central-data-ktokd = 'CU01'.
ls_customer-header-object_instance-kunnr = ' '.
ls_customer-header-object_task = 'I'.
ls_customer-company_data = ls_company_code.
APPEND ls_customer TO ls_customers-customers.

*********************** End of sales data *************************

*****************Finally fill the main data structure**************

APPEND ls_data TO lt_data.
************************** validating BP data ********************

CALL METHOD cl_md_bp_maintain=>validate_single
EXPORTING
i_data        = ls_data "lt_data
IMPORTING
et_return_map = ls_return_map. "lt_return.

*****************************Creating BP **************************
IF ls_return_map IS  INITIAL.

CALL METHOD cl_md_bp_maintain=>maintain
EXPORTING
i_data   = lt_data
IMPORTING
e_return = lt_return.

***************************** Commit BAPI *************************
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'.                " Use of Command `COMMIT AND WAIT`
ENDIF.

*** *********Partner Number
SELECT partner,crdat FROM but000
INTO TABLE @DATA(lt_but000)
WHERE NAME_ORG1 = @ls_payload-name1
AND crdat = @sy-datum.
SORT lt_but000 DESCENDING BY partner.
READ TABLE lt_but000 INTO DATA(ls_but000) INDEX 1.

************To get  the Customer number
SELECT  kunnr,erdat FROM kna1
INTO TABLE @DATA(lt_kna1)
WHERE name1 =  @ls_payload-name1
AND    erdat  =  @sy-datum.
SORT lt_kna1 DESCENDING BY kunnr.
READ TABLE lt_kna1 INTO DATA(ls_kna1) INDEX 1.

****payload
IF sy-subrc = 0.
er_entity-partner =  ls_but000-partner.
ENDIF.
er_entity-category = ls_payload-category.
er_entity-grouping = ls_payload-grouping.
IF sy-subrc = 0.
er_entity-customer =  ls_kna1-kunnr.
ENDIF.
er_entity-role  = ls_payload-role.
er_entity-name1 = ls_payload-name1.
er_entity-street = ls_payload-street.
er_entity-postl_cod1 = ls_payload-postl_cod1.
er_entity-city = ls_payload-city.
er_entity-country = ls_payload-country.
er_entity-region = ls_payload-region.
er_entity-langu = ls_payload-langu.
er_entity-telephone = ls_payload-telephone.
er_entity-fax = ls_payload-fax.
er_entity-email = ls_payload-email.
er_entity-customerrole = ls_payload-customerrole.
er_entity-salesorg = ls_payload-salesorg.
er_entity-distribution = ls_payload-distribution.
er_entity-division = ls_payload-division.
er_entity-currency = ls_payload-currency.
er_entity-inco1 = ls_payload-inco1.
er_entity-inco2 = ls_payload-inco2.
er_entity-tax = ls_payload-tax.
er_entity-taxcategory = ls_payload-taxcategory.
er_entity-taxnumber = ls_payload-taxnumber.
er_entity-companycode = ls_payload-companycode.
er_entity-recaccount = ls_payload-recaccount.
er_entity-payterm = ls_payload-payterm.

ENDMETHOD

Save and Activate the entity sets.

Step:11 Add and Maintain the service:

Go for the t-code ‘ /IWFND/MAINT_SERVICE‘ to add the service.

Click on ‘Add service‘ to add service.

 

Step:12  Give system name and click on ‘Get service‘ and the project will be found and select project click on ‘Add selected service‘.It will automatically maintained the service.

Step: 13  After it will shows technical service with some details and Click on Continue button.

Step: 14 Go back to maintain services and select the project and ‘Load Metadata‘ & Click on ‘Sap Gateway Client‘.

Step: 15 .It will shows the HTTP Request with Request URI and select the entity set name as below.

Step: 16 Give the Category number  for get the details by clicking on ‘Get‘ radio button in the request.

Execute the Request URI.

We will get the success message (status code:200) the Partner details will be displayed.

Click on ‘Use as Request‘ and change the data.

Step:17 After change the data click on ‘post‘ radio button for create.

Execute. The new Business Partner  number is ‘0060000520‘ created with success message

(Status code: ‘201‘) as below.

Step:18

We can check the Business Partner by going T-code BP.

You can easily identify with roles, what are you dealing with:

The base role should be a business partner- 000000- In general, you need to do nothing here, it will automatically be created with other roles by default.

Let us see other roles here for customer integration:

  1. Business Partner -000000
  2. Customer- FLCUXX
    1. Customer Account
    2. Customer sales.

You can easily identify in below screen:

Customer Role FLCU01  for Sales data.

Customer Role FLCU00 for Financial Accounting.

 

Conclusion:    

I hope this blog Post helps to create BP and assign multiple customer roles to it.

Assigned Tags

      9 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Niall Brennan
      Niall Brennan

      This was perfect for me. Do you know if I can create a contact and at the same time assign it directly to a pre-existing organization -or do I need to create the contact first and then in a separate step assign it?

      Author's profile photo Alina Matei
      Alina Matei

      there is one question, how is the class defined zcl_z_business_partner_mpc?

      Author's profile photo Richard Koval
      Richard Koval

      We are receiving the error 'Internal error when calling operation module BUA_CHECK_ADDRESS_VALIDITY_ALL; a check table is missing' from the method cl_md_bp_maintain=>validate_single. Has anyone else run into this and found a solution?

      Author's profile photo Muhammed Abdelaziz
      Muhammed Abdelaziz

      check this SAP note :
      3159451 - CL_MD_BP_MAINTAIN - Internal error when calling operation module BUA_CHECK_ADDRESS_VALIDITY_ALL; a check table is missing

      Author's profile photo Arno van Damme
      Arno van Damme

      Hi, interesting Blog you have made here. I was wondering if you also can create a supplier for multiple company codes at once?

      Author's profile photo Ankush Thareja
      Ankush Thareja

      Hello,

      Yes, you can create a supplier for multiple company codes at once. The API CL_MD_BP_MAINTAIN supports this feature.

      Regards,

      Ankush

      Author's profile photo Alejandro Gongora Fuentes
      Alejandro Gongora Fuentes

      Hi, thank you for this post, it was very helpful. It is possible that you can share how to handle the BP's and Customer update scenario, in the images I can see a method called BP_CREATIONSET_UPDATE_ENTITY, I assume that it must be used to update data from a BP/Customer.

      Thanks in advance for your help.

       

       

       

       

      Author's profile photo Miguel Motta
      Miguel Motta

      Hi,

      Suggestion to retrieve the partner code without doing select in but table.
      Use function module BUPA_NUMBERS_GET passing parameter IV_PARTNER_GUID = LV_GUID.

      Regards!

      Author's profile photo Prasenjit Bist
      Prasenjit Bist

      I don't understand why I would like to take so much pain when there is already an API available API_BUSINESS_PARTNER. Use it simply rather than creating an ODATA project on own.

      Is there something very specific going on here?