Technology Blogs by SAP
Learn how to extend and personalize SAP applications. Follow the SAP technology blog for insights into SAP BTP, ABAP, SAP Analytics Cloud, SAP HANA, and more.
cancel
Showing results for 
Search instead for 
Did you mean: 
Clover
Product and Topic Expert
Product and Topic Expert
0 Kudos
1,580

 

In the Create Sales Orders - Automatic Extraction app, the system starts data extraction and data proposal for sales order requests immediately after your purchase order files are uploaded. If SAP pre-delivered proposal rules do not satisfy your business needs, key users can create custom logic to modify sales order request data based on your own rules. (To know more about the default proposal rules, see Create Sales Orders - Automatic Extraction on SAP Help Portal.)


Here is an example of how to create your custom logic. You want the custom logic to work as follows:

  • If the company code of a sales order request is 0001, the system sets the sales area to 0001/01/01.
  • If no requested delivery date can be proposed , the system sets the requested delivery date to the current date plus seven days.

 

To create custom logic, SAP S/4HANA Cloud users should use the BAdI SD_SOR_AUTO_XTRCTN_MODIFY in the Custom Logic app, and SAP S/4HANA users can also call transaction se18 to open the enhancement spot ES_SD_SOR_AUTO_XTRCTN_MODIFY. The screenshots in following procedure are based on SAP S/4HANA Cloud 2402.

Creating Custom Logic

1. Open the Custom Logic app (extensibility specialist role SAP_BR_EXTENSIBILITY_SPEC).

Clover_0-1710147715344.png

2. On the Custom Logic tab, click Create.

Clover_1-1710147753797.png

3. Search for “SD_SOR_AUTO_XTRCTN_MODIFY” or “Sales Order Request”, and choose the extension point. Click Step 2.

Clover_2-1710147786661.png

Specify a description for your implementation. The system generates an ID according to your description. Click Review.

Clover_3-1710147817695.png

Click Create.

Clover_4-1710147855571.png

Once an implementation is created, click Publish.

Clover_5-1710147892495.png

  1. Open the code editor to implement your custom logic.

Clover_6-1710147922430.png

The code editor includes three tabs: Develop, Test and Compare. You can write code and check parameters info on the Develop tab. Click Edit to start writing.

Clover_7-1710147963323.png

Note: In our case, the custom logic involves both header and item fields. So, the output parameters include salesorderrequestheaderchanged (for header) and salesorderrequestitemschanged (for items).


In your code for the sales order request header, specify "company code = 0001" as the condition, and "sales area = 0001/01/01" as the result.

Clover_8-1710147999601.png

In your code for sales order request items, specify "requested delivery date = initial" as the condition, and "requested delivery date = current date + 7 days" as the result. Note that the current system date is retrieved from class cl_abap_context_info and method get_system_date.

Clover_9-1710148033322.png

Tip: The code editor support auto-completion. You can press "Ctrl + Space" to get suggestions and press "Shift + Enter" to insert the full signature.

Clover_10-1710148065929.png

5. Once the code is done, click Save. We recommend that you test your logic before publishing it.

Clover_11-1710148104937.png

Testing Custom Logic

Switch to the Test tab. Here you need to provide test data in the import parameters manually.

1. Enter "0001" for company code in the import parameter for sales order request header.

Clover_12-1710148133619.png

2. Input one row of test data in the import parameter for the sales order request items source. Specify a sales order request ID and an item ID.

Clover_13-1710148162016.png

3. Input one row of test data in the import parameter for sales order request items. Enter the same sales order request ID and item ID, with an empty request delivery date.

Clover_14-1710148201224.png

4. Save the test data by clicking Save As, and specify a variant name. Later you can switch test data using variants.

Clover_0-1710148377751.png

5. Click Test and check the test result in output parameters. The system should have set the sales area and the item request delivery date to expected values.

Clover_1-1710148402626.png

Publishing Custom Logic
Once the test is passed, you can Click Publish.

Clover_2-1710148457734.png

More Samples 

Click Show Sample Code in the code editor window. The samples show how you can use the import and changing parameters. You can copy the code snippets and adjust them as needed.

1. Determinate Ship-to as Sold-to

With the custom logic, the system fills the ship-to party with the sold-to party for sales order requests whose sales area is 1010/10/03 and for which no ship-to party can be determined.

Clover_3-1710148592644.png

2. Assign Sales Area According to Ship-to

With the custom logic, the system assigns a sales area according to the ship-to party for sales order requests whose company code is F001.

Clover_4-1710148640387.png

3. Change Sales Order Type

With the custom logic, the system changes the sales order type from OR (default type) to CCIS for sales order requests whose sales area is 1010/10/00.

Clover_5-1710148751034.png

4. Determinate Header Requested Delivery Date According to Items

With the custom logic, the system sets the header requested delivery date to the earliest requested delivery date in all items.

Clover_6-1710148769657.png

5. UoM Conversion

With the custom logic, the system changes the UoM to KG and sets the requested quantity to "requested quantity*100" for sales order request items whose UoM is BAG.

Clover_7-1710148787189.png

Related info


You can find series of blogs about this solution in below link.

The Link Collection for Create Sales Orders – Automatic Extraction | SAP Blogs