Managing Transmission Responses


Some EDI specifications define the interchanges and messages to be used to notify the EDI sender about transmission status, from initial receipt of the transmission to the errors, if any, encountered in the EDI data stream received from the EDI sender. For example:

As described in Response Element, the Analyze method generates dialect-specific transmission responses as Receipt and Acknowledgement elements in the EDI analysis report.

This section covers the following topics:

Receipt Element Example

Here is an example of the Receipt element from the analysis report created using the Analyze method to convert the sample file threemsgs.x12 to XML:

        <Receipt> 
            <X12>
                <ISA>
                    <ISA01>00</ISA01>
                    <ISA03>00</ISA03>
                    <ISA05>01</ISA05>
                    <ISA06>5151515151</ISA06>
                    <ISA07>01</ISA07>
                    <ISA08>1515151515</ISA08>
                    <ISA11>^</ISA11>
                    <ISA12>00403</ISA12>
                    <ISA13>0</ISA13>
                    <ISA14>0</ISA14>
                    <ISA15>P</ISA15>
                    <ISA16>*</ISA16>
                </ISA>
                <TA1>
                    <TA101>32123</TA101>
                    <TA102>041201</TA102>
                    <TA103>1217</TA103>
                    <TA104>A</TA104>
                    <TA105>000</TA105>
                </TA1>
                <IEA/>
            </X12>
        </Receipt>  

The specific structure of the Receipt element varies based on the dialect, and contents, of the EDI stream being converted. In this example:

Acknowledgement Element Example

Following is an example of the Acknowledgement element from the same analysis report created using the Analyze method to convert the sample file threemsgs.x12 to XML. Note that is has been abbreviated for formatting considerations.

        <Acknowledgement> 
            <X12>
                <ISA> … </ISA>
                <GS> … </GS>
                <TS_997>
                    <ST>
                        <ST01>997</ST01>
                        <ST02>0</ST02>
                    </ST>
                    <AK1>
                        <AK101>CT</AK101>
                        <AK102>128</AK102>
                    </AK1>
                    <AK2>
                        <AK201>831</AK201>
                        <AK202>00128001</AK202>
                    </AK2>
                    <AK5> … </AK5>
                    <AK2>
                        <AK201>831</AK201>
                        <AK202>00128002</AK202>
                    </AK2>
                    <AK3> … </AK3>
                    <AK4> 
                        <AK401> … </AK401>
                        <AK402>782</AK402>
                        <AK403>6</AK403>
                        <AK404>ZZZZ</AK404>
                    </AK4>
                    <AK5> … </AK5>
                    <AK2> … </AK2>
                        <AK201>831</AK201>
                        <AK202>00128003</AK202>
                    <AK5> … </AK5>
                    <AK9>
                        <AK901>P</AK901>
                        <AK902>3</AK902>
                        <AK903>3</AK903>
                        <AK904>2</AK904>
                    </AK9>
                    <SE/>
                </TS_997>
                <GE/>
                <IEA/>
            </X12>
        </Acknowledgement>  

Converting Response Messages to EDI

Since transmission responses are structured as XML, they need to be converted to EDI before they can be returned to the EDI sender. This example shows how to

To see a complete example application that converts both Receipt and Acknowledgement responses to EDI, see Example 14.

Invoking the Analyze Method

To get started, the EDI XML Converter is used to initiate the conversion of the source EDI document, threemsgs.x12 to EDI:

		try { 
			Source ediSource = new UriSource(uriString + "threemsgs.x12"); 
			ConvertToXml toXml = factory.CreateConvertToXml("converter:EDI"); 

Next the Analyze method is used to generate the analysis report and saves the output to report.xml:

			Result reportResult = new UriResult("report.xml"); 
			toXml.Analyze(ediSource, reportResult); 

See Receipt Element Example for a sample of the analysis report, report.xml.

Converting the Source EDI

In this section of code, the analysis report is used as input to convert the EDI stream to XML. Any errors in the EDI stream are recorded in the analysis report, which is used by ConvertToXml as a filter so that only valid EDI messages are converted to XML. Here, the valid EDI is written to an XML document, twomsgs.xml.

	Source reportSource = new UriSource(new FileInfo("report.xml").FullName); 
	Result xmlResult = new UriResult("twomsgs.xml"); 
	toXml.Convert(ediSource, xmlResult, reportSource); 

Locating Response Messages

The EDI analysis report is used again, this time as the source for the EDI transmission response messages that have been generated in the Receipt and Acknowledgement elements in the XML report. It is these elements whose contents will be converted to EDI for transmission back to the EDI sender. Here the report is opened with an instance of XmlReader.

XmlReader rdr = XmlReader.Create("report.xml"); 

Once the XmlReader object is created, we can read through the analysis report, skipping first to the Receipt element, then to the X12 element:

			while(rdr.Read()) { 
				if (   rdr.NodeType == XmlNodeType.Element 
				    && rdr.LocalName == "Receipt") 
					break; 
			} 
			while(rdr.Read()) { 
				if (   rdr.NodeType == XmlNodeType.Element 
				    && rdr.LocalName == "X12") 
					break; 
			} 

(For a refresher of the Receipt element structure, see Receipt Element Example.)

Converting the Receipt Element to EDI

Once the Receipt element is located in the analysis report, it can be converted to EDI for transmission back to the EDI sender. Note that the converter: property is specified as ED.

ConvertFromXml converter = factory.CreateConvertFromXml("converter:EDI"); 
Source responseSource = new XmlReaderSource(rdr); 
Result receiptResult = new UriResult("receipt.x12"); 
converter.Convert(responseSource, receiptResult); 

The resulting EDI is written to the file, receipt.x12, which contains the following:

ISA+00+          +00+          +01+5151515151     
+01+1515151515     +090818+1110+^+00403+000000000+0+P+*' 
TA1+000032123+041201+1217+A+000' 
IEA+0+000000000' 

Notice that the IEA segment (Interchange Control Trailer), which was represented in the original XML conversion of the source EDI document as an empty element (<IEA/) has been automatically computed by the EDI XML Converter and now includes values for the Number of Included Functional Groups (IEA01) and Interchange Control Number (IEA02) segments.

Sending Responses to the EDI Sender

When you send a response to an EDI sender, you typically must provide each interchange with a unique identifier – for X12, for example, this is the Interchange Control Number (ISA12 ) segment; for EDIFACT, this is the Interchange Control Reference (UNB05) segment.

You can perform this task as part of the application code that extracts the Receipt or Acknowledgement element from the analysis report; it is expected that the generation of a unique identifier is handled elsewhere.

Example

This simple XSLT locates the Interchange Control Header (ISA) segment, replaces the value of the Interchange Control Number (ISA12) segment with 1000, and converts the node to EDI for transmission to the EDI sender.

<?xml version='1.0'?> 
<xsl:stylesheet version="1.0" xmlns:xsl=
"http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="xml" indent="yes"/>
    <xsl:param name="InterchangeControlID"/>

    <xsl:template match="/">
        <xsl:apply-templates select="/AnalyzeReport/Response/Receipt/X12"/>
    </xsl:template>

    <xsl:template match="*">
        <xsl:copy>
            <xsl:apply-templates/>
        </xsl:copy>
    </xsl:template>

    <xsl:template match="ISA12">
        <ISA12><xsl:value-of select="$InterchangeControlID"/></ISA12>
    </xsl:template>
        
</xsl:stylesheet>