clear
    
    * CREATES EDI DOCUMENT OBJECT
    oEdiDoc = createobject("fredi.ediDocument")
 
    * THIS MAKES CERTAIN THAT FREDI ONLY USES THE SEF FILE PROVIDED, AND THAT IT DOES 
    * NOT USE ITS BUILT-IN STANDARD REFERENCE TABLE TO TRANSLATE THE EDI FILE.
    oSchemas = oEdiDoc.GetSchemas
    oSchemas.EnableStandardReference = .F.
 
    * THIS OPTIONS STOPS FREDI FROM KEEPING ALL THE SEGMENTS IN MEMORY
    oEdiDoc.CursorType = 1
 
    * LOADS THE SEF FILE
    oEdiDoc.LoadSchema("211_003070.SEF", 0)
 
    * LOADS THE EDI FILE
    oEdiDoc.LoadEdi("211.txt")
 
    * GETS THE FIRST DATA SEGMENT
    oSegment = oEdiDoc.FirstDataSegment
 
    * LOOP THAT WILL TRAVERSE THRU EDI FILE FROM TOP TO BOTTOM
    do while !isnull(oSegment)
 
        && DATA SEGMENTS WILL BE IDENTIFIED BY THEIR ID, THE LOOP SECTION AND AREA
        && (OR TABLE) NUMBER THAT THEY ARE IN.
        sSegmentID = oSegment.ID
        sLoopID = oSegment.LoopSection
        nArea = oSegment.Area
 
        do case
        case nArea = 0
            do case
            case sLoopID == ""
                do case
                case sSegmentID = "ISA"
                    sValue = oSegment.DataElementValue(1)     && Authorization Information Qualifier
                    sValue = oSegment.DataElementValue(2)     && Authorization Information
                    sValue = oSegment.DataElementValue(3)     && Security Information Qualifier
                    sValue = oSegment.DataElementValue(4)     && Security Information
                    ? oSegment.DataElement(5).Description + " = " + oSegment.DataElementValue(5)     && Interchange ID Qualifier
                    ? oSegment.DataElement(6).Description + " = " + oSegment.DataElementValue(6)     && Interchange Sender ID
                    sValue = oSegment.DataElementValue(7)     && Interchange ID Qualifier
                    sValue = oSegment.DataElementValue(8)     && Interchange Receiver ID
                    sValue = oSegment.DataElementValue(9)     && Interchange Date
                    sValue = oSegment.DataElementValue(10)     && Interchange Time
                    sValue = oSegment.DataElementValue(11)     && Interchange Control Standards Identifier
                    sValue = oSegment.DataElementValue(12)     && Interchange Control Version Number
                    ? oSegment.DataElement(13).Description + " = " + oSegment.DataElementValue(13)     && Interchange Control Number
                    sValue = oSegment.DataElementValue(14)     && Acknowledgment Requested
                    sValue = oSegment.DataElementValue(15)     && Usage Indicator
                    sValue = oSegment.DataElementValue(16)     && Component Element Separator
 
                case sSegmentID = "GS"
                    sValue = oSegment.DataElementValue(1)     && Functional Identifier Code
                    sValue = oSegment.DataElementValue(2)     && Application Sender's Code
                    sValue = oSegment.DataElementValue(3)     && Application Receiver's Code
                    sValue = oSegment.DataElementValue(4)     && Date
                    sValue = oSegment.DataElementValue(5)     && Time
                    ? oSegment.DataElement(6).Description + " = " + oSegment.DataElementValue(6)     && Group Control Number
                    sValue = oSegment.DataElementValue(7)     && Responsible Agency Code
                    sValue = oSegment.DataElementValue(8)     && Version / Release / Industry Identifier Code
                endcase && sSegmentID
            endcase && sLoopID
 
        case nArea = 1
            do case
            case sLoopID == ""
                do case
                case sSegmentID = "ST"
                    sValue = oSegment.DataElementValue(1)     && Transaction Set Identifier Code
                    ? oSegment.DataElement(2).Description + " = " +  oSegment.DataElementValue(2)     && Transaction Set Control Number
 
                case sSegmentID = "BOL"
                    sValue = oSegment.DataElementValue(1)     && Standard Carrier Alpha Code
                    sValue = oSegment.DataElementValue(2)     && Shipment Method of Payment
                    ? oSegment.DataElement(3).Description + " = " +  oSegment.DataElementValue(3)     && Shipment Identification Number
                    ? oSegment.DataElement(4).Description + " = " + oSegment.DataElementValue(4)     && Date
                    sValue = oSegment.DataElementValue(5)     && Time
                    sValue = oSegment.DataElementValue(6)     && Reference Identification
 
                case sSegmentID = "B2A"
                    sValue = oSegment.DataElementValue(1)     && Transaction Set Purpose Code
 
                case sSegmentID = "MS2"
                    sValue = oSegment.DataElementValue(1)     && Standard Carrier Alpha Code
                    sValue = oSegment.DataElementValue(2)     && Equipment Number
                endcase && sSegmentID
 
            case sLoopID == "N1"
                && If loop has more that one instance, then you should check for the qualifier that differentiates the loop instances here e.g.
                If sSegmentID = "N1" then  
                    sLoopQlfr = oSegment.DataElementValue(1)   && In most cases the loop qualifier is the first element of the first segment in the loop, but not necessarily
                EndIf
                
                do case
                case sLoopQlfr = "SH" 
                    do case
                    case sSegmentID = "N1"
                        sValue = oSegment.DataElementValue(1)     && Entity Identifier Code
                        ? "Shipper Name = " + oSegment.DataElementValue(2)     && Name
                        sValue = oSegment.DataElementValue(3)     && Identification Code Qualifier
                        sValue = oSegment.DataElementValue(4)     && Identification Code
     
                    case sSegmentID = "N3"
                        ? "Shipper Address = " + oSegment.DataElementValue(1)     && Address Information
                        sValue = oSegment.DataElementValue(2)     && Address Information
     
                    case sSegmentID = "N4"
                        ? "Shipper City = " + oSegment.DataElementValue(1)     && City Name
                        sValue = oSegment.DataElementValue(2)     && State or Province Code
                        sValue = oSegment.DataElementValue(3)     && Postal Code
                    endcase && sSegmentID
                    
                case sLoopQlfr = "CN"
                    do case
                    case sSegmentID = "N1"
                        sValue = oSegment.DataElementValue(1)     && Entity Identifier Code
                        ? "ConsigneeName = " + oSegment.DataElementValue(2)     && Name
                        sValue = oSegment.DataElementValue(3)     && Identification Code Qualifier
                        sValue = oSegment.DataElementValue(4)     && Identification Code
     
                    case sSegmentID = "N3"
                        ? "ConsigneeAddress = " + oSegment.DataElementValue(1)     && Address Information
                        sValue = oSegment.DataElementValue(2)     && Address Information
     
                    case sSegmentID = "N4"
                        ? "ConsigneeCity = " + oSegment.DataElementValue(1)     && City Name
                        sValue = oSegment.DataElementValue(2)     && State or Province Code
                        sValue = oSegment.DataElementValue(3)     && Postal Code
     
                    case sSegmentID = "G61"
                        sQlfr = oSegment.DataElementValue(1)     && Contact Function Code
                        if sQlfr = "DC" then
                            ? "Delivery Contact Name = " + oSegment.DataElementValue(2)     && Name
                        endif
                        
                        sQlfr = oSegment.DataElementValue(3)     && Communication Number Qualifier
                        if sQlfr = "TE" then
                            ? "Delivery Contact Telephone Number = " + oSegment.DataElementValue(4)     && Communication Number
                        endif
                    endcase && sSegmentID                
                endcase && sLoopQlfr 
                    
            endcase && sLoopID
 
        case nArea = 2
            do case
            case sLoopID == "AT1"
                do case
                case sSegmentID = "AT1"
                    sValue = oSegment.DataElementValue(1)     && Lading Line Item Number
 
                case sSegmentID = "L11"
                    sValue = oSegment.DataElementValue(1)     && Reference Identification
                    sValue = oSegment.DataElementValue(2)     && Reference Identification Qualifier
 
                case sSegmentID = "AT4"
                    sValue = oSegment.DataElementValue(1)     && Lading Description
                endcase && sSegmentID
 
            case sLoopID == "AT1;AT2"
                do case
                case sSegmentID = "AT2"
                    ? oSegment.DataElement(1).Description + " = " +  oSegment.DataElementValue(1)     && Lading Quantity
                    sValue = oSegment.DataElementValue(2)     && Packaging Form Code
                    sValue = oSegment.DataElementValue(3)     && Weight Qualifier
                    sValue = oSegment.DataElementValue(4)     && Weight Unit Code
                    sValue = oSegment.DataElementValue(5)     && Weight
                    ? oSegment.DataElement(6).Description + " = " +  oSegment.DataElementValue(6)     && Lading Quantity
                    sValue = oSegment.DataElementValue(7)     && Packaging Form Code
                    sValue = oSegment.DataElementValue(8)     && Yes/No Condition or Response Code
                    ? oSegment.DataElement(9).Description + " = " +  oSegment.DataElementValue(9)     && Commodity Code
 
                case sSegmentID = "MAN"
                    sValue = oSegment.DataElementValue(1)     && Marks and Numbers Qualifier
                    ? oSegment.DataElement(2).Description + " = " + oSegment.DataElementValue(2)     && Marks and Numbers
 
                case sSegmentID = "SPO"
                    ? oSegment.DataElement(1).Description + " = " +  oSegment.DataElementValue(1)     && Purchase Order Number
                    sValue = oSegment.DataElementValue(2)     && Reference Identification
                    sValue = oSegment.DataElementValue(3)     && Unit or Basis for Measurement Code
                    ? oSegment.DataElement(4).Description + " = " +  oSegment.DataElementValue(4)     && Quantity
                endcase && sSegmentID
            endcase && sLoopID
        endcase && nArea
 
        && GETS THE NEXT DATA SEGMENT
        oSegment = oSegment.Next
 
   enddo

    ?
    ? "Done"
    

    Click here to download a trial version of the Framework EDI