Learn how to create a new Intermediate Document (IDoc)output for sending goods movements when you use transaction MIGO so that you can retain all the benefits of output message control.
Key Concept
An Intermediate Document (IDoc) is a standard SAP document used for message exchange between SAP application systems (such as SAP R/3, SAP ERP, SAP SCM, or SAP Customer Relationship Management [SAP CRM]). Material documents created from goods movements sometimes need to be delivered to different external systems. IDocs are the most standard way of interfacing SAP application systems with third-party systems.
Imagine you need to send goods movement data to external third-party systems. SAP doesn’t deliver any standard Intermediate Document (IDoc) output for this, and suggests use of a standard user exit to send the data. However, I prefer to use message control. Note that both options require development.
Most transactional interfaces (such as sending purchase orders, sales order confirmations, or deliveries) use a message control mechanism to send IDocs. If you use user exits instead, you lose a few important features:
- You cannot use an access sequence to specify which movements (from which plants, storage locations) need to be delivered to the external warehouse management system. You would need to hardcode it in the user exit.
- You cannot repeat the output (if this is necessary) from a material document transaction. In addition, you cannot check if the output was successful in any other way except by checking transaction WE02 (IDoc monitoring).
When you send material documents created by good movements as an IDoc using standard message control, you gain the ability to monitor your IDocs from a material document. You can also easily check for errors and resend the IDoc directly from the material document overview.
To use standard message control to send IDocs from material movements created using transaction MIGO, you need to follow the steps in the next section to implement the functionality. The steps are required because no predefined output type exists for an Electronic Data Interchange (EDI) Application Link Enabling (ALE) scenario for transaction MIGO.
Implementation
Step 1. Create a function module to populate an IDoc. The function module populates the IDoc with material document data. Because this IDoc uses standard message control, you need to have function module parameters exactly the same as for every other standard SAP IDoc. That is why the easiest way to create the new function module correctly is to copy any standard function module used for IDoc exchange. You can copy them directly from transaction SE37. You need to specify the standard IDoc function module (for example, IDOC_OUTPUT_DELVRY). Select Copy As, and enter a new module name Z_IDOC_OUTPUT_MOVEMENT, as shown in Figure 1. Remember to use a custom function group for your custom function modules because you cannot create custom function modules in standard function groups.

Figure 1
Copy a function module
Then, fill in the function module with the sample code provided in Figure 2 that populates the IDoc with information from the material document. The comments attached inside the code provide detailed information on what is happening inside the function module.
FUNCTION Z_IDOC_OUTPUT_MOVEMENT.
*"---------------------------------------------------------------------- *" *"Global Interface: *" IMPORTING *" VALUE(OBJECT) LIKE NAST STRUCTURE NAST *" VALUE(CONTROL_RECORD_IN) LIKE EDIDC STRUCTURE EDIDC *" EXPORTING *" VALUE(OBJECT_TYPE) LIKE WFAS1-ASGTP *" VALUE(CONTROL_RECORD_OUT) LIKE EDIDC STRUCTURE EDIDC *" TABLES *" INT_EDIDD STRUCTURE EDIDD *" EXCEPTIONS *" ERROR_MESSAGE_RECEIVED *"----------------------------------------------------------------------
tables: edidd, edidc, e1mbxyh, e1mbxyi.
data: begin of comm_IDoc_control occurs 10.
include structure edidc.
data: end of comm_IDoc_control.
data : begin of xMKPF occurs 0.
include structure MKPF .
data: end of xMKPF.
data : begin of xmseg occurs 0.
include structure mseg .
data: end of xmseg.
*you need to copy the control record that comes
*to the function module to the one that will
*be visible in the output
CONTROL_RECORD_OUT = CONTROL_RECORD_IN.
*the only things you need to fill in the output
*control record is the message type and the IDoc type
*you are using message type WMMBXY and IDoc type WMMBID01
*as these are SAP standard for inbound material movements
*(so they have the same fields as the outbound)
CONTROL_RECORD_OUT-mestyp = 'WMMBXY'.
CONTROL_RECORD_OUT-IDoctp = 'WMMBID01'.
data: LV_MBLNR(10).
DATA: LV_MJAHR(4).
DATA: LV_ZEILE(4).
*Object segment has all the information about
*the material movement document (number, year, position)
check OBJECT is not initial.
LV_MBLNR = OBJECT-OBJKY(10).
LV_MJAHR = OBJECT-OBJKY+10(4).
LV_ZEILE = OBJECT-OBJKY+14(4).
*you need to select the data from material document line
*on the basis of the object segment information
select * from mseg into table xmseg
WHERE MBLNR = LV_MBLNR
and MJAHR = LV_MJAHR
and ZEILE = LV_ZEILE .
if sy-subrc = '0'.
*you need to select the data from material document header
*on the basis of the object segment information
SELECT * FROM MKPF INTo TABLE xmkpf
WHERE MBLNR = LV_MBLNR .
if sy-subrc = '0'.
clear INT_EDIDD.
*you move the data to IDoc segments
loop at xmkpf.
move-corresponding xmkpf to e1mbxyh.
move sy-tcode to e1mbxyh-tcode.
move e1mbxyh to INT_EDIDD-sdata.
INT_EDIDD-SEGNAM = 'E1MBXYH'.
INT_EDIDD-SDATA = e1mbxyh.
APPEND INT_EDIDD.
endloop.
*you move the data to IDoc segments
loop at xmseg.
clear INT_EDIDD.
move-corresponding xmseg to e1mbxyi.
e1mbxyi-SMBLN = xmseg-MBLNR.
e1mbxyi-SMBLP = xmseg-ZEILE.
move e1mbxyi to INT_EDIDD-sdata.
INT_EDIDD-SEGNAM = 'E1MBXYI'.
INT_EDIDD-SDATA = e1mbxyi.
APPEND INT_EDIDD.
endloop.
endif.
endif.
ENDFUNCTION. |
<><>
Figure 2 Sample code for function module for outbound material movements
Note that the message output from transaction MIGO using message control can only be done on an item level (with some documents such as purchase orders, sales orders, deliveries), or also on header level apart from the item level. This means that with the code in Figure 2, you can have one IDoc message per each line in a material document and that every material document is split into as many IDocs as the number of lines it has. As an alternative, you could change the code to output all lines in one IDoc, but then you would need to suppress the rest of the item level IDocs. For the purpose of this article you should configure item level IDocs that have only one item (the one for which the output was generated).
Step 2. Assign a new function module to the output process code. During the outbound process using message control, a function module that processes the IDoc can only be found using the outbound process code. You can configure a new process code by following SAP menu path Tools > Business Communications > IDoc Interface/ALE > Development > IDoc > Outbound Processing > Maintain Process Code or by using transaction WE41. Go to the change mode for this transaction by clicking the change icon. Then click the New Entries button, and fill in the Process code and Function module fields (Figure 3). Remember to select Option ALE-Service/inb. procg as Processing w/o ALE service because you won’t be using ALE to send this IDoc.

Figure 3
Outbound process code creation
Once you’ve created the process code to point to a function module, you’ll see that you can use it later in partner profile configuration. Before you can go to the partner profile configuration, you need to finish the rest of the steps for output configuration.
Step 3. Define a new access sequence. An access sequence defines the order in which the system searches for condition records that (in terms of output types) controls which data can create an IDoc message. Imagine you’d only like to send material movements that are created in a specific plant or storage location. In addition, every material document line created is doubled by an automatically created line in the other direction. If you don’t want to output those automatic lines, you also need to include a credit/debit indicator in your access sequence. You can create a new access sequence table with transaction NACQ. In the transaction’s main screen, select application ME (inventory management) and a table number (for custom tables, you should use one from 900-999). Once you choose the table number, click the create icon from the menu. On the next screen, click Plant, Storage location, and Debit/Credit ind (indicator) in the right column so they also appear in the left column, as shown in Figure 4.

Figure 4
Custom access sequence table creation
Next, generate the table by clicking the generate icon
in Figure 4. This completes the process of creating a new access sequence table. You have removed the automatically generated double line and the table is ready to use in an active access sequence.
Step 4. Create a new output type for EDI processing. Output types are the central components of message control. They contain generic processing routines (programs) that are executed depending on the medium used (e.g., printer, EDI, or ALE). For material movements you have a few preconfigured output types. However, none are configured with EDI processing routines (meaning they cannot be used with IDocs). The easiest way to create a new one is to copy a standard one and just add a few things necessary for IDoc message exchange. You can create new output types in transaction NACE. After you select application ME (inventory management), click the Output Types button. Next, go to the change mode and select output type MLGR to copy it (Figure 5).

Figure 5
Output type copying
Next, click the copy icon and enter ZLGR for the new output type name. When you try to save it, you see the message, “The entry to be copied has dependent entries.” Select the copy all option. You should add a new processing routine for EDI processing. To do that select the new output type and then open processing routines on the left side of the screen. Then you create a new one for transmission Medium 6 (EDI) exactly as shown in Figure 6 with program RSNASTED and form routine EDI_PROCESSING.

Figure 6
EDI processing routine assignment
To use the new output type with the partner profile of a logical system (e.g., SAP NetWeaver Process Integration [SAP NetWeaver PI]) instead of using vendor or customer numbers select partner functions and add an entry with EDI and LS (for logical system) as shown in Figure 7.

Figure 7
New partner function assignment
Once the new output type is saved, you can add it to the output procedure to make it work in the next step.
Step 5. Assign a new output type to the standard output procedure of material documents. An output procedure is a pool of output types that applications use to determine the current document type. The inventory management application (ME) has only one output procedure — ME0001. Attach this to your new output type ZLGR. First, select procedure ME0001 and click the control menu on the left side of the screen. Then you can add a new entry with the new output type. The Step field should be the last one on the list you enter, so make sure you select the number higher then the last maintained when you’re in the ME001 output procedure view. Set the control column (Condition counter [Cntr]) to 10 because it’s not used in this application. The CTyp (output type) needs to be ZLGR as per previous configuration. The customizing should be exactly as specified in Figure 8.

Figure 8
Assignment of a new output type to an output procedure
Step 6. Assign a new access sequence table to the access sequence used with the output type. To use the new access sequence table created in step 3 you need to add it to the access sequence used with the new output type ZLGR. Because the access sequence that you copied from the original output type was 0002, you can add a new access sequence table to that access sequence. You can also add a new access sequence table in transaction NACE with selected application ME by using the Access sequence button. Then, select access sequence 0002 and double-click the Accesses folder as shown in Figure 9. Finally, fill in the access sequence number (AcNo) with any value greater than any of the existing ones. In the Tab column enter the number of the new access sequence table and save everything.

Figure 9
Assign a new access sequence table to an access sequence
Once you update the access sequence with the customer table, enter condition records for it.
Step 7. Fill in the condition record for the new output type. The new access sequence offers a way to specify plant, storage location, and debit/credit indicators that are checked during creation of a new material document if the output should be created. Transaction NACE has one more option — condition records — that allows you to specify those values. Once in transaction NACE, select the condition records and ZLRG output type. Next, fill in values for plant, storage location, and debit/credit indicator for which you want to have an IDoc created. For the test, enter 1000 for Plant, 0001 for Storage location, and H for the debit/credit indicator (D/C indic.). You also need to specify partner function (LS), the logical system (DXICLNT100) that will be the receiver of the IDoc, medium (6 for EDI), and date of the output creation (4 for immediately), as shown in Figure 10. Note that the logical system varies in each case.

Figure 10
New output conditions
Step 8. Configure the Partner profiles for the IDoc message exchange. After the creation and configuration of a new output type, fill in the partner profiles that are the endpoints to the IDoc exchange. The partner profile stores the message type and IDoc type that specify the kind of IDoc that can be generated and information about the port. The port is a real destination where the IDoc will be delivered (SAP NetWeaver PI, for example). Configure the partner profiles in transaction WE20 after selecting the partner number (e.g., the logical system for SAP NetWeaver PI) you need to select outbound configuration and add a new entry button. Then enter:
- Message Type WMMBXY: This is a standard message type for material documents
- Receiver port: This is the port created in transaction WE21, which can point to SAP NetWeaver PI or any other port available
- Basic type WMMBID01: IDoc basic type for material documents
You can leave the default values for the rest (Figure 11). Because you don’t need to send an IDoc to a real receiver for the purpose of this article, I will not explain how to create receiver ports and Remote Function Call (RFC) destinations used in those ports. If you need to connect SAP ERP to SAP NetWeaver PI, I suggest taking a look at my and coauthor Michal Kowalczewski’s SAP PRESS book Mastering IDoc Business Scenarios with the SAP Exchange Infrastructure 3.0 for more details.

Figure 11
Partner profile details for material document IDoc exchange
Once you fill in the main screen of the partner profile configuration, select the Message Control tab and specify which process codes trigger the IDoc message exchange. For the purpose of sending goods movements (material documents), create a new message type (output type) ZLGR and a new process code ZMOV (Figure 12). Application for material documents is always the same ME. If you want to make sure the IDoc is sent after you change the material document and not only during creation, fill in the second line with exactly the same information but with the Change output check box selected.

Figure 12
Message control configuration for a new output type
Step 9. Test the new IDoc scenario and select what kind of goods movement you want to perform. For the purpose of this article you should do a simple plant-to-plant movement using the 301 movement type. Go to transaction MIGO, select movement type 301, and fill in the details for the material number, source plant and storage location, and receiver plant and storage location. Remember to use the same source plant/storage location combination you specified in the condition record in step 7. Otherwise the IDoc does not generate. Figure 13 shows a sample data for MIGO transaction. You can use other material or plant/storage location combinations.

Figure 13
Sample plant to plant material movement
If you save the transaction, the IDoc should generate successfully. You can see this in transaction WE02, which is used for IDoc monitoring. If you want to see the IDoc number go to transaction MB03 (material document display) and enter the material document number generated in transaction MIGO and the current year. Once you confirm the entry, click the Details fm Item button (Figure 14). When a second screen comes up, click the Messages button to see the details.

Figure 14
Button to show details
Now a third screen comes up showing the details (Figure 15). If you select the line with ZLGR output type and click the Processing log button, the IDoc number displays. You can view the IDoc in transaction WE02 by entering the number from the processing log in the IDoc number field of this transaction.

Figure 15
Output types for a new material document
If you encountered a problem with sending the IDoc, the message on the Messages screen of MB03 is red, not green. If you select the red message and click the Processing log button, you can view more information about the error.
Michal Krawczyk
Michal Krawczyk is an SAP consultant for BCC Poland. He works with SAP XI/PI, ALE/EDI, CRM middleware, and other SAP interface-related technologies. He was presented the Top Contributor award in the XI/PI area on SDN in 2005, 2006, and 2007, and the SAP Mentor award in 2007. He has published more than 60 articles about SAP XI and MDM on SDN and has written a book about PI published by SAP PRESS. He is also an SAP Professional Journal author.
You may contact the author at sap.integration@gmail.com.
If you have comments about this article or publication, or would like to submit an article idea, please contact the editor.