SAP Tech Pro

SAP Technical Blog
Topprice Price Comparison

Outbound processing – SAP ALE IDOCS

Outbound processing – SAP ALE IDOCS

For the purposes of this example we will develop a small ALE scenario.

We will develop a custom IDoc to carry the billing number from the Receiver system to the Service Provider’s system.

We will populate the IDoc in a user exit on the sending side. No rule conversion, segment filtering or version conversion will be implemented in the model

And in the next post we will process the transaction on the receiving side using a custom function module and a BDC transaction call.

Note: All IMG references to transactions are located in the transaction SALE

 

1. Create IDoc type (WE30) Client independent

The IDoc type refers to the IDoc structure that you will require for your development. In our case the IDoc type is called ZINVRV01.

This IDoc type will have 1 segment called Z1INVRV with 2 fields, LIFNR & XBLNR, in this segment. If you require many segments or nested segments then they are also created using the same procedure.

image

 

To create the IDoc type, follow these next few steps:

  • Enter transaction WE30 (ALE -> Extensions -> IDoc types -> Maintain IDoc type)
  • Type in ZINVRV01 and click on Basic IDoc type, click the Create icon
  • Click on Create new (we are creating an IDoc from scratch but you may want to copy another IDoc if it is similar to your requirements) and enter a description, and press enter
  • Click on ZINVRV01 and then on the Create icon
  • Enter Z1INVRV as the segment type (must start with Z1), check mandatory if the segment must exist (in this case check it), enter 1 in minimum number and 1 as maximum number. (Make the maximum number 9999999999 if there are going to be many of these segments in each IDoc. IE. When line items are passed via IDocs), click on Segment editor
  • Enter a description for your segment type and create
  • Enter a description for your segment, enter each field required in your IDoc, in our case type LIFNR across for Field name, DE structure and DE documentation, repeat for XBLNR and press enter to validate.
  • Save and generate, press back
  • To release the segment choose Goto, Release from the menu
  • Check the box on the line of your new segment
  • Save, Back and Enter
  • Your IDoc type structure should be displayed with your new segment
  • Save and back
  • To release the IDoc type choose Extras, Release type from the menu and Yes

Your IDoc is now ready for use. If you need to add fields or segments to your IDoc type, you will need to cancel the release of the IDoc type as well as the segment release using a similar procedure followed above (except now you uncheck the release box for the segment and you choose cancel release for the IDoc type).

 

2. Create message type (WE81) Client independent

To create a new message type, follow these next few steps:

  • Enter transaction WE81 (ALE -> Extensions -> IDoc types -> Maintain message type for intermed. Structure -> Create logical message type)
  • Choose Create logical message type by double clicking on it
  • Click on change icon to enter change mode
  • Click on New entries to add a new type
  • Enter the required message type, in our case it is ZINVRV and an appropriate description
  • Save and exit.

Your message type has now been created. The next step will be to link it to the IDoc.

 

3 Link message to IDoc type (WE82 & BD69) Client independent

To link the message type to the IDoc type follow these next few steps:

  • Enter transaction WE82 (ALE -> Extensions -> IDoc types -> Maintain message type for intermed. Structure -> EDI: Message Types and Assignment to IDoc Types)
  • Click on change icon to enter change mode
  • Click on New entries to create the link
  • Enter the message type ZINVRV and the BasicIDoc type as ZINVRV01
  • Save and exit
  • Enter transaction BD69 (ALE -> Extensions -> IDoc types -> Maintain message type for intermed. Structure -> Assign message type to IDoc for ALE)
  • Click on change icon to enter change mode
  • Click on New entries to create the link
  • Enter the message type ZINVRV and the BasicIDoc type as ZINVRV01
  • Save and exit

Your IDoc is now linked to your message type. We still need to link object types and add the message to the model before we can use the message.

 

4. Maintain object type for message type (BD59) Client independent

The ALE objects are used to create links between IDocs and applications objects. For our own message type and IDoc you must maintain object types for the links.

If you want to check the serialisation for the message type, then you must maintain object types for the serialisation. If no serialisation object has been maintained for a given message type, then the serialisation will not be checked for this message type.

To add an object type to our message type, follow these next few steps:

  • Enter transaction BD59 (ALE -> Extensions -> ALE object maintenance -> Maintain object types)
  • Type in your message type ZINVRV and press enter
  • Click on New entries
  • Enter your object type, LIFNR (We need to use the vendor as a filter object), the segment name where LIFNR resides, Z1INVRV, a number 1 for the sequence followed by the actual field name LIFNR
  • Save and exit.

You have now created an object that we’ll use as a filter object in the customer model to direct the flow of messages to the various logical systems based on the vendors in the filter of the message type ZINVRV.

We now need to add our new message type to the distribution model.

5. Configuring the Distribution Model (BD64) Client independent

To manually configure the customer distribution model, read the ALE configuration procedure, and follow these steps:

  • Perform the Maintain customer distribution model directly function. (ALE -> Distribution customer model -> Maintain customer distribution model directly)
  • Specify the customer model you want to maintain and the logical system that is to be the sender of the messages OR create a new model. (Create model ALE with logical system ALELS1C400)
  • Choose the receiving systems to which the sending system must forward message type ZINVRV to.
  • For each receiving logical system allocate the message type necessary for communication to the receiving systems as per ALE configuration procedure.
  • Create filter objects (in our case LIFNR as the object type with the associated vendor number, 0000018001 with leading zeros, in the object area) for the message types.
  • Save the entries.

NOTES:

You cannot maintain a message type between the same sender and receiver in more than one customer distribution model.

 

6. Maintain Sending System Partner type (WE20) Client independent

With this function, you define the partner profiles for all outbound and inbound messages on the basis of the customer distribution model.

After you have defined and distributed the customer model, you will have to maintain the partner profiles locally. Enter the output mode (background, immediately) and the package size for outbound processing.

 

7. Populate & Distribute IDoc using ABAP

 

An IDoc consists of a control record with structure edidc and one or more data records with structure edidd. The control record contains the sender and recipient of the IDoc, as well as information on the type of message.

To be able to pass an IDoc to the ALE layer, you must set up a field string with structure edidc and an internal table with structure edidd. They are used to call function module MASTER_IDOC_DISTRIBUTE, which performs the save to the database and triggers the dispatch if necessary.

7.1. Example code

The code displayed below does the following:

  • Populates our IDoc segment Z1INVR with the 2 fields XBLNR and LIFNR, populates the segment name and appends this to an internal table used to store the IDoc data.
  • Populates the control record info with the message type and IDoc type, and
  • Calls the MASTER_IDOC_DISTRIBUTE function module which distributes the IDoc as configured in the customer distribution model.

*--- Data declaration statements
DATA:		C_INVREV_SEGNAME(7) TYPE C VALUE 'Z1INVRV',
		C_INVREV_MESTYPE(6) TYPE C VALUE 'ZINVRV',
		C_INVREV_IDOC_TYPE(8) TYPE C VALUE 'ZINVRV01', 
		Z1INVRV LIKE Z1INVRV,
		C_INVREV_DOCTYPE LIKE BKPF-BLART VALUE 'YY',
		IDOC_CONTROL LIKE EDIDC,
		T_COMM_CONTROL LIKE EDIDC OCCURS 0 WITH HEADER LINE,
		IDOC_DATA LIKE EDIDD OCCURS 0 WITH HEADER LINE.

*--- Move the document header into a structure
LOOP AT DOC_HEAD_TAB INTO DOC_HEAD.
ENDLOOP.

*--- Move the document item data into a structure
LOOP AT DOC_ITEM_TAB INTO DOC_ITEM WHERE NOT ( LIFNR IS INITIAL ).
ENDLOOP.

*--- Populate the IDoc segment’s field with the required data
CLEAR Z1INVRV.
Z1INVRV-LIFNR = DOC_ITEM-LIFNR.		“Store vendor number for filter
Z1INVRV-XBLNR = DOC_HEAD-XBLNR.		“Billing number
IDOC_DATA-SEGNAM = C_INVREV_SEGNAME.	“Segment name
IDOC_DATA-SDATA = Z1INVRV.			“Segment data
APPEND IDOC_DATA.				“Populate IDoc internal table

*--- Move the control data info required for the distribution
IDOC_CONTROL-MESTYP = C_INVREV_MESTYPE.
IDOC_CONTROL-DOCTYP = C_INVREV_IDOC_TYPE.

*--- Call the distribute function with the required parameters
CALL FUNCTION 'MASTER_IDOC_DISTRIBUTE' IN UPDATE TASK
		EXPORTING
			MASTER_IDOC_CONTROL		= IDOC_CONTROL
		TABLES
			COMMUNICATION_IDOC_CONTROL	= T_COMM_CONTROL
			MASTER_IDOC_DATA			= IDOC_DATA
		EXCEPTIONS
			ERROR_IN_IDOC_CONTROL			= 1
			ERROR_WRITING_IDOC_STATUS		= 2
			ERROR_IN_IDOC_DATA			= 3
			SENDING_LOGICAL_SYSTEM_UNKNOWN 	= 4
			OTHERS					= 5.

 

NOTE: For debugging purposes, use transaction WE05 (IDoc overview) to see check your IDoc status, or to see whether an IDoc was created.

Add comment

Before Buying, Compare Prices at Topprice.in

Topprice.in