cancel
Showing results for 
Search instead for 
Did you mean: 

BAPI_OUTB_DELIVERY_CHANGE to Change a Partner Address

amy_king
Active Contributor
0 Kudos

Hi,

I'm trying to use BAPI_OUTB_DELIVERY_CHANGE to change the address details of a partner in an existing outbound delivery but I've not had success. I wonder if anyone has had success using this BAPI to change a partner address. I'd like to pass in the address details to the BAPI, e.g., NAME, CITY, STREET, etc., without providing an existing ADDRESSNUMBER. I'd like to pass in the address details and let the system create a new ADRC address and attach the new address to the outbound delivery.

In addition to the code below, I've also tried passing in the header_partner table with a record that indicated a manual_addr entry, but didn't have any luck with that approach either. If anyone has achieved a partner address change using this BAPI or by some other approach, I'd be interested to know your solution.

  
  DATA ls_header         TYPE bapiobdlvhdrchg.
  DATA ls_header_control TYPE bapiobdlvhdrctrlchg.
  DATA ls_partner_addr   TYPE bapidlvpartnaddrchg.
  DATA lt_partner_addr   TYPE STANDARD TABLE OF bapidlvpartnaddrchg.
  DATA lt_return         TYPE bapiret2_t.

  ls_header-deliv_numb         = vbeln.
  ls_header_control-deliv_numb = vbeln.

  ls_partner_addr-upd_mode_adr = 'U'. " create or update
*  ls_partner_addr-addr_no            " left blank
  ls_partner_addr-name         = ls_ship_to-name1.
  ls_partner_addr-name_2       = ls_ship_to-name2.
  ls_partner_addr-city         = ls_ship_to-city1.
  ls_partner_addr-postl_cod1   = ls_ship_to-post_code1.
  ls_partner_addr-street       = ls_ship_to-street.
  ls_partner_addr-str_suppl2   = ls_ship_to-str_suppl2.
  ls_partner_addr-location     = ls_ship_to-location.
  ls_partner_addr-country      = ls_ship_to-country.
  ls_partner_addr-region       = ls_ship_to-region.
  ls_partner_addr-tel1_numbr   = ls_ship_to-tel_number.   

  APPEND ls_partner_addr TO lt_partner_addr.   

  CALL FUNCTION 'BAPI_OUTB_DELIVERY_CHANGE'     
    EXPORTING       
      header_data              = ls_header       
      header_control           = ls_header_control       
      delivery                 = vbeln     
    TABLES 
*  header_partner              = lt_partner      
      header_partner_addr      = lt_partner_addr       
      return                   = lt_return.   

  COMMIT WORK.

Cheers,

Amy

Accepted Solutions (1)

Accepted Solutions (1)

marcin_milczynski
Contributor
0 Kudos

Hi Amy,

It is not possible, as during processing the system checks address number in form partner_address_chg_fill, include LV50IF02:

FORM partner_address_chg_fill
      TABLES   it_header_partner_addr STRUCTURE bapidlvpartnaddrchg
      USING    if_address_no          LIKE      bapidlvpartner-address_no
      CHANGING cs_partner             STRUCTURE shp_partner_update.
   DATA LF_MSG. "#EC NEEDED

  CHECK NOT if_address_no IS INITIAL.
   READ TABLE it_header_partner_addr
        WITH KEY addr_no = if_address_no BINARY SEARCH.
   CHECK sy-subrc = 0.
   cs_partner-adrnr = it_header_partner_addr-addr_no.
   cs_partner-anred = it_header_partner_addr-formofaddr.
   cs_partner-name1 = it_header_partner_addr-name.
   cs_partner-name2 = it_header_partner_addr-name_2.
   cs_partner-name3 = it_header_partner_addr-name_3.
   cs_partner-name4 = it_header_partner_addr-name_4.
   cs_partner-ort01 = it_header_partner_addr-city.
   cs_partner-ort02 = it_header_partner_addr-district.
   cs_partner-pstlz = it_header_partner_addr-postl_cod1.
   cs_partner-pstl2 = it_header_partner_addr-postl_cod2.
   cs_partner-pfach = it_header_partner_addr-po_box.
   cs_partner-pfort = it_header_partner_addr-po_box_cit.
   cs_partner-stras = it_header_partner_addr-street.
   cs_partner-hausn = it_header_partner_addr-house_no.
   cs_partner-regio = it_header_partner_addr-region.
   cs_partner-telf1 = it_header_partner_addr-tel1_numbr.
   cs_partner-telfx = it_header_partner_addr-fax_number.
   cs_partner-lzone = it_header_partner_addr-transpzone.
   cs_partner-txjcd = it_header_partner_addr-taxjurcode.

   IF NOT it_header_partner_addr-langu_iso IS INITIAL.
     CALL FUNCTION 'LANGUAGE_CODE_ISO_TO_SAP'
       EXPORTING
         iso_code  = it_header_partner_addr-langu_iso
       IMPORTING
         sap_code  = cs_partner-spras
       EXCEPTIONS
         not_found = 1
         OTHERS    = 2.
     IF sy-subrc <> 0.
       MESSAGE a549(b1) WITH it_header_partner_addr-langu_iso
                             'LANGU_ISO'
                        INTO lf_msg.
       LCL_MESSAGE=>ADD( if_param = 'HEADER_PARTNER_ADDR'
                         if_field = 'LANGU_ISO' ).
     ENDIF.
   ELSE.
     CLEAR cs_partner-spras.
   ENDIF.
   IF NOT it_header_partner_addr-country IS INITIAL.
     MOVE it_header_partner_addr-country TO cs_partner-land1.
   ELSEIF it_header_partner_addr-countryiso IS INITIAL.
     CLEAR cs_partner-land1.
   ELSE.
     CALL FUNCTION 'COUNTRY_CODE_ISO_TO_SAP'
       EXPORTING
         iso_code  = it_header_partner_addr-countryiso
       IMPORTING
         sap_code  = cs_partner-land1
       EXCEPTIONS
         not_found = 1
         OTHERS    = 2.
     IF sy-subrc <> 0.
       MESSAGE a549(b1) WITH it_header_partner_addr-countryiso
                             'COUNTRYISO'
                        INTO lf_msg.
       LCL_MESSAGE=>ADD( if_param = 'HEADER_PARTNER_ADDR'
                         if_field = 'COUNTRYISO' ).
     ENDIF.
   ENDIF.

   cs_partner-updkz_adr = it_header_partner_addr-upd_mode_adr.

   MOVE-CORRESPONDING it_header_partner_addr TO gt_bapiaddr1. "n_1031533
   APPEND gt_bapiaddr1.                                      "n_1031533

ENDFORM.                    " PARTNER_ADDRESS_CHG_FILL

Regards,

Marcin

amy_king
Active Contributor
0 Kudos

Hi Marcin,

Thanks for the reply. Subroutine partner_address_chg_fill is called only if a manual address is indicated by importing parameter header_partner-manual_addr. In my call, this parameter is false, so the subroutine you mention is not called.

It must somehow be possible to change the partner address by passing in individual address details like CITY, STREET, etc., otherwise I imagine there would not be a need to have those fields in the import table header_partner_address.

Cheers,

Amy

marcin_milczynski
Contributor
0 Kudos

Hi Amy,

If you don't mark the address as manual, then the address number of customer number record KNA1 is assigned in VBPA table for delivery partners. So the only option to change the address in delivery is to mark it as manual netry.

Regards,

Marcin

amy_king
Active Contributor
0 Kudos

HI Marcin,

Thanks for your time. So if header_partner-manual_addr is required to provide new address details, this means header_partner_addr-addr_no is also required since, as you pointed out, the subroutine partner_address_chg_fill requires it. This means that you must have previously created the address you want to use since you must know its address number. How can you first create a new address record so that you can know its address number to pass to the BAPI? I've looked for function modules or BAPIs to create a new address record in table ADRC, but all the function modules I find require creating the address in the context of an employee or business partner, which I don't want to do since this address is for use by a delivery only.

Cheers,

Amy

-----Edited-----

So I was able to answer this last part on my own. The following function modules are unreleased, but this sequence of calls does create a new address record in table ADRC which you may then pass to the BAPI as the new partner address.

  1. Function module SD_PARTNER_BAPI_ADDRESS_CREATE
  2. Function module SD_VBPA_RECORD_FILL
  3. Function module SD_PARTNER_ADDRESSES_TO_DB
  4. COMMIT WORK

Message was edited by: Amy King

Former Member
0 Kudos

HI,Amy!

Now ,I have the same problem update the DN header partner address use bapi for abap.

I had try to use the funciton 'WS_DELIVERY_UPDATE' the import IT_PARTNER_UPDATE to change

the partner address,but I find did not fill the partner's tel and fax for use the funciton.

Your message is useful ,can you give the full sample code for me ref....

ths more!

<email removed by the Moderator>

by owner

0 Kudos

Hi all,

It's driving me crazy.  I'm trying to update the related delivery VBPA-ADRNR from userexit_save_document called from VA02.  The address is manual (9xxxxxxxxx) and might be different since we use the parameter to generate manual address.  I'm using BAPI_OUTB_DELIVERY_CHANGE and any sample code would be appreciated.

thanks

JF

amy_king
Active Contributor
0 Kudos

Hi JF and Owner,

In my call to BAPI_OUTB_DELIVERY_CHANGE, I was able to update the partner address details by using the BAPI's header_partner and header_partner_addr parameters. I populated these parameters as follows...

   data ls_partner           type bapidlvpartnerchg.
   data ls_partner_addr type bapidlvpartnaddrchg.

   ls_partner-upd_mode_partn = 'U'.   " update partner
   ls_partner-deliv_numb           = delivery_number.
   ls_partner-partn_role             = partner_role.
   ls_partner-partner_no            = customer_number.
   ls_partner-address_no          = address_number.

   case abap_true.
       when use_customer_address.    " i.e.,
address_number is the customer's KNA1-ADRNR address number
           ls_partner-manual_addr = abap_false.

      when others. " manual address
           ls_partner-manual_addr = abap_true.

           ls_partner_addr-upd_mode_adr = 'U'. " create or update address
           ls_partner_addr-addr_no             = address_number.
           ls_partner_addr-name                  = name1.
           ls_partner_addr-name_2              = name2.
           ls_partner_addr-city                      = city.
           ls_partner_addr-postl_cod1         = postal_code.
           ls_partner_addr-street                  = street.
           ls_partner_addr-str_suppl2          = street_suppl2.
           ls_partner_addr-location               = location.
           ls_partner_addr-country                = country.
           ls_partner_addr-region                 = region.
           ls_partner_addr-tel1_numbr         = telephone_number.


           append ls_partner_addr to header_partner_addr.
   endcase.

   append ls_partner to header_partner.

One important thing to note is the partner I am updating is a custom partner role and not the standard ship-to partner role that is populated when the delivery is first created. We found in our system that it was not possible to change details of the standard ship-to partner after the outbound delivery was initially created. There is supposedly some configuration that would make it possible to change the standard ship-to partner after initial creation of an outbound delivery, but our config folks were not able to enable this. To work around the issue, we created custom partner roles which we have complete control over and can change as needed.


Good luck.

Amy

0 Kudos

thanks Amy.  That's a great advice and piece of code.  In your investigation, do you know if it's possible to change the ADRNR assigned to a delivery to another existing VBPA-ADRNR or in other words just pass addr_no in your FM.

thanks,

JF

amy_king
Active Contributor
0 Kudos

Hi JF,

You'll have to give this a try to see if it works or not. In my code snippet above, I'm using

  ls_partner_addr-upd_mode_adr = 'U'.

Value 'U' indicates change or create address, if it does not already exist.

but you can also leave this field blank to tell the BAPI to ignore address data. This may allow you to just pass in the address number and not have to provide address details-- I think that's what you're trying to do.

  ls_partner_addr-upd_mode_adr = space.

Value space indicates No change, address data will be ignored.

Cheers,

Amy

Former Member
0 Kudos

This message was moderated.

Answers (0)