简体   繁体   中英

How can I update BUT050 & BUT051 tables?

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.

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM