1

I have the following scenario: I am using BAPI BAPI_BUPR_RELATIONSHIP_CHANGE to change validuntildate. (BUT050-DATE_TO / BUT051-DATE_TO). But I also need to update field BUT051-PAFKT and a custom field in BUT050 (lets call it ZZFIELD). I do this by updating BUT050 / BUT051 from internal tables.

At the end, if I write COMMIT WORK or call FM BAPI_TRANSACTION_COMMIT, only the fields from BAPI_BUPR_RELATIONSHIP_CHANGE will be updated. If I do not write anything at the end, only the field from UPDATE FROM TABLE will be updated.

How can I update all my fields? Are there any BAPI that can allow me to modify BUT051-PAFKT and custom fields from BUT050 ?

Sample code for testing:

DATA: lt_return   TYPE bapiret2_t,
      lv_kunnr    TYPE kunnr VALUE '111',
      lv_partner  TYPE bu_partner VALUE '222',
      lv_rel_cat  TYPE bu_reltyp VALUE 'BUR001',
      lv_new_date TYPE sy-datum VALUE '20300101',
      lt_but051   TYPE TABLE OF but051.

CALL FUNCTION 'BAPI_BUPR_RELATIONSHIP_CHANGE'
      EXPORTING
        businesspartner1               = lv_kunnr
        businesspartner2               = lv_partner
        relationshipcategory           = lv_rel_cat
        validfromdate                  = sy-datum
        validuntildate                 = sy-datum
        validuntildatenew              = lv_new_date
        datetox                        = abap_true
     TABLES
       RETURN                         = lt_return.

SELECT *
  FROM but051
  INTO TABLE lt_but051
    WHERE partner1 = lv_kunnr
      AND partner2 = lv_partner
      AND reltyp   = lv_rel_cat.

LOOP AT lt_but051 ASSIGNING FIELD-SYMBOL(<ls_but051>).
  <ls_but051>-pafkt = '0003'.
ENDLOOP.

UPDATE but051 FROM TABLE lt_but051.

COMMIT WORK.
Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
Ovidiu Pocnet
  • 579
  • 12
  • 32
  • 1
    I guess you experience an asynchronous update which makes you think that the BAPI doesn't update because you look at the tables too fast. You may wait for the end of the asynchronous update task by calling `BAPI_TRANSACTION_COMMIT` with argument `WAIT = 'X'` (NB: as rule-of-thumb you must use this function module to commit the updates if you use a BAPI, it includes `COMMIT WORK`), or if you need to make everything synchronous you may use `SET UPDATE TASK LOCAL` before calling the BAPI. – Sandra Rossi Dec 21 '21 at 18:21
  • You don't need a BAPI to manage your own custom fields in standard tables, SAP won't check their values, a simple `UPDATE but051 SET zzfield = 'value'` is sufficient. Note that `BAPI_BUPR_RELATIONSHIP_CHANGE` is not released, so you shouldn't use it (SAP support won't help in case of error due to this use). – Sandra Rossi Dec 22 '21 at 14:46
  • @SandraRossi regarding the first comment: the SELECT is not dependent on the BAPI being ready, it is just the fact that if I use COMMIT only the BAPI will work and if I do not use COMMIT, only the UPDATE from internal table will work. Regarding the second comment, I should not use BAPI_BUPR_RELATIONSHIP_CHANGE not even for updating DATE_TO fields ? It do not understand what it means, the fact that it is not released. – Ovidiu Pocnet Dec 23 '21 at 14:19
  • 1
    When I say "you shouldn't", of course it's up to you. You can see in the note [577453 - Using BAPI BAPI_DELIVERYPROCESSING_EXEC](https://launchpad.support.sap.com/#/notes/577453/E), and in many other ones, that "The interface is not fixed and may be changed in new releases (these changes may be incompatible)", "SAP does not guarantee that this BAPI will work in all scenarios without errors", "the same restrictions apply as for function modules that have not been released", etc. – Sandra Rossi Dec 23 '21 at 16:14

1 Answers1

3

Try this (or its wrapper BAPI_BUPR_CONTP_CHANGE):

DATA: ls_person                    TYPE bapibus1006_central_person.
DATA: ls_person_x                  TYPE bapibus1006_central_person_x.
DATA: ls_central                   TYPE bapibus1006_central.
DATA: ls_central_x                 TYPE bapibus1006_central_x.
DATA: lt_return                    TYPE bapiret2_t.

is_data-function = '0001'. "<-- your PAFKT
is_data_x-function = abap_true.

* changes of the central data
CALL FUNCTION 'BUPR_CONTP_CHANGE'
  EXPORTING
    iv_partner                     = is_data-partner1
*   IV_PARTNER_GUID                =
    iv_contactperson               = is_data-partner2
*   IV_CONTACTPERSON_GUID          =
*   IV_DATE_FROM                   =
*   IV_DATE_TO                     =
*   IV_DEFAULTRELATIONSHIP         =
*   IV_DEFAULTRELATIONSHIP_X       =
    is_data                        = is_data-data
    is_data_x                      = is_data_x-central
*   IV_TESTRUN                     = ' '
  TABLES
    et_return                      = lt_return.

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
  EXPORTING
    WAIT = abap_true.

Also check my answer about updating relations and the corresponding note.

Regarding the custom field in BUT050, you can't just add a new field and update it, you need to change the BOL model.

Suncatcher
  • 10,355
  • 10
  • 52
  • 90