Skip to Content
Technical Articles
Author's profile photo Daiana Feiten

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%20Logic%20app

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.

  1. 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%20Sales%20Orders%20%28VA01%29%20app

Create Sales Orders (VA01) app

 

  1. 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%20Sales%20Orders%20%28VA01%29%20app

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%20Your%20Solution%20app

Manage Your Solution app

 

Troubleshooting Tips

  1. Note: The Incoterms version is only editable for sales order with status open.

 

  1. 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%20no.%20V2720

Message no. V2720

 

  1. 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%20no.%20V2721

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.

Assigned Tags

      3 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Izabelle Lopes
      Izabelle Lopes

      Really helpful and well explained blog! Thanks for it, Daiana!

      Author's profile photo Thangaraj Thomas
      Thangaraj Thomas

      Hi Daiana,

      Excellent Blog. Thank you the information.

      Thanks

      Thangaraj Thomas

      Author's profile photo Kudi Shi
      Kudi Shi

      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