Beruflich Dokumente
Kultur Dokumente
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
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)
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
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".
Exceptions:
'BAPISDORDER_GETDETAILEDLIST';
'BAPI_SALESORDER_CHANGE';
'BAPI_TRANSACTION_COMMIT'.
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.
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.
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.
Related Content
SDN Forum
For more information, visit the ABAP homepage .