Electronic Data Interchange

Procedure for Changing a Value in a UN/EDIFACT Document


This procedure describes how one can translate a UN/EDIFACT Invoice (INVOIC) document, and change a single data element value.  A simple application is created that will read a single EDI file using a single Standard Exchange Format (SEF) file as an implementation guideline.  This procedure is available only in Dynamic cursor mode, which is the default operation mode for Framework EDI (FREDI).  In Dynamic cursor, an internal hierarchical tree is created of data segments.  The hierarchical relationship between the data segments is defined in the SEF guideline, and the tree is created in the same hierarchical relationship.  In this procedure, a single data element value will be modified and the EDI document will then be saved to a file, which should reflect the changed value.  The procedure is as follows:

  1. Create an instance of ediDocument object.
  2. Specify implementation guidelines
  3. Specify Terminators
  4. Load EDI document
  5. Change data element value
  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 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"

Change the data element value.  In dynamic cursor, the data segments are organized in a hierarchical relationship as defined in the SEF file.  The data segments contain data elements that hold the value, and this value can be changed.  To change a value in a data element, use the DataElementValueByPos property and pass a string that describes a hierarchy (please see Hierarchical String Syntax) to access the data segment and the data element whose value we want to change by simply assigning a new value.  Save the document to a file, and view its contents to verify the changed value.

' Get the data segment
Set oDataSegment = oEdiDoc.FirstDataSegment

' Modify the data element value.
oDataSegment.DataElementValueByPos("\UNB\UNH\NAD(1)\NAD<C080,3036>") = "New Company Name"

' Save to an output file.
oEdiDoc.Save App.Path & "\Output.txt"

Sample

Sample program to translate UN/EDIFACT EDI file and change a value