Sie sind auf Seite 1von 9

Changing Partners Address Data

of the Sales Order

Applies to:
SAP ECC 6.0. For more information, visit the ABAP homepage.

Summary
This article explains how to change partners address data in sales order programmatically.
Author:

Oleg Zilin

Company: Ozone Consulting JLLC, Republic of Belarus


Created on: 3 February 2011

Author Bio
Oleg Zilin started his IT career more than 30 years ago. He programmed with COBOL, Visual
Basic, Delphi, and Java and long ago with FORTRAN for mainframes. He has been working with
the SAP solutions since 2004. He has the experience in IT Services, Automotive, Electronics,
Consumer Products, Manufacturing industries. At present he works for the company Ozone
Consulting JLLC in Republic of Belarus as programmer analyst (ABAP4 Developer)

SAP COMMUNITY NETWORK


2011 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com


1

Changing Partners Address Data of the Sales Order

Table of Contents
Introduction ......................................................................................................................................................... 3
The Interface of the Functional Module .............................................................................................................. 4
Some Words about the Functional Module ..................................................................................................... 4
The Source Code of the Function ................................................................................................................... 5
Conclusion .......................................................................................................................................................... 7
Related Content .................................................................................................................................................. 8
Disclaimer and Liability Notice ............................................................................................................................ 9

SAP COMMUNITY NETWORK


2011 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com


2

Changing Partners Address Data of the Sales Order

Introduction
In order to see and change partners address data, its necessary:
1. Start transaction VA02 for processed sales order ;
2. Press Display doc. header details;
3. Choose the bookmark Partners.

If you create a sales order (Transaction - VA01) without partners address data, then will be used data from
the master data.
If we double click on the field of the partner, we can get partners address data and change it.
During this a new user address ID will be created with new partners address data for this sales order only.
The master data for this partner will be unchanged. You can test it in the tables KNA1, ADRC and VBPA.
Thus we have changed the address data by means of transaction VA02.
Sometimes, it should be made programmatically.
We name our function module "ZSO_PARTNERS_ADDR_DATA_CHANGE".

SAP COMMUNITY NETWORK


2011 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com


3

Changing Partners Address Data of the Sales Order

The Interface of the Functional Module


We define input parameters of the function module in this way:

Exceptions:

Some Words about the Functional Module


It is possible to create new ADDRNUMBER in table ADRC and write address data in the database directly,
but it is bad practice. For work with addresses we have to use the Business Address Services (BAS).
It is recommended SAP. More information about BAS can you get in the SAP documentation
(BCSRV-ADR). BAS functional groups: SZA0, SZA1, SZA5, SZA7.
The function module 'BAPI_SALESORDER_CHANGE' uses BAS function modules to maintain addresses.
For this reason, we will use following functional modules:

'BAPISDORDER_GETDETAILEDLIST';
'BAPI_SALESORDER_CHANGE';
'BAPI_TRANSACTION_COMMIT'.

SAP COMMUNITY NETWORK


2011 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com


4

Changing Partners Address Data of the Sales Order

The Source Code of the Function

FUNCTION ZSO_PARTNERS_ADDR_DATA_CHANGE.
*"---------------------------------------------------------------------*"*"Local Interface:
*" IMPORTING
*"
REFERENCE(IM_VBELN) TYPE VBELN
*"
REFERENCE(IM_PARVW) TYPE PARVW
*"
REFERENCE(IM_ADDRESS) TYPE BAPIADDR1
*" EXCEPTIONS
*"
ERROR_DETAIL_INFORMATION
*"
PARTNER_FUNCTION_NOT_FOUND
*"
ERROR_OF_SALESORDER_CHANGING
*"---------------------------------------------------------------------type-pools : abap .
constants :
CNST_NEW_ADDR
type addr_link value '999999' ,
CNST_UPDATE
type updkz_d
value 'U'
CNST_ERR_R
type bapiflag
value 'R'
data :
ls_selected
type
order_view,
ls_vbeln
type
sales_key ,
ls_header
type
bapisdhd
,
lt_vbeln
type table of sales_key ,
lt_header
type table of bapisdhd
,
lt_partners
type table of bapisdpart ,
lt_return
type table of bapiret2
,
lt_partner_ch
type table of bapiparnrc ,
lt_address
type table of bapiaddr1 ,
ls_hdr1
type bapisdh1
,
ls_hdr1_x
type bapisdh1x
,
ls_partner_ch
type bapiparnrc
,
ls_address
type bapiaddr1
.
field-symbols :
<fs_partners>
type bapisdpart ,
<fs_return>
type bapiret2
.
* -------------------------------------------* Get detail information about sales order
* -------------------------------------------ls_selected-header := abap_true .
ls_selected-partner := abap_true .
ls_selected-address := abap_true .

,
.

ls_vbeln-vbeln := im_vbeln .
append ls_vbeln-vbeln TO lt_vbeln .
CALL FUNCTION 'BAPISDORDER_GETDETAILEDLIST'
EXPORTING
i_bapi_view
= ls_selected
TABLES
sales_documents
= lt_vbeln
order_headers_out = lt_header
order_partners_out = lt_partners.

SAP COMMUNITY NETWORK


2011 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com


5

Changing Partners Address Data of the Sales Order

ls_hdr1_x-updateflag := CNST_UPDATE .
read table lt_header
into ls_header
index 1.
if sy-subrc = 0 .
ls_hdr1-sales_org := ls_header-sales_org .
ls_hdr1-distr_chan := ls_header-distr_chan.
ls_hdr1-division
:= ls_header-division
else.
raise error_detail_information .
endif.
ls_partner_ch-document
:= im_vbeln .
ls_partner_ch-updateflag := CNST_UPDATE .
* -------------------------------------------*
Set partners info
* -------------------------------------------ls_partner_ch-partn_role := im_parvw .
read table lt_partners
assigning <fs_partners>
with key partn_role = im_parvw .

if sy-subrc = 0 .
ls_partner_ch-addr_link
:= CNST_NEW_ADDR .
ls_partner_ch-address
:= <fs_partners>-address .
ls_partner_ch-p_numb_old
:= <fs_partners>-customer .
ls_partner_ch-p_numb_new := <fs_partners>-customer .
append ls_partner_ch to lt_partner_ch .
unassign <fs_partners> .
else.
raise partner_function_not_found .
endif.
* -------------------------------------------*
Set new address
* -------------------------------------------ls_address
:= im_address
.
ls_address-addr_no
:= CNST_NEW_ADDR .
APPEND ls_address TO lt_address .
* -------------------------------------------*
Sales order change
* -------------------------------------------CALL FUNCTION 'BAPI_SALESORDER_CHANGE'
EXPORTING
salesdocument
= im_vbeln
order_header_in
= ls_hdr1
order_header_inx
= ls_hdr1_x
behave_when_error = CNST_ERR_R
TABLES
return
= lt_return
partnerchanges
= lt_partner_ch
partneraddresses
= lt_address.
* -------------------------------------------*
Errors handling
* -------------------------------------------loop at lt_return assigning <fs_return>
where type = 'E' or type = 'A'.
raise error_of_salesorder_changing .
endloop.

SAP COMMUNITY NETWORK


2011 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com


6

Changing Partners Address Data of the Sales Order

unassign <fs_return>.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.
ENDFUNCTION.

Conclusion
Thus, we see that if we change the address data of the partner in sales order - master data does not vary. A
new user address ID with the new address data will be created only for processed sales order.
Using this functional module, it is possible to write the functional module for copying of the partners address
data with partners function Ship-to to Bill-to et cetera.

SAP COMMUNITY NETWORK


2011 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com


7

Changing Partners Address Data of the Sales Order

Related Content
SDN Forum
For more information, visit the ABAP homepage .

SAP COMMUNITY NETWORK


2011 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com


8

Changing Partners Address Data of the Sales Order

Disclaimer and Liability Notice


This document may discuss sample coding or other information that does not include SAP official interfaces and therefore is not
supported by SAP. Changes made based on this information are not supported and can be overwritten during an upgrade.
SAP will not be held liable for any damages caused by using or misusing the information, code or methods suggested in this document,
and anyone using these methods does so at his/her own risk.
SAP offers no guarantees and assumes no responsibility or liability of any type with respect to the content of this technical article or
code sample, including any liability resulting from incompatibility between the content within this document and the materials and
services offered by SAP. You agree that you will not hold, or seek to hold, SAP responsible or liable with respect to the content of this
document.

SAP COMMUNITY NETWORK


2011 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com


9

Das könnte Ihnen auch gefallen