EDIdEv - Electronic Data Interchange Development    EDIdEv


 
Sample VB .NET source code using FREDI-NET

  EDI Tool for Developers

Sample EDI X12 810 Invoice translator

	[Run Program]     [Download program]
	'This procedure iterates through each data segment of the EDI file starting from the
	'top.  The data segments are first identified by their Area location, Loop Section,
	'and Segment ID.  Once identified, their data elements are mapped to a form text field
	'or variable (e.g. sValue)
        Dim oEdiDoc As ediDocument
        Dim oSegment As ediDataSegment
        Dim oWarning As ediWarning
        Dim oWarnings As ediWarnings
        Dim sSegmentID As String
        Dim sLoopSection As String
        Dim nArea As String
        Dim sQlfr As String
        Dim sValue As String
        Dim nWarningCount As Integer
        Dim i As Integer
        Dim sEdiString As String
        Dim nItemCount As String
        Dim nSegCount As String
        'Instantiate oEdi Document object
        oEdiDoc.Set(oEdiDoc, New ediDocument)   
        'Load Sef file
        oEdiDoc.LoadSchema("d:\Inetpub\wwwroot\edidev-ca\samples\vbNetTran\bin\810_X12-4010.SEF", 0)
        'Get EDI string from form field
        sEdiString = txtEdiString.Text
        If Len(Trim(sEdiString)) > 0 And Len(Trim(sEdiString)) < 10000 Then
            'Load EDI string
            oEdiDoc.LoadEdiString(sEdiString)
            nSegCount = 0

            'Get first segment of EDI file
            oSegment.Set(oSegment, oEdiDoc.FirstDataSegment())  

            'Iterate through each segment of the EDI file
            Do While Not oSegment Is Nothing

                'Get ID, Loopsection and Area of segment to identify it
                sSegmentID = oSegment.ID
                sLoopSection = oSegment.LoopSection
                nArea = oSegment.Area
                If nArea = 0 Then
                    If sLoopSection = "" Then
                        If sSegmentID = "ISA" Then
                            'return value of data element in position 13 of ISA segment
                            txtICNo.Text = oSegment.DataElementValue(13)
                        ElseIf sSegmentID = "GS" Then
                            'return value of data element in position 6 of GS segment
                            txtGroupNo.Text = oSegment.DataElementValue(6)
                        End If
                    End If
                ElseIf nArea = 1 Then
                    If sLoopSection = "" Then
                        If sSegmentID = "ST" Then
                            txtTsNo.Text = oSegment.DataElementValue(2)
                            nItemCount = 0
                        ElseIf sSegmentID = "BIG" Then
                            txtInvoiceDate.Text = oSegment.DataElementValue(1)
                            txtInvoiceNo.Text = oSegment.DataElementValue(2)
                        ElseIf sSegmentID = "ITD" Then
                            sValue = oSegment.DataElementValue(1)   'Terms Type Code
                            sValue = oSegment.DataElementValue(2)   'Terms Basis Date Code
                        ElseIf sSegmentID = "FOB" Then
                            sValue = oSegment.DataElementValue(1)   'Method of payment
                        End If
                    ElseIf sLoopSection = "N1" Then
                        'Get Qualifier
                        If sSegmentID = "N1" Then
                            sQlfr = oSegment.DataElementValue(1)
                        End If
                        If sQlfr = "ST" Then    'Ship To information
                            If sSegmentID = "N1" Then
                                txtShipTo.Text = oSegment.DataElementValue(2)
                            ElseIf sSegmentID = "N3" Then
                                sValue = oSegment.DataElementValue(1)   'Address Information
                            ElseIf sSegmentID = "N4" Then
                                sValue = oSegment.DataElementValue(1)   'Ship-To City
                                sValue = oSegment.DataElementValue(2)   'Ship-To State
                                sValue = oSegment.DataElementValue(3)   'Ship-To Zip
                            End If
                        ElseIf sQlfr = "BT" Then    'Bill To information
                            If sSegmentID = "N1" Then
                                txtBillTo.Text = oSegment.DataElementValue(2)
 
                           ElseIf sSegmentID = "N3" Then
                                sValue = oSegment.DataElementValue(1)   'Bill-To address
                            ElseIf sSegmentID = "N4" Then
                                sValue = oSegment.DataElementValue(1)   'Bill-To City
                                sValue = oSegment.DataElementValue(2)   'Bill-To State
                                sValue = oSegment.DataElementValue(3)   'Bill-To Zip
                            End If
                        End If
                    End If
                ElseIf nArea = 2 Then
                    If sLoopSection = "IT1" Then
                        If sSegmentID = "IT1" Then
                            sValue = oSegment.DataElementValue(1)
                            sValue = oSegment.DataElementValue(2)   'Quantity
                            sValue = oSegment.DataElementValue(3)   'Unit
                            sValue = oSegment.DataElementValue(4)   'Unit Price
                            nItemCount = nItemCount + 1
                        End If
                    ElseIf sLoopSection = "IT1;PID" Then
                        If sSegmentID = "PID" Then
                            sValue = oSegment.DataElementValue(5)   'Description
                        End If
                    End If
                ElseIf nArea = 3 Then
                    If sLoopSection = "" Then
                        If sSegmentID = "TDS" Then
                            sValue = oSegment.DataElementValue(1)   'Amount
                        ElseIf sSegmentID = "CAD" Then
                            sValue = oSegment.DataElementValue(5)   'Routing
                        ElseIf sSegmentID = "CTT" Then
                            sValue = oSegment.DataElementValue(1)   'Number of line items
                        ElseIf sSegmentID = "SE" Then
                        End If
                    ElseIf sLoopSection = "ISS" Then
                        If sSegmentID = "ISS" Then
                            sValue = oSegment.DataElementValue(1)   'Number of Units Shipped
                            sValue = oSegment.DataElementValue(2)   'Unit
                        End If
                    End If
                End If
                'Get next segment
                oSegment.Set(oSegment, oSegment.Next)   
                nSegCount = nSegCount + 1
            Loop
            txtItemCount.Text = nItemCount
            txtSegmentCount.Text = nSegCount
            'Instantiate warnings object
            oWarnings.Set(oWarnings, oEdiDoc.GetWarnings)   
            'get count of errors from the warnings object
            txtErrCount.Text = oWarnings.Count
        Else
            lblMessage.Text = "Program only accepts valid and short 810 EDI files (less than 10K characters)"
        End If

 

  Home

  Evaluate Framework EDI

  Download Samples

  Purchase

  Support

  About EDIdEv LLC

EDIdEv - EDI Development
www.edidev.com