PO Number field (VBAK-BSTNK) in Sales order contains customer’s order reference number. To avoid raising duplicate order for a customer SAP can be configured to check duplicate PO numbers. This blog highlights where in configuration you can activate this duplicate order check and which customer enhancement you can implement to check duplication during inbound IDoc processing.

SPRO configuration
You can configure this setting in same place where you define Sales Order document type. Navigate to path Sales and Distribution-> Sales-> Sales Documents-> Sales Document Header-> Define Sales Document Types in SPRO. As this setting is defined in Sales Document type level you will have to activate this for each sales document type you use. However, do take care not to activate this setting on return orders as return order will have same customer reference as original order.
Specify value A in ‘Check purh.order no’ to activate the check.
sap duplicate order spro va01
After this setting, if sales order is raised for a customer with duplicate PO number then message ‘Purchase order number in document number: & already exists’ (V4 115) will be issued. Type of message i.e. whether it will be warning or error will depend on another setting. To access this navigate to Sales and Distribution-> Sales-> Sales Documents-> Define Variable Messages.
sap duplicate order spro va01
Here you can change kind of message you want to issue. Obviously if it specify E (Error) then user will not be able to create this duplicate order but if you want them to create with caution then putting setting as W (Warning) will be appropriate.
Customer Enhancement
If you have configured message V4 115 as E (Error) then inbound Orders message will automatically fail during posting EDI. However, if message is W (warning) then order will be created without any notification to users.
You can use customer enhancement VEDA0001- ‘SD EDI Incoming Orders (Customer Extensions)’ to catch duplicate orders and issue notification emails. Or if you have more complex requirement to identify duplicate order which cannot be fulfilled by standard SAP logic then you can implement this customer enhancement and put you code there.
Standard SAP executes following select statement to check for duplicates. This should give you a good starting point to implement your own custom logic.
  SELECT b~vbeln
    INTO CORRESPONDING FIELDS OF TABLE tvbeln
    FROM vbak AS b
    INNER JOIN vbkd AS a
      ON b~vbeln EQ a~vbeln
    WHERE a~bstkd_m EQ customer_order_number
      AND b~vbeln   NE new_order_number
      AND b~kunnr   EQ sold_to_party
      AND b~auart   EQ order_type.
 
  IF NOT tvbeln IS INITIAL.
*   Duplicate order
  ENDIF.
In exit EXIT_SAPLVEDA_011 you can fill error messages in parameter DERRTAB, if you need to stop IDoc from posting.
 -----------------------------------------------------------------------------------------------
 Serkan AKKAVAK
Computer Engineer / ABAP Developer
serkurumsal@yandex.com
You can ask me all your questions about SAP and Abap .