Technical Articles
How to use custom logic to set Incoterms in Sales Documents
In a sales document, by default, Incoterms are always determined from the sold-to party and not from the ship-to party.
From CE2202, it is possible for Incoterms to be derived from the ship-to party when creating or changing the sales document. You can set or change the following fields by implementing custom logic in the Business Add-Ins (BAdIs) Sales Header Business Data Modification and Sales Item Business Data Modification:
- Incoterms version
- Incoterms classification
- Incoterms location 1
- Incoterms location 2
To customize your BAdI logic, logon to the SAP Fiori launchpad as an Administrator and open Custom Logic app:
Choose Custom Logic in top menu bar and choose Create.
Custom Logic app
You can implement the custom logic at the header level using Sales Header Business Data Modification (SD_SLS_MODIFY_HEAD_BUSINESS) or at the item level using Sales Item Business Data Modification (SD_SLS_MODIFY_ITEM_BUSINESS). It really depends on your business process.
You can follow as an example, the following implementation on the header level and on the item level.
- Header level – Fill the following entries and choose Create.
- Business Context: Sales: Sales Document
- BAdI Description: Sales Header Business Data Modification
- Implementation Description: Modify Incoterms at the header level (for example)
- Implementation ID: Generated by default
Choose Draft, implement your logic in Draft Logic page.
Sample Code:
MOVE-CORRESPONDING salesdocument to salesdocument_businessdata.
data: ls_customersalesarea type i_customersalesarea.
read table salesdocumentpartners WITH KEY partnerfunction = 'WE' INTO data(lv_shipto).
Select single incotermsclassification, incotermsversion, incotermslocation1, incotermslocation2
from I_CustomerSalesArea into CORRESPONDING FIELDS OF @ls_customersalesarea
where customer = @lv_shipto-customer and
salesorganization = @salesdocument-salesorganization and
distributionchannel = @salesdocument-distributionchannel and
division = @salesdocument-organizationdivision.
salesdocument_businessdata-incotermsversion = ls_customersalesarea-incotermsversion.
salesdocument_businessdata-incotermsclassification = ls_customersalesarea-incotermsclassification.
salesdocument_businessdata-incotermslocation1 = ls_customersalesarea-incotermslocation1.
salesdocument_businessdata-incotermslocation2 = ls_customersalesarea-incotermslocation2.
Choose Save Draft and then Publish.
With this customized logic, when creating or changing a sales document, the system will read the values of incotermsclassification, incotermsversion, incotermslocation1, incotermslocation2 fields of the ship-to party and then set/update the matched values at the sales header level.
Create Sales Orders (VA01) app
- Item Level – Fill the following entries and choose Create.
- Business Context: Sales: Sales Document Item
- BAdI Description: Sales Item Business Data Modification
- Implementation Description: Modify Incoterms at the item level (for example)
- Implementation ID: Generated by default
Choose Draft, implement your logic in Draft Logic page.
Sample Code:
MOVE-CORRESPONDING salesdocumentitem to salesdocumentitem_businessdata. data: ls_customersalesarea type i_customersalesarea. if line_exists( salesdocumentitempartners[ salesdocumentitem = salesdocumentitem-salesdocumentitem partnerfunction = 'WE' ] ). read table salesdocumentitempartners WITH KEY partnerfunction = 'WE' salesdocumentitem = salesdocumentitem-salesdocumentitem INTO data(ls_shipto). Select single incotermsclassification, incotermslocation1, incotermslocation2 from I_CustomerSalesArea into CORRESPONDING FIELDS OF @ls_customersalesarea where customer = @ls_shipto-customer and salesorganization = @salesdocument-salesorganization and distributionchannel = @salesdocument-distributionchannel and division = @salesdocument-organizationdivision. salesdocumentitem_businessdata-incotermsclassification = ls_customersalesarea-incotermsclassification. salesdocumentitem_businessdata-incotermslocation1 = ls_customersalesarea-incotermslocation1. salesdocumentitem_businessdata-incotermslocation2 = ls_customersalesarea-incotermslocation2. endif.
Choose Save Draft and then Publish.
With this customized logic, the system will read the values of incotermsclassification, incotermslocation1, incotermslocation2 fields of the ship-to party and then set/update the matched values at the sales item level.
Create Sales Orders (VA01) app
Custom Configuration
Just a brief reminder that Incoterms setup is dependent on the following configuration steps. For example, in the Manage Your Solution app, choose Configure Your Solution. You can find this configuration activity under Sales -> Sales Master Data Management -> Set up Incoterms.
Manage Your Solution app
Troubleshooting Tips
- Note: The Incoterms version is only editable for sales order with status open.
- When an item at the sales document is partially or fully delivered, it is not possible to change the Incoterms.
A message will be displayed, and the Incoterm details will not be taken over:
The system has collected messages. For more information, see the log.
Message no. V2720
- Note: The Incoterms version is not changeable on item level.
A message will be displayed, and the Incoterms version won’t to be changed:
The system has collected messages. For more information, see the log.
Message no. V2721
This blog post only shows a simple case using BAdI to set or change Incoterms at the sales documents. Basically, you can achieve various enhancement against your business process.
Really helpful and well explained blog! Thanks for it, Daiana!
Hi Daiana,
Excellent Blog. Thank you the information.
Thanks
Hi Daiana,
Thanks for your sharing.
If there is a requirment about changing incoterms at the header level of sales document manually, after reading the default value from ship-to party via the BAdI above. During my test, it looks not changeable for business with the BAdI(SD_SLS_MODIFY_HEAD_BUSINESS).
Do you have any exits/ideas for this?
Best Regards,
Kudi