We had a specific requirement for creating Sales Order from Purchase Orders within the same SAP system. This was to happen in scenarios where we had an inter-company Purchase Order – a Plant in say Country X raises a PO for a Material which can be produced by another Plant in Country Y. Now both plants belong to the same Company but will have different Company Codes.
Normally for a PO we have a normal outbound EDI 850 (IDoc Type: ORDERS05) going to an external system (say EDI) using a middleware like SAP PI.
Then we also have the inbound EDI 850 (same IDoc Type) which creates a sales order (Transaction VA01) in SAP ECC.
In this case for Purchase Order (Application ‘EF’), instead of triggering the normal EDI 850 outbound to XI (Medium – ‘6’ for EDI) for our custom output type, we can use medium ‘8’ (Special Function). Then we need to specify a program and subroutine name. The subroutine should be like this:
SET EXTENDED CHECK OFF.
INCLUDE rvadtabl. "Messages
INCLUDE rv56acom. "I/O-Structure
SET EXTENDED CHECK ON.
FORM sub_trigger_code_for_po USING returncode TYPE sy-subrc
us_screen TYPE c.
* Code Logic
ENDFORM. " sub_trigger_code_for_po
The global structure nast is available in this subroutine. Here you can get the object key (objky) which will contain the PO number in this case.
The custom logic can be written as per our requirement. The triggering of the output conditions can be defined by the access sequences and routines associated with it. Only when the given conditions are satisfied, then the output condition is triggered which then calls the custom logic implemented in the subroutine.
For our scenario, in this structure we can get the PO data from concerned tables using the PO number available in nast.
This data can be populated into the IDoc structures and Inbound IDoc created using function module IDOC_INBOUND_WRITE_TO_DB. If you want this IDoc to be posted, you can do the same using IDOC_START_INBOUND.
Also Read: Sending Inbound IDocs from SAP Program
A good approach for doing this would be to do the IDoc population and triggering logic in background or a separate task.
Another quite useful trick for populating standard outbound IDocs for say PO’s in any custom program is by calling the standard SAP function module associated with that output type / outbound process code. Like example for PO if you want to populate the standard ORDERS05 outbound IDoc in your custom program, you can do the same just by calling IDOC_OUTPUT_ORDERS.
* Call the Function Module to Generate EDIDD Structure
CALL FUNCTION 'IDOC_OUTPUT_ORDERS'
object = wa_nast
control_record_in = wa_edidc
int_edidd = i_edidd
error_message_received = 1
data_not_relevant_for_sending = 2
OTHERS = 3.
Note that in this case we would need to send the control data in wa_edidc and a dummy (but valid) PO number and other details in wa_nast. The user exits associated with this EDI / IDoc will also get triggered for this case. Any further customization during population can be done there.
The populated IDoc can then easily be created and transmitted using MASTER_IDOC_DISTRIBUTE.
If you want to get such practical issues and resolutions straight to your inbox, please SUBSCRIBE. We respect your privacy and take protecting it seriously.
If you liked this post, please hit the share buttons on your screen.
Thank you very much for your time!!