To accept/process an EDI X12 file, EDI Receive Pipeline is used and in it the actual data (message -- Single ST to SE) are extracted after detaching envelope part (header and trailer) and added to message context. But, ISA06, ISA08, ISA15, GS01, GS02, GS03, GS08, ST03 and ST0 are the only properties which are promoted, whereas ISA_Segment and GS_Segment are written, rest properties are not promoted due to performance reason. This article intends to show how to fetch the ISA and GS segment values using helper class and mapping those to the destination structure.
EDI X12 850 files are received and data from it has to be mapped to the destination structure, also Interchange Control and Functional Group Header values. Destination structure can be XML, Flat file or schema generated from database. In this article destination structure is XML.
using
System;
System.Collections.Generic;
System.Linq;
System.Text;
namespace
SegmentValueFetcher
{
public
class
FetchSegment
static
string
fetchvalue(
segstr,
int
value)
char
elemsptr;
elemsptr = segstr[3];
if
(segstr.Substring(0,2) ==
"GS"
)
elemsptr = segstr[2];
}
var lst = segstr.Split(elemsptr);
return
lst[value];
xmlDoc.LoadXml(
"<ns0:Context xmlns:ns0='http://demoedi.edicontext/'><ISASegment>ISASegment_0</ISASegment><GSSegment>GSSegment_0</GSSegment></ns0:Context>"
);
Contextmsg = xmlDoc;
Contextmsg.ISASegment = EDImsg(EDI.ISA_Segment);
Contextmsg.GSSegment = EDImsg(EDI.GS_Segment);
Figure 6: GS segment mapping
<?
xml
version
=
"1.0"
encoding
"UTF-8"
?>
<
ns0:Order
xmlns:ns0
"http://DemoEDI.XMLOrder"
>
Header
OrderId
>42222001</
Currency
>USD</
BillTo
Name
>DemoPartner1 International</
AdressLine1
>Development</
AddressLine2
>PO Box 2158</
City
>BillTo City</
State
>NJ</
PostalCode
>07096</
Country
>US</
</
ShipTo
>DemoPartner1 INC</
AddressLine1
>Po Box 820O</
>ShipTo City</
>CA</
>930128557</
Details
Item
ItemId
>28-9323-60</
ItemDescription
>C</
Quantity
>2</
UnitPrice
>107.1</
LineNumber
>00001</
UOM
>PK</
>28-9322-25</
>3</
>82.82</
>00002</
Interchange
ISA01
>00</
ISA02
> </
ISA03
ISA04
ISA05
>ZZ</
ISA06
>Partner1 </
ISA07
ISA08
>Partner2 </
ISA09
>130903</
ISA10
>1705</
ISA11
>U</
ISA12
>00503</
ISA13
>000141425</
ISA14
>0</
ISA15
>T</
Functional
GS01
>PO</
GS02
>BTS-SENDER</
GS03
>RECEIVE-APP</
GS04
>20130903</
GS05
>1856</
GS06
>31300</
GS07
>X</
GS08
>##</
>########## </
Author