Electronic Data Interchange

Procedure for Translating a UN/EDIFACT Document


This procedure describes how one can translate a UN/EDIFACT Invoice (INVOIC) document.  A simple application is created that will read a single EDI file using a single Standard Exchange Format (SEF) file as an implementation guideline, and displays all the data segments and its elements to a list box.  The procedure is as follows:

  1. Create an instance of ediDocument object.
  2. Specify implementation guidelines
  3. Specify Terminators
  4. Load EDI document
  5. Traverse data segments
  6. Sample

 

Example in Visual Basic

This example will use the following:

 

Create an instance of ediDocument.  The ediDocument object is the top level application instance for Framework EDI (FREDI).  This object is the topmost object in the object model hierarchy of FREDI.  This instance is always created at the start of a program.

Dim oEdiDoc As Fredi.ediDocument

Set oEdiDoc = New Fredi.ediDocument

Specify implementation guidelines.  Specify the implementation guidelines using the LoadSchema method of the ediDocument object.  In this example, the standard reference library will not be used so we disable its use by setting the EnableStandardReference property to false in the ediSchemas object.

Dim oSchemas As Fredi.ediSchemas
Dim oSchema As Fredi.ediSchema

' Disable standard reference library.
Set oSchemas = oEdiDoc.GetSchemas
oSchemas.EnableStandardReference = False

Set oSchema = oEdiDoc.LoadSchema(App.Path & "\SampleEdifact_INVOIC.SEF", Schema_Standard_Exchange_Format)

 

Specify Terminators.  Before loading the EDI file, specify the terminators used to separate the semantic objects in the document.  This is necessary for documents that do not have a UNA segment.  The UNA segment contain the separation characters, which FREDI will use if the UNA segment is present.

' For UN/EDIFACT specify separators if there is no UNA segment in file.
oEdiDoc.SegmentTerminator = vbCrLf
oEdiDoc.ElementTerminator = "+"
oEdiDoc.CompositeTerminator = ":"
oEdiDoc.ReleaseIndicator = "?"

Load EDI document.  Load the EDI document using the LoadEdi method of the ediDocument object.  This method will read the EDI file, and verify its correctness using the implementation guideline in the SEF file specified previously in the program using the LoadSchema method.  The data is stored and organized internally in a hierarchical tree.

' Load EDI document normally.
oEdiDoc.LoadEdi App.Path & "\SampleEdifact_INVOIC.EDI"

Traverse data segments.  The data segments of the EDI file that has been read using the LoadEdi method are stored internally and are organized in a hierarchical tree.  The hierarchical relationship between the semantic objects are defined in the SEF implementation guideline, and the data segments are organized in this same hierarchical relationship.  To traverse the data segments, access the first data segment in the tree using the FirstDataSegment of the ediDocument, and moving down the tree accessing subsequent data segments using NextDataSegment.

' Traverse all the data segments in the EDI document and extract the value in the its individual
' data elements.

Set oDataSegment = oEdiDoc.FirstDataSegment

While Not oDataSegment Is Nothing

Dim oDataElements As Fredi.ediDataElements
Dim oDataElement As Fredi.ediDataElement

sDisplayString = sDisplayString & "Segment: " & oDataSegment.ID & vbCrLf

' Get the data elements collection of the data segment.
Set oDataElements = oDataSegment.DataElements

' Get the value of the individual data elements
For Each oDataElement In oDataElements
If oDataElement.IsComposite Then
' Composite element contain sub elements.

Dim oSubElement As Fredi.ediDataElement

sDisplayString = sDisplayString & vbTab & "Composite: " & oDataElement.ID & vbCrLf

' Get the sub elements collection of the composite element.
Set oDataElements = oDataElement.DataElements

' Get the value of the individual data elements
For Each oSubElement In oDataElements
' Only show data elements that have data
If Len(oSubElement.Value) > 0 Then
sDisplayString = sDisplayString & vbTab & vbTab & "Sub Element: " & oSubElement.ID & " = " & oSubElement.Value & vbCrLf
End If
Next
Else
' Only show data elements that have data
If Len(oDataElement.Value) > 0 Then
sDisplayString = sDisplayString & vbTab & "Element: " & oDataElement.ID & " = " & oDataElement.Value & vbCrLf
End If
End If
Next

' Get the next data segment in the document.
Set oDataSegment = oEdiDoc.NextDataSegment
Wend

Sample

Sample program to translate UN/EDIFACT EDI file