Edi to xml using multiple X12 transactions as an input

30 views
Skip to first unread message

Carlos Rodolfo Schrader Garcia Escobar

unread,
May 11, 2021, 9:46:49 AMMay 11
to Smooks Users
Hi im trying to handle Edi(x12 specification)with multiple transactions to Xml conversion, im using loops to solve this situation where i have a purchase Order (850) and a Functional acknowledge(997) in the same file in that order, this is what i have done:

X12 File
ISA*00* *00* *ZZ*CVS *01*Supplier ID *130212*1608*U*00401*000010952*0*P*^~GS*PO*CVS*Supplier ID *20130212*1608*5850*X*004010~ST*850*179960~BEG*00*NE*9999999**20130212~FOB*PP*US*free from text Desctiption*QualifierCode*TradeTerms~DTM*002*20210605~DTM*010*20210528~DTM*177*20130606~N9*L1*PO COMMENTS*Free form description~MSG*THIS PO SUBJECT TO THE TERMS AND CONDITIONS FOUND ON CVS SUPPLIERS WEBSITE~N1*ST*someone*54*Y101~N2*free from name ~N4*WAVERLY****NY*14892~TD5****H*~N1*bt*billName*54*Y101~N2*free fromname~N4*WAVERLY****NY*14892~TD5****H*~PO1**1*CA*57.6*CP*UA*999999*IN*099999999999*VN*099999999991*************UK*125438245689784~PID*F****FreeTextDescription~SAC*A*C1310******0****~SAC*C*C1310******0****~CTT*1**75.0*UN*222*CF~AMT*TT*4320~SE*20*179960~GE*38*5850~GS*Ak*CVSD*Supplier ID *20130212*1608*5850*X*004010~ST*997*179960~AK1*Ak*5850~AK2*997*179960~AK5*A~AK9*A*38*1*1~SE*00*SA~GE*38*5850~IEA*1*000010952~

mapping  for smooks:

<?xml version="1.0" encoding="UTF-8"?>
<medi:edimap xmlns:medi="http://www.milyn.org/schema/edi-message-mapping-1.6.xsd">

<medi:description name="DVD Order" version="1.0"/>

<medi:delimiters segment="~" field="*" component="^" sub-component="&#10;"/>

<medi:segments xmltag="purchase-order">

<medi:segment segcode="ISA" xmltag="interchange-Control-Header" maxOccurs="1" minOccurs="1">
<medi:field xmltag="Authorization-Information-Qualifier"/>
<medi:field xmltag="Authorization-Information"/>
<medi:field xmltag="Security-Information-Qualifier"/>
<medi:field xmltag="Security-Information"/>
<medi:field xmltag="Interchange-ID-Qualifier"/>
<medi:field xmltag="Interchange-Sender-ID"/>
<medi:field xmltag="Interchange-ID-Qualifier"/>
<medi:field xmltag="Interchange-Receiver-ID"/>
<medi:field xmltag="Interchange-Date"/>
<medi:field xmltag="Interchange-Time"/>
<medi:field xmltag="Interchange-Control-Standards-Identifier"/>
<medi:field xmltag="Interchange-Control-Version-Number"/>
<medi:field xmltag="Interchange-Control-Number"/>
<medi:field xmltag="Acknowledgement-Requested"/>
<medi:field xmltag="Usage-Indicator"/>
<medi:field xmltag="Component-Element-Separator"/>
</medi:segment>

<medi:segmentGroup xmltag="POLoop" >

<medi:segment segcode="GS" xmltag="Group-Header" >
<medi:field xmltag="Functional-Code-Identifier"/>
<medi:field xmltag="Application-Senders-Code"/>
<medi:field xmltag="Application-Receivers-Code"/>
<medi:field xmltag="Date"/>
<medi:field xmltag="Time"/>
<medi:field xmltag="Group-Control-Number"/>
<medi:field xmltag="Responsible-Agency-Code"/>
<medi:field xmltag="Version-Release-Industry-Identifier-Code"/>
</medi:segment>

<medi:segment segcode="ST" xmltag="transaction-Set" maxOccurs="10" >
<medi:field xmltag="transaction-code"/>
<medi:field xmltag="transaction-set-control-number"/>
</medi:segment>

<medi:segment segcode="BEG" xmltag="beginning-segment" maxOccurs="1">
<medi:field xmltag="purpose-code"/>
<medi:field xmltag="Po-type"/>
<medi:field xmltag="Po-Number"/>
<medi:field xmltag="empty"/>
<medi:field xmltag="Date"/>
</medi:segment>

<medi:segment segcode="FOB" xmltag="Fob-Instructions" maxOccurs="1">
<medi:field xmltag="shipment-Method-Payment"/>
<medi:field xmltag="Location-Qualifier"/>
<medi:field xmltag="Description"/>
<medi:field xmltag="Transportation-Terms-Qualifier-Code"/>
<medi:field xmltag="Transportation-Terms-Code"/>
</medi:segment>

<medi:segment segcode="DTM" xmltag="Date-Time-Reference" maxOccurs="10">
<medi:field xmltag="date-Time-qualifier" required="true"/>
<medi:field xmltag="date" required="true"/>
</medi:segment>

<medi:segmentGroup xmltag="N9Loop" maxOccurs="1000">
<medi:segment segcode="N9" xmltag="Reference-Identification" maxOccurs="1">
<medi:field xmltag="Reference-Identification-Qualifier" required="false"/>
<medi:field xmltag="Reference-Identification" required="false"/>
<medi:field xmltag="Free-form-Description" required="false"/>
</medi:segment>

<medi:segment segcode="MSG" xmltag="Message-Text" maxOccurs="1000">
<medi:field xmltag="Free-Form-Message-Text" required="true"/>
</medi:segment>
</medi:segmentGroup>

<medi:segmentGroup xmltag="N1Loop" maxOccurs="200">
<medi:segment segcode="N1" xmltag="Name" maxOccurs="4">
<medi:field xmltag="Entity-Identifier-Code" required="true"/>
<medi:field xmltag="Name" required="true"/>
<medi:field xmltag="Identification-Code-Qualifier" required="true"/>
<medi:field xmltag="Identification-Code" required="true"/>
</medi:segment>

<medi:segment segcode="N2" xmltag="Additional-Name-Information" maxOccurs="4">
<medi:field xmltag="Name" required="true"/>
</medi:segment>

<medi:segment segcode="N4" xmltag="Geographic-Location" maxOccurs="4">
<medi:field xmltag="City-Name" required="true"/>
<medi:field xmltag="n402" required="false"/>
<medi:field xmltag="n403" required="false"/>
<medi:field xmltag="n404" required="false"/>
<medi:field xmltag="location-qualifier" required="true"/>
<medi:field xmltag="Location-Identifier" required="true"/>
</medi:segment>

<medi:segment segcode="TD5" xmltag="Carrier-Details" maxOccurs="4">
<medi:field xmltag="TD01" required="false"/>
<medi:field xmltag="TD02" required="false"/>
<medi:field xmltag="TD03" required="false"/>
<medi:field xmltag="Transportation-Method" required="true"/>
<medi:field xmltag="TD05" required="false"/>
</medi:segment>
</medi:segmentGroup>

<medi:segmentGroup xmltag="PO1Loop" maxOccurs="100000">

<medi:segment segcode="PO1" xmltag="Baseline-Item-Data" maxOccurs="1">
<medi:field xmltag="PO101" required="false"/>
<medi:field xmltag="Quantity-Ordered" required="false"/>
<medi:field xmltag="Unit-Measurement" required="false"/>
<medi:field xmltag="Unit-Price" required="true"/>
<medi:field xmltag="Basis-of-Unit-Price-Code" required="true"/>
<medi:field xmltag="Product-Service-ID-Qualifier" required="true"/>
<medi:field xmltag="Product-Service-ID" required="true"/>
<medi:field xmltag="Product-Service-ID-Qualifier" required="false"/>
<medi:field xmltag="Product-Service-ID" required="false"/>
<medi:field xmltag="PO110" required="false"/>
<medi:field xmltag="PO111" required="false"/>
<medi:field xmltag="PO112" required="false"/>
<medi:field xmltag="PO113" required="false"/>
<medi:field xmltag="PO114" required="false"/>
<medi:field xmltag="PO115" required="false"/>
<medi:field xmltag="PO116" required="false"/>
<medi:field xmltag="PO117" required="false"/>
<medi:field xmltag="PO118" required="false"/>
<medi:field xmltag="PO119" required="false"/>
<medi:field xmltag="PO120" required="false"/>
<medi:field xmltag="PO121" required="false"/>
<medi:field xmltag="PO122" required="false"/>
<medi:field xmltag="PO123" required="false"/>
<medi:field xmltag="Product-Service-ID-Qualifier" required="true"/>
<medi:field xmltag="Product-Service-D" required="true"/>
</medi:segment>
</medi:segmentGroup>

<medi:segmentGroup xmltag="PIDLoop" maxOccurs="1000">

<medi:segment segcode="PID" xmltag="Product-Item-Description" maxOccurs="1">
<medi:field xmltag="Item-Description-Type" required="true"/>
<medi:field xmltag="PID02" required="false"/>
<medi:field xmltag="PID03" required="false"/>
<medi:field xmltag="PID04" required="false"/>
<medi:field xmltag="Description" required="true"/>
</medi:segment>
</medi:segmentGroup>

<medi:segmentGroup xmltag="SACLoop" maxOccurs="25">
<medi:segment segcode="SAC" xmltag="Allowance-or-Charge-Information" maxOccurs="4">
<medi:field xmltag="Allowance-or-Charge-Indicator" required="true"/>
<medi:field xmltag="Service-Promotion-Allowance-or-Charge-Code" required="true"/>
<medi:field xmltag="SAC03" required="false"/>
<medi:field xmltag="SAC04" required="false"/>
<medi:field xmltag="SAC05" required="false"/>
<medi:field xmltag="SAC06" required="false"/>
<medi:field xmltag="SAC07" required="false"/>
<medi:field xmltag="Rate" required="false"/>
<medi:field xmltag="SAC9" required="false"/>
<medi:field xmltag="SAC10" required="false"/>
<medi:field xmltag="SAC11" required="false"/>
<medi:field xmltag="Allowance-Charge-Method-f-Handling-Code" required="false"/>
</medi:segment>

</medi:segmentGroup>

<medi:segmentGroup xmltag="CTTLoop" maxOccurs="1">

<medi:segment segcode="CTT" xmltag="Transaction-Totals" maxOccurs="1">
<medi:field xmltag="Number-of-Line-Items" required="true"/>
<medi:field xmltag="CTT02" required="false"/>
<medi:field xmltag="Weight" required="true"/>
<medi:field xmltag="Unit-or-Basis-for-Measurement-Code" required="false"/>
<medi:field xmltag="Volume" required="false"/>
<medi:field xmltag="Unit-or-Basis-for-Measurement-Code" required="false"/>
</medi:segment>

<medi:segment segcode="AMT" xmltag="Monetary-Amount" maxOccurs="1">
<medi:field xmltag="Amount-Qualifier-ode" required="true"/>
<medi:field xmltag="Monetary-Amount" required="true"/>
</medi:segment>

<medi:segment segcode="SE" xmltag="Transaction-Set-Trailer" maxOccurs="10">
<medi:field xmltag="Number-of-Included-Segments" required="true"/>
<medi:field xmltag="Transaction-Set-Control-Number" required="true"/>
</medi:segment>
</medi:segmentGroup>

<medi:segment segcode="GE" xmltag="functional-group-end" maxOccurs="1" minOccurs="1">
<medi:field xmltag="GE01" required="true"/>
<medi:field xmltag="GE2" required="true"/>
</medi:segment>
</medi:segmentGroup>

<!-- Acknowledge Transaction -->

<medi:segmentGroup xmltag="ACKLoop">

<medi:segment segcode="GS" xmltag="Group-Header" maxOccurs="1" minOccurs="1">
<medi:field xmltag="Functional-Code-Identifier"/>
<medi:field xmltag="Application-Senders-Code"/>
<medi:field xmltag="Application-Receivers-Code"/>
<medi:field xmltag="Date"/>
<medi:field xmltag="Time"/>
<medi:field xmltag="Group-Control-Number"/>
<medi:field xmltag="Responsible-Agency-Code"/>
<medi:field xmltag="Version-Release-Industry-Identifier-Code"/>
</medi:segment>

<medi:segment segcode="ST" xmltag="transaction-Set" maxOccurs="10">
<medi:field xmltag="transaction-code"/>
<medi:field xmltag="transaction-set-control-number"/>
</medi:segment>

<medi:segment segcode="AK1" xmltag="Functional-Group-Response-Header" maxOccurs="1">
<medi:field xmltag="Functional-Identifier-Code" required="true"/>
<medi:field xmltag="Group-Control-Number" required="true"/>
</medi:segment>

<medi:segment segcode="AK2" xmltag="Transaction-Set-Response-Header" maxOccurs="1">
<medi:field xmltag="Transaction-Set-Identifier-Code"/>
<medi:field xmltag="Transaction-Set-Control-Number"/>
</medi:segment>

<medi:segment segcode="AK5" xmltag="Transaction-Set-Response-Trailer" maxOccurs="1">
<medi:field xmltag="Transaction-Set-Acknowledgment-Code"/>
</medi:segment>


<medi:segment segcode="AK9" xmltag="Functional-Group-Response-Trailer" maxOccurs="1">
<medi:field xmltag="Functional-Group-Acknowledge-Code"/>
<medi:field xmltag="Number-of-Transaction-Sets-Included"/>
<medi:field xmltag="Number-of-Received-Transaction-Sets"/>
<medi:field xmltag="Number-of-Accepted-Transaction-Sets"/>
</medi:segment>

<medi:segment segcode="SE" xmltag="Transaction-Set-Trailer" maxOccurs="10">
<medi:field xmltag="Number-of-Included-Segments" required="true"/>
<medi:field xmltag="Transaction-Set-Control-Number" required="true"/>
</medi:segment>

<medi:segment segcode="GE" xmltag="functional-group-end" maxOccurs="1" minOccurs="1">
<medi:field xmltag="GE01" required="true"/>
<medi:field xmltag="GE2" required="true"/>
</medi:segment>

</medi:segmentGroup>

<medi:segment segcode="IEA" xmltag="interchange-control-trailer" maxOccurs="1" minOccurs="1">
<medi:field xmltag="functional-groups-involved" required="true"/>
<medi:field xmltag="control-numbers" required="true"/>
</medi:segment>

</medi:segments>

</medi:edimap>

this configuration actually works but when i modify the X12 File to have the functional acknowledge (997) first and then the Purchase order ( 850) like this

X12 modified:
ISA*00* *00* *ZZ*CVS *01*Supplier ID *130212*1608*U*00401*000010952*0*P*^~GS*Ak*CVSD*Supplier ID *20130212*1608*5850*X*004010~ST*997*179960~AK1*Ak*5850~AK2*997*179960~AK5*A~AK9*A*38*1*1~SE*00*SA~GE*38*5850~GS*PO*CVS*Supplier ID *20130212*1608*5850*X*004010~ST*850*179960~BEG*00*NE*9999999**20130212~FOB*PP*US*free from text Desctiption*QualifierCode*TradeTerms~DTM*002*20210605~DTM*010*20210528~DTM*177*20130606~N9*L1*PO COMMENTS*Free form description~MSG*THIS PO SUBJECT TO THE TERMS AND CONDITIONS FOUND ON CVS SUPPLIERS WEBSITE~N1*ST*someone*54*Y101~N2*free from name ~N4*WAVERLY****NY*14892~TD5****H*~N1*bt*billName*54*Y101~N2*freefromname~N4*WAVERLY****NY*14892~TD5****H*~PO1**1*CA*57.6*CP*UA*999999*IN*099999999999*VN*099999999991*************UK*125438245689784~PID*F****FreeTextDescription~SAC*A*C1310******0****~SAC*C*C1310******0****~CTT*1**75.0*UN*222*CF~AMT*TT*4320~SE*20*179960~GE*38*5850~IEA*1*000010952~

and using the same configuration with smooks im getting this error

EDI message processing failed [DVD Order][1.0].  Must be a minimum of 1 instances of segment [BEG].  Currently at segment number 4.

is there any way to process many transaction in any order in the same file and parse it to Xml or to Java using smooks ?



Jeff Bradley

unread,
May 11, 2021, 11:32:36 AMMay 11
to Smooks Users
I would set the ST segment `maxOccurs` attribute to "unbounded" so that it is a segment group. Then, within that segment group, you can set the `minOccurs` attribute of each element to "0". 

Using Smooks version 2 and and XSD, it would look like this contrived example, where the transaction set could contain either B10 or AK1 elements, which themselves contain their respective elements.

Again, sorry for the contrived example and for the XSD. I did what i could with the time I have :)

<xsd:element name="transaction-sets">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="transaction-set" dfdl:initiator="ST" maxOccurs="unbounded">
<xsd:complexType>
<xsd:sequence>
<xsd:sequence dfdl:ref="ibmEdiFmt:EDISegmentFormat">
<xsd:sequence dfdl:ref="ibmEdiFmt:EDISegmentSequenceFormat">
<xsd:element name="identifier-code" type="xsd:string" />
<xsd:element name="sequence" type="xsd:string" />
</xsd:sequence>
</xsd:sequence>
<xsd:element name="shipment-status" dfdl:initiator="B10" minOccurs="0">
<xsd:complexType>
<xsd:sequence>
<xsd:sequence dfdl:ref="ibmEdiFmt:EDISegmentFormat">
<xsd:sequence dfdl:ref="ibmEdiFmt:EDISegmentSequenceFormat">
<xsd:element name="reference-identification" type="xsd:string" />
<xsd:element name="shipment-identification-number" type="xsd:string" />
<xsd:element name="scac" type="xsd:string" />
</xsd:sequence>
</xsd:sequence>
<xsd:element name="reference-numbers">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="reference-number" dfdl:initiator="L11" maxOccurs="unbounded">
<xsd:complexType>
<xsd:sequence dfdl:ref="ibmEdiFmt:EDISegmentFormat">
<xsd:sequence dfdl:ref="ibmEdiFmt:EDISegmentSequenceFormat">
<xsd:element name="reference-identification" type="xsd:string" />
<xsd:element name="reference-qualifier" type="xsd:string" />
</xsd:sequence>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="example" dfdl:initiator="XXX" minOccurs="0">
<xsd:complexType>
<xsd:sequence>
<xsd:sequence dfdl:ref="ibmEdiFmt:EDISegmentFormat">
<xsd:sequence dfdl:ref="ibmEdiFmt:EDISegmentSequenceFormat">
<xsd:element name="reference-identification" type="xsd:string" />
<xsd:element name="shipment-identification-number" type="xsd:string" />
<xsd:element name="scac" type="xsd:string" />
</xsd:sequence>
</xsd:sequence>
<xsd:element name="reference-numbers">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="reference-number" dfdl:initiator="L11" maxOccurs="unbounded">
<xsd:complexType>
<xsd:sequence dfdl:ref="ibmEdiFmt:EDISegmentFormat">
<xsd:sequence dfdl:ref="ibmEdiFmt:EDISegmentSequenceFormat">
<xsd:element name="reference-identification" type="xsd:string" />
<xsd:element name="reference-qualifier" type="xsd:string" />
</xsd:sequence>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:sequence dfdl:initiator="LX" dfdl:ref="ibmEdiFmt:EDISegmentFormat">
<xsd:sequence dfdl:ref="ibmEdiFmt:EDISegmentSequenceFormat">
<xsd:element name="assigned-number" type="xsd:string" />
</xsd:sequence>
</xsd:sequence>
<xsd:sequence dfdl:initiator="AT7" dfdl:ref="ibmEdiFmt:EDISegmentFormat">
<xsd:sequence dfdl:ref="ibmEdiFmt:EDISegmentSequenceFormat">
<xsd:element name="indicator-code" type="xsd:string" />
<xsd:element name="reason-code-1" type="xsd:string" />
<xsd:element name="status-code" type="xsd:string" />
<xsd:element name="reason-code-2" type="xsd:string" />
<xsd:element name="date" type="xsd:string" />
<xsd:element name="time" type="xsd:string" />
<xsd:element name="time-code" type="xsd:string" />
</xsd:sequence>
</xsd:sequence>
<xsd:sequence dfdl:initiator="AT8" dfdl:ref="ibmEdiFmt:EDISegmentFormat">
<xsd:sequence dfdl:ref="ibmEdiFmt:EDISegmentSequenceFormat">
<xsd:element name="weight-qualifier" type="xsd:string" />
<xsd:element name="weight-unit-code" type="xsd:string" />
<xsd:element name="weight" type="xsd:string" />
<xsd:element name="lading-quantity" type="xsd:string" />
</xsd:sequence>
</xsd:sequence>
<xsd:sequence dfdl:initiator="SE" dfdl:ref="ibmEdiFmt:EDISegmentFormat">
<xsd:sequence dfdl:ref="ibmEdiFmt:EDISegmentSequenceFormat">
<xsd:element name="number-of-segments" type="xsd:string" />
<xsd:element name="control-number" type="xsd:string" />
</xsd:sequence>
</xsd:sequence>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>

Carlos Rodolfo Schrader Garcia Escobar

unread,
May 12, 2021, 9:12:43 AMMay 12
to Smooks Users
thank you so much, im using smoks 1.7.1 and i did the modifications and still not work, i guess that i will upgrade to version 2 to be able of archieve this


Regards !
Reply all
Reply to author
Forward
0 new messages