When a sales order is assigned to a sales contract in SAP S/4HANA Cloud Public Edition, the system creates a reference relationship between the two documents and updates pricing accordingly. By default, however, the system copies very few header fields from the contract to the order — most fields are not transferred unless you explicitly configure it.
The BAdI SD_ASSG_CONTRHDR_DATATRANSFER is the extensibility point for controlling exactly what gets transferred at the header level — most notably the price list type, which the system does not copy by default, and any custom extension fields you have added to the sales document header. A companion BAdI, SD_ASSG_CONTRITM_DATATRANSFER, covers the same for the item level.
For background on how sales contract assignment works, see Sales Contract Fulfillment, Enabling Sales Contract Assignments, and Automatic Assignment of Sales Contracts.
BAdI at a Glance
Property Value
| BAdI name | SD_ASSG_CONTRHDR_DATATRANSFER |
| Description | Data Transfer for Contract Header Assignment |
| Enhancement suite | ES_SD_SALESCONTRACT_EXTEND |
| Business context | Sales: Sales Document |
| Interface | IF_SD_ASSG_CONTRHDR_DTATRANSF |
| Method | DEFINE_FIELDCOPY |
| Trigger | Sales contract header assignment to a sales order header |
| Implementation app | Custom Logic |
This BAdI fires during every assignment — manual and automatic — at the moment the system copies header data from the contract to the sales order. You implement this BAdI in the Custom Logic app. To enable copying of custom fields, you must first create them using the Custom Fields app with the business context Sales: Sales Document.
There is a companion BAdI for the item level: SD_ASSG_CONTRITM_DATATRANSFER (business context: Sales: Sales Document Item).
The Interface
INTERFACE if_sd_assg_contrhdr_dtatransf
PUBLIC.
INTERFACES if_badi_interface.
TYPES:
BEGIN OF ty_fieldlist,
fieldname TYPE c LENGTH 40,
copy TYPE abap_bool,
END OF ty_fieldlist.
TYPES tt_fieldlist TYPE STANDARD TABLE OF ty_fieldlist WITH DEFAULT KEY.
TYPES:
BEGIN OF ty_salescontract_in,
salescontract TYPE vbak-vbeln,
pricelisttype TYPE vbkd-pltyp.
INCLUDE TYPE sdsalesdoc_incl_eew_ps.
TYPES: END OF ty_salescontract_in.
TYPES:
BEGIN OF ty_salesorder_in,
salesordertype TYPE vbak-auart,
salesordercategory TYPE vbak-vbtyp,
salesorganization TYPE vbak-vkorg,
distributionchannel TYPE vbak-vtweg,
division TYPE vbak-spart,
soldtoparty TYPE vbak-kunnr,
pricelisttype TYPE vbkd-pltyp.
INCLUDE TYPE sdsalesdoc_incl_eew_ps.
TYPES: END OF ty_salesorder_in.
TYPES:
BEGIN OF ty_messages,
messagetype TYPE c LENGTH 1,
messagetext TYPE c LENGTH 148,
END OF ty_messages.
TYPES tt_messages TYPE STANDARD TABLE OF ty_messages WITH DEFAULT KEY.
METHODS define_fieldcopy
IMPORTING
salescontract_in TYPE ty_salescontract_in
salesorder_in TYPE ty_salesorder_in
CHANGING
fieldlist TYPE tt_fieldlist
messages TYPE tt_messages
RAISING
cx_ble_runtime_error.
ENDINTERFACE.
Method Parameters
Importing
salescontract_in — data from the source sales contract header:
- salescontract: the contract document number
- pricelisttype: the price list type assigned to the contract
- All custom fields from SDSALESDOC_INCL_EEW_PS
salesorder_in — key attributes of the target sales order:
- salesordertype, salesordercategory
- salesorganization, distributionchannel, division
- soldtoparty
- pricelisttype
- All custom fields from SDSALESDOC_INCL_EEW_PS
Changing
fieldlist — fields the framework considers copyable:
- fieldname
- copy (default is false)
PriceListType is the only standard field pre-populated. Custom fields must be appended explicitly.
messages — output messages:
- messagetype: S, I, W
- messagetext: up to 148 characters
In manual assignment, messages appear as a dialog. In automatic assignment, they are logged.
Examples
Price List Type
CLASS zcl_sd_assg_contrhdr_copy DEFINITION
PUBLIC FINAL CREATE PUBLIC.
PUBLIC SECTION.
INTERFACES if_badi_interface.
INTERFACES if_sd_assg_contrhdr_dtatransf.
ENDCLASS.
CLASS zcl_sd_assg_contrhdr_copy IMPLEMENTATION.
METHOD if_sd_assg_contrhdr_dtatransf~define_fieldcopy.
LOOP AT fieldlist ASSIGNING FIELD-SYMBOL()
WHERE fieldname="PriceListType".
-copy = abap_true.
ENDLOOP.
ENDMETHOD.
ENDCLASS.
Custom Field
Suppose you have created a custom field YY1_CONTRACTTIER_SDH. This holds a customer tier classification — GOLD, SILVER, or STANDARD — and you want to copy it under certain conditions.
CHECK salesorder_in-salesorganization = '1000'
OR salesorder_in-salesorganization = '2000'.
IF salescontract_in-yy1_contracttier_sdh IS NOT INITIAL.
APPEND VALUE #(
fieldname = `YY1_CONTRACTTIER_SDH`
copy = abap_true
) TO fieldlist.
ENDIF.
Item-Level Counterpart
If your custom fields exist at line item level, implement SD_ASSG_CONTRITM_DATATRANSFER alongside this BAdI. It follows the same pattern and is triggered during item-level assignment.
Summary
These BAdIs give you precise control over what flows from a sales contract to a sales order during assignment. You can enable copying of the price list type and any custom header fields, and apply business rules that determine when copying should happen.



