Electronic Data Interchange

Simple Procedure for Translating a String Document (ASC/X12)


This procedure describes how one can translate an ASC/X12 Purchase Order (850) document represented as a string.  A simple application is created that will read a stringed EDI document 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. Load string document
  4. Traverse data segments

 

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 & "\SampleSefX12_850.SEF", Schema_Standard_Exchange_Format)

 

Load the string document.  Load the string document using the LoadEdiString method of the ediDocument object.  This method will read the string, 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.

' Create the EDI string.
Dim sEdiString As String

' Construct the EDI string
sEdiString = "ISA!00! !00! !12!2132505600 !01!005146311 !960807!1548!U!00401!000000020!0!P!>" & vbCrLf
sEdiString = sEdiString & "GS!PO!52H8P8T00!005146311!19960807!1548!20!X!004010" & vbCrLf
sEdiString = sEdiString & "ST!850!20001" & vbCrLf
sEdiString = sEdiString & "BEG!00!BY!000000101!!19960807" & vbCrLf
sEdiString = sEdiString & "CUR!SE!USD!!!!!004!19960808!1640!010!!2245" & vbCrLf
sEdiString = sEdiString & "REF!PR!ABC-12345-1" & vbCrLf
sEdiString = sEdiString & "PER!OC!Ramil Howe!TE!2132505600!EX!302" & vbCrLf
sEdiString = sEdiString & "PER!OC!!FX!2132504863" & vbCrLf
sEdiString = sEdiString & "FOB!PP!F!L.A.CA" & vbCrLf
sEdiString = sEdiString & "N1!BY!ROCH INC." & vbCrLf
sEdiString = sEdiString & "N3!453 S.Figueroa Street, 4th Floor" & vbCrLf
sEdiString = sEdiString & "N4!Los Angeles!CA!90019" & vbCrLf
sEdiString = sEdiString & "N1!ST!ROCH INC." & vbCrLf
sEdiString = sEdiString & "N3!453 S.Figueroa Street, 4th Floor" & vbCrLf
sEdiString = sEdiString & "N4!Los Angeles!CA!90019" & vbCrLf
sEdiString = sEdiString & "N1!BT!ROCH INC." & vbCrLf
sEdiString = sEdiString & "N3!453 S.Figueroa Street, 4th Floor" & vbCrLf
sEdiString = sEdiString & "N4!Los Angeles!CA!90019" & vbCrLf
sEdiString = sEdiString & "PO1!1!2!EA!191.9!ES!SW!10600!VN!10600*BIPE!MF!ARG" & vbCrLf
sEdiString = sEdiString & "PID!F!!!!BODY WRAP PLUS 35X84X6" & vbCrLf
sEdiString = sEdiString & "QTY!15!20" & vbCrLf
sEdiString = sEdiString & "PKG!F!!!!1EA" & vbCrLf
sEdiString = sEdiString & "SLN!11!!I!10000!PC!1.56!TP!O!VC!P-8750S!UI!09999982001" & vbCrLf
sEdiString = sEdiString & "CTT! 1" & vbCrLf
sEdiString = sEdiString & "SE!23!20001" & vbCrLf
sEdiString = sEdiString & "GE!1!20" & vbCrLf
sEdiString = sEdiString & "IEA!1!000000020" & vbCrLf

' Process the EDI string.
oEdiDoc.LoadEdiString sEdiString

Traverse data segments.  The EDI information read from the string is stored internally as 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
' Only show data elements that have data
If Len(oDataElement.Value) > 0 Then
sDisplayString = sDisplayString & vbTab & "Element: " & oDataElement.ID & " = " & oDataElement.Value & vbCrLf
End If
Next

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

See Also: