Skip to Content
0
Former Member
Apr 09, 2014 at 09:11 AM

Create relationship in BAdI PARTNER_UPDATE

447 Views

Hello together,

i have a little problem with the BADI PARTNER_UPDATE. Maybe anybody has a good idea to solve that issue.

Business case: If a business partner will be archived we delete all contact person relationships and create for each contact a new relationship called "Archived contact". Until now, we do this in the Web-UI during the EH_ONSAVE. But in the meanwhile we also have a mobile App. So we would like to do that in a more general way. They idea was to implement this feature in the BAdI PARTNER_UPDATE

Problem: As you can see in my coding i try to create this new relationship in the method CHANGE_BEFORE_UPDATE:

CONSTANTS: lc_contact TYPE bu_reltyp VALUE 'BUR001', "Contact
lc_arch_contact TYPE bu_reltyp VALUE 'ZBURAR'. "Archived contact
DATA:
lt_but000_new TYPE TABLE OF but000,
lt_but000_old TYPE TABLE OF but000,
lt_relationships TYPE TABLE OF bapibus1006_relations,
lt_return TYPE TABLE OF bapiret2.

DATA:
ls_but000_new LIKE LINE OF lt_but000_new,
ls_but000_old LIKE LINE OF lt_but000_old,
ls_contact_person TYPE bapibus1006_relations,
ls_return TYPE bapiret2.

CALL FUNCTION 'BUPA_GENERAL_CALLBACK'
TABLES
et_but000_new = lt_but000_new
et_but000_old = lt_but000_old.

READ TABLE lt_but000_new INTO ls_but000_new INDEX 1.
CHECK sy-subrc EQ 0.
READ TABLE lt_but000_old INTO ls_but000_old INDEX 1.
CHECK sy-subrc EQ 0.

IF ls_but000_new-xdele = ls_but000_old-xdele OR ls_but000_new-xdele = abap_false.
RETURN.
ENDIF.

* Get all contacts
CALL FUNCTION 'BAPI_BUPA_RELATIONSHIPS_GET'
EXPORTING
businesspartner = ls_but000_new-partner
TABLES
relationships = lt_relationships
return = lt_return.

LOOP AT lt_return INTO ls_return WHERE type CA 'AXE'.
RETURN.
ENDLOOP.
CLEAR lt_return.

LOOP AT lt_relationships INTO ls_contact_person WHERE relationshipcategory = lc_contact.
CALL FUNCTION 'BUPR_RELATIONSHIP_CREATE'
EXPORTING
iv_partner_1 = ls_contact_person-partner1
* IV_PARTNER_1_GUID =
iv_partner_2 = ls_contact_person-partner2
* IV_PARTNER_2_GUID =
iv_relationship = lc_arch_contact
* iv_relationtype = 'BUP001'
iv_date_from = sy-datlo
iv_date_to = '99991231'
* IV_DIFFERENTIATION_TYPE_VALUE =
* iv_testrun = ' '
iv_x_save = ' '
* IV_XDFREL =
TABLES
et_return = lt_return.
ENDLOOP.

But if i run this coding nothing happens. I also tried the function module BAPI_BUPR_RELATIONSHIP_CREATE but this FM causes an PERFORM ON COMMIT: NESTED_PERFORM_ON_COMMIT.

That seams not logical for me. Because if i'm "in the middle of a committ", why doesn't the system creates the relationship?

I'm thankful for any ideas/suggestions.

Best regards,

Sascha