EDIdEv - Electronic Data Interchange Development

Creating an EDI Translator

This page will describe how to create an EDI translator with the Framework EDI parser.

The following are required:

1.  The EDIdEv Framework EDI component.  Click here to download a full evaluation.

2.  A programming language that supports COM or .NET components such as Visual Basic 6, VB.NET, C++, C#, Delphi, FoxPro, VB Scripts (Access and Excel) etc.

3.  An EDI implementation guideline of your trading partner.  An implementation guideline is a document with a set of rules defining how EDI files should be processed.  For more details, click here.

 

The EDI file structure

Before creating an EDI translator, one must have a basic understanding of the EDI file structure.  For an overview about EDI, please read What Is EDI?

The following points are important to know about an EDI file when developing an EDI translator:

1.  An EDI file is made up of data segments, which in turn are made up of data elements.

2.  An EDI file is sectioned into tables (or areas): the header (or Area 1); the detail (or Area 2); the summary (or Area 3)

3.  A loop is a group of segments, and a loop can have other sub loops under it.

4.  A data segment can be uniquely located by its Area, Loop Section and ID

5.  Instances of segments or loops can be identified by their qualifier or entity identifier respectively.

 

Setting up the Framework EDI component

To install Framework EDI, simply run the installer and then follow the instructions on each screen.  For more details, please read Installing Framework EDI.

Once Framework EDI is installed, the COM or .NET component has to be referenced in the programming language.  Click on the programming language listed below for instructions on referencing the component:

Visual Basic
Delphi
C++
.NET

 

Programming Overview

Below are the steps to take when creating an EDI translator.

  1. Obtain a SEF file that has your trading partner's specifications.

  2. Design a destination database.

  3. Write the program to get data from the EDI file, and save them into the database.

 

The Standard Exchange Format (SEF) file

The purpose of a SEF file is to convey an implementation guideline in a standard format that is parsable so that computer programs can readily import the SEF file and obtain an EDI schema from it.

Visit https://www.edidev.com/SEF.htm to get more details about SEF files.

For the Framework EDI component to correctly process an EDI file, it requires a SEF file that corresponds with the EDI file.  For example, to translate an EDI X12 850 4010 file, it would need an X12 850 4010 SEF file.

Details about editing with the SEF Manager so that you can include your trading partners specifications in a SEF file can be read at  https://www.edidev.com/articles/createIG/HowToCreateIG.html

 

Designing a Database

An EDI file is a medium for data exchange, while a database is a medium for data storage.  So it only makes sense that a database would be the destination for the EDI data after translation (even if it's an intermediate database).

A good database design would be normalized and have a one-to-one link between its fields and the elements of an EDI schema.  For more about the similarities between a database and an EDI file structure, please read  https://www.edidev.com/edi2database.htm.

Below is an example of a database design for an EDI X12 850 4010 schema.

 

Once the SEF file is prepared and the database designed, the next step is to create the program, which basically is mapping the parsed data of the EDI file into the fields of a database.  (The Framework EDI component is an EDI parser, which parses EDI files down to their data elements.)

Overview of the mapping algorithm
  1. Instantiate an EDI document object.

  2. Load the SEF file and EDI file into the EDI document object.

  3. Traverse through each segment of the EDI document object.

  4. Identify and interrogate each segment to get the values from their data elements.

  5. Map data elements to database fields.

 

Instantiating an EDI Document Object
To instantiate an EDI document object of the Framework EDI component that will represent the EDI file in object-oriented programming, do the following:

Dim oEdiDoc As Fredi.ediDocument
Set oEdiDoc = New Fredi.ediDocument

 

Loading the SEF file and EDI file
When the SEF and EDI files are loaded into the EDI document object, the EDI file will get parsed automatically into identifiable units such as data segments and data elements making it possible to reference them during mapping.  To load the SEF and EDI files, do the following:

oEdiDoc.LoadSchema sSefFile, 0
oEdiDoc.LoadEdi sEdiFile

 

Traversing through the EDI file
To traverse through the entire EDI file, we have to start from the top, and then iterate through each segment until there are no longer any segments.  This can be done programmatically by doing the following:

Set oSegment = oEdiDoc.FirstDataSegment
Do While Not oSegment Is Nothing
     Set oSegment = oSegment.Next
Loop

 

Identifying Data Segments
Data segments can be uniquely identified by checking its Area, LoopSection and ID.  Therefore conditions can be included into the traversing loop to locate the data segments that will be interrogated.  For example, to find the BEG segment, which is located in Area1, and is not under any loop, we would add the following lines and conditions into the traversing loop.

Set oSegment = oEdiDoc.FirstDataSegment
Do While Not oSegment Is Nothing
     nArea = oSegment.Area
     sLoopSection = oSegment.LoopSection
     sSegmentID = oSegment.ID


     If nArea = 1 Then
          If sLoopSection = "" Then
              If sSegmentID = "BEG" Then
                   'get data elements
              End If
          End If
     End If

     Set oSegment = oSegment.Next
Loop

 

Mapping Data Elements to Database fields
Once the data segment of interest is located, we interrogate it to obtain the values from its data elements by simply calling the DataElementValue method.  For example, to map the data elements in position 3 and 5 of the BEG segment to their corresponding fields we do the following:

Set oSegment = oEdiDoc.FirstDataSegment
Do While Not oSegment Is Nothing
     nArea = oSegment.Area
     sLoopSection = oSegment.LoopSection
     sSegmentID = oSegment.ID
     If nArea = 1 Then
          If sLoopSection = "" Then
               If sSegmentID = "BEG" Then
                    oRsPOMaster("PONumber").Value = oSegment.DataElementValue(3)
                    oRsPOMaster("PODate").Value = oSegment.DataElementValue(5)
               End If
          End If
     End If
     Set oSegment = oSegment.Next
Loop

 

Identifying a Loop Instance
A loop is a group of segments with inter-dependant data to convey an information.  Loops can be repeated to convey another set of information that has a similar structure.  Each repetition of a loop is called an instance.  An example of loop instances are the the "Bill-To" and "Ship-To" address loop information of the N1 Loop.  To identify the loop instances, we check the code value of their loop entity identifier data element.  To iterate through loop segments, we do the following:

If nArea = 1 Then
     ....
     If sLoopSection = "" Then
          ...
     ElseIf sLoopSection = "N1" Then
          'Obtain the entity identifier of the loop to determine the kind of information the segments in the loop holds
          If sSegmentID = "N1" Then
               sEntity = oSegment.DataElementValue(1)
          End If

          If sEntity = "BT" Then 'Bill To Information loop
               If sSegmentID = "N1" Then
                    oRsPOMaster("BillToName").Value = oSegment.DataElementValue(2)
                    oRsPOMaster("BillToID").Value = oSegment.DataElementValue(4)

               ElseIf sSegmentID = "N3" Then
                    oRsPOMaster("BillToAddress").Value = oSegment.DataElementValue(1)

               ElseIf sSegmentID = "N4" Then
                    oRsPOMaster("BillToCity").Value = oSegment.DataElementValue(1)
                    oRsPOMaster("BillToState").Value = oSegment.DataElementValue(2)
                    oRsPOMaster("BillToZip").Value = oSegment.DataElementValue(3)
               End If

          ElseIf sEntity = "ST" Then 'Ship To Information loop
               If sSegmentID = "N1" Then
                    oRsPOMaster("ShipToName").Value = oSegment.DataElementValue(2)
                    oRsPOMaster("ShipToID").Value = oSegment.DataElementValue(4)

               ElseIf sSegmentID = "N3" Then
                    oRsPOMaster("ShipToAddress").Value = oSegment.DataElementValue(1)

               ElseIf sSegmentID = "N4" Then
                    oRsPOMaster("ShipToCity").Value = oSegment.DataElementValue(1)
                    oRsPOMaster("ShipToState").Value = oSegment.DataElementValue(2)
                    oRsPOMaster("ShipToZip").Value = oSegment.DataElementValue(3)
               End If
          End If
     End If
End If

To download the complete program, please click on frediAccessTran850



Programming an EDI Translator

 

For more examples, please visit https://www.edidev.com/menudownload.htm

 

    Click here to evaluate the Framework EDI     

 

Related Topics