cancel
Showing results for 
Search instead for 
Did you mean: 

A function module to create BP employee in CRM

Former Member
0 Kudos

Hello,

I would like to create automatic user creation in our system.

The user creation now is manually done in the following way:

Creation of SAP user with the SU01 transaction

Creation of a BP person with the 'employee' rolled and assigning the previously created SAP user to the BP.

And another few various seeds.

I was able to create a SAP user. But creation the BP does not work.

I tried using  the function module 'BAPI_BUPA_CREATE_FROM_DATA' it does return

me a BP number which does not exist anywhere (I did run 'BAPI_TRANSACTION_COMMIT')

I wasnt able to find the BP in the 'BP transaction.

I don't if its the right function to create a BP, but it doesnt seem to work.

If its not the way I would like an alternative way to create BP from ABAP which result in the same as I would create from the BP transaction.

Thank you,

Alex.

Accepted Solutions (0)

Answers (3)

Answers (3)

Former Member
0 Kudos

Hi,

Also you could try using BAPI_USER_CREATE1 to create a user and then assign the role with BAPI_USER_PROFILES_ASSIGN.

Br

Former Member
0 Kudos

Hi Sergey

I hope this will help you..

bit hard coded as per our requirement,

DATA : l_wa_input       TYPE zumrdt_bpcreate_req_sap_1320_r,
          l_wa_return      TYPE zumrdt_bpcreate_resp_sap_1320,
          l_wa_centraldate TYPE bapibus1006_central,
          l_wa_person      TYPE bapibus1006_central_person,
          l_wa_address     TYPE bapibus1006_address,
          l_bp             TYPE bapibus1006_head-bpartner,
          li_return        TYPE TABLE OF bapiret2,
          l_wa_error       TYPE bapiret2,
          l_v_guid         TYPE bu_partner_guid,
          li_email         TYPE STANDARD TABLE OF bapiadsmtp,
          l_wa_email       TYPE bapiadsmtp.

   IF x_input[] IS NOT INITIAL .
     SORT x_input[].
     DELETE ADJACENT DUPLICATES FROM x_input COMPARING ALL FIELDS .
     READ TABLE x_input[] INTO l_wa_input INDEX 1 .
     IF sy-subrc EQ 0.
       IF l_wa_input-name_first IS INITIAL .
         RAISE first_name_missing.
       ENDIF.

       IF l_wa_input-name_last IS INITIAL .
         RAISE last_name_missing.
       ENDIF.

       IF l_wa_input-userid IS INITIAL .
         RAISE userid_missing.
       ENDIF.
     ENDIF.

     DATA : lv_bp_guid TYPE bu_partner_guid.

*   Start processing the data
     LOOP AT x_input[] INTO l_wa_input.
       CLEAR : l_wa_centraldate, l_wa_person, l_wa_address, l_bp, li_return.

       l_wa_person-firstname = l_wa_input-name_first .
       l_wa_person-lastname = l_wa_input-name_last .

       l_wa_address-country = 'GB'.

       CLEAR lv_bp_guid.
       CALL FUNCTION 'CRM_CENTRALPERSON_GET'
         EXPORTING
           iv_username         = l_wa_input-userid
         IMPORTING
           ev_bu_partner_guid  = lv_bp_guid
         EXCEPTIONS
           no_central_person   = 1
           no_business_partner = 2
           no_id               = 3
           OTHERS              = 4.

       IF lv_bp_guid IS INITIAL.

         CLEAR : l_wa_email.
         REFRESH : li_email[].
         l_wa_email-e_mail = x_email.
         APPEND l_wa_email TO li_email.

         CALL FUNCTION 'BAPI_BUPA_CREATE_FROM_DATA'
           EXPORTING
             partnercategory   = '1'
             partnergroup      = 'Z003'
             centraldata       = l_wa_centraldate
             centraldataperson = l_wa_person
             addressdata       = l_wa_address
           IMPORTING
             businesspartner   = l_bp
           TABLES
             return            = li_return
             e_maildata        = li_email.
         IF l_bp IS NOT INITIAL .

*         Assign Business Role to created BP
           CALL FUNCTION 'BAPI_BUPA_ROLE_ADD'
             EXPORTING
               businesspartner     = l_bp
               businesspartnerrole = 'BUP003'.

           CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
             EXPORTING
               wait = 'X'.

*         Get BP Guid after is save into DB
           SELECT SINGLE partner_guid FROM but000 INTO l_v_guid  WHERE partner = l_bp.

           IF sy-subrc = 0.
*           If BP saved successfully, call FM to update User ID
             CALL FUNCTION 'CRM_BUPA_CREATECENTRALPERSON'
               EXPORTING
                 iv_bu_partner_guid = l_v_guid
                 iv_user_id         = l_wa_input-userid.
           ENDIF.

           l_wa_return-subrc = 0.
           l_wa_return-message = 'BP Created Successfully'.
           l_wa_return-message_v1 = l_bp.
           APPEND l_wa_return TO xyt_return.
           CLEAR l_wa_return .
         ELSE.
           l_wa_return-subrc = 1.
           CLEAR l_wa_error.
           READ TABLE li_return INTO l_wa_error WITH KEY type = 'E'.
           IF sy-subrc EQ 0 .
             l_wa_return-message = l_wa_error-message..
             l_wa_return-message_v1 = l_wa_error-message_v1.
           ELSE.
             l_wa_return-message = 'BP is not Created Successfully'.
           ENDIF.
           APPEND l_wa_return TO xyt_return.
           CLEAR l_wa_return .
         ENDIF.
       ENDIF.
     ENDLOOP.

   ENDIF.

ENDFUNCTION.

Former Member
0 Kudos

Hey Sergey,

the following function module should do what you want...

COM_BPUS_CONTACTPERSON_CREATE

And afterwards the commit...

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.

Or in case of an error...

CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.

The address data can be read by 'BAPI_BUPA_ADDRESS_GETDETAIL' and created by 'BAPI_BUPA_ADDRESS_ADD' or changed by 'BAPI_BUPA_ADDRESS_CHANGE'.

Best regards.

Ben