* This is just an example program to show how to translate an EDI 856 file in FoxPro
    * using the Framework EDI
    
    clear all

    * CREATES EDIDOC 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
 
     sSefFile = "856_X12-4010.SEF"
     sEdiFile = "856_4010.X12"
     
    * LOADS THE SEF FILE
    oEdiDoc.LoadSchema(sSefFile , 0)
 
    * LOADS THE EDI FILE
    oEdiDoc.LoadEdi(sEdiFile )
 
    * 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
        sLoopSection= oSegment.LoopSection
        nArea = oSegment.Area
 
        do case
        case nArea = 0
            do case
            case sLoopSection== ""
                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
                    sValue = oSegment.DataElementValue(5)     && Interchange ID Qualifier
                    sValue = 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 sLoopSection == ""
                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 = "BSN"
                    sValue = oSegment.DataElementValue(1)     && Transaction Set Purpose Code
                    ? oSegment.DataElement(2).Description + " = " + oSegment.DataElementValue(2)     && Shipment Identification
                    sValue = oSegment.DataElementValue(3)     && Date
                    sValue = oSegment.DataElementValue(4)     && Time
                    sValue = oSegment.DataElementValue(5)     && Hierarchical Structure Code
                endcase && sSegmentID
            endcase && sLoopSection 
 
        case nArea = 2
        
            if sLoopSection == "HL" and sSegmentID == "HL" then
                sLoopHLQlfr = oSegment.DataElementValue(3)
            endif
                
            do case
            case sLoopHLQlfr == "S"    && SHIPMENTS
            
                do case
                case sLoopSection== "HL"
 
                    do case
                    case sSegmentID = "HL"
                        sValue = oSegment.DataElementValue(1)     && Hierarchical ID Number
                        sValue = oSegment.DataElementValue(2)     && Hierarchical Parent ID Number
                        sValue = oSegment.DataElementValue(3)     && Hierarchical Level Code
                        sValue = oSegment.DataElementValue(4)     && Hierarchical Child Code
     
                    case sSegmentID = "TD1"
                        sValue = oSegment.DataElementValue(1)     && Packaging Code
                        ? oSegment.DataElement(2).Description + " = " + oSegment.DataElementValue(2)     && Lading Quantity
                        sValue = oSegment.DataElementValue(3)     && Commodity Code Qualifier
                        sValue = oSegment.DataElementValue(4)     && Commodity Code
                        sValue = oSegment.DataElementValue(5)     && Lading Description
                        sValue = oSegment.DataElementValue(6)     && Weight Qualifier
                        sValue = oSegment.DataElementValue(7)     && Weight
                        sValue = oSegment.DataElementValue(8)     && Unit or Basis for Measurement Code
     
                    case sSegmentID = "TD5"
                        sValue = oSegment.DataElementValue(1)     && Routing Sequence Code
                        sValue = oSegment.DataElementValue(2)     && Identification Code Qualifier
                        ? oSegment.DataElement(3).Description + " = " + oSegment.DataElementValue(3)     && Identification Code
                        sValue = oSegment.DataElementValue(4)     && Transportation Method/Type Code
                        sValue = oSegment.DataElementValue(5)     && Routing
     
                    case sSegmentID = "TD3"
                        sValue = oSegment.DataElementValue(1)     && Equipment Description Code
                        sValue = oSegment.DataElementValue(2)     && Equipment Initial
                        ? oSegment.DataElement(3).Description + " = " + oSegment.DataElementValue(3)     && Equipment Number
     
                    case sSegmentID = "REF"
                        sValue = oSegment.DataElementValue(1)     && Reference Identification Qualifier
                        ? oSegment.DataElement(2).Description + " = " + oSegment.DataElementValue(2)     && Reference Identification
     
                    case sSegmentID = "DTM"
                        sQlfr = oSegment.DataElementValue(1)     && Date/Time Qualifier
                        do case
                        case = "011" && shipped
                            ? oSegment.DataElement(2).Description + " Shipped = " + oSegment.DataElementValue(2)     && Date
                        case = "017" && estimated delivery
                            ? oSegment.DataElement(2).Description + " estimated delivery = " + oSegment.DataElementValue(2)     && Date
                        endcase
                    endcase && sSegmentID
 
                case sLoopSection== "HL;N1"
                    If sSegmentID = "N1" then  
                        sNm1Entity= oSegment.DataElementValue(1)   
                    EndIf
                    
                    do case
                    case sNm1Entity= "BT"    && BILL-TO
                        do case
                        case sSegmentID = "N1"
                            sValue = oSegment.DataElementValue(1)     && Entity Identifier Code
                            ? oSegment.DataElement(2).Description + " Bill-To = " + oSegment.DataElementValue(2)     && Name
                            sValue = oSegment.DataElementValue(3)     && Identification Code Qualifier
                            sValue = oSegment.DataElementValue(4)     && Identification Code
         
                        case sSegmentID = "N3"
                            sValue = oSegment.DataElementValue(1)     && Address Information
         
                        case sSegmentID = "N4"
                            sValue = oSegment.DataElementValue(1)     && City Name
                            sValue = oSegment.DataElementValue(2)     && State or Province Code
                            sValue = oSegment.DataElementValue(3)     && Postal Code
                        endcase && sSegmentID    
                                        
                    case sNm1Entity= "ST"    && SHIP-TO
                        do case
                        case sSegmentID = "N1"
                            sValue = oSegment.DataElementValue(1)     && Entity Identifier Code
                            ? oSegment.DataElement(2).Description + " Ship-To = " + oSegment.DataElementValue(2)     && Name
                            sValue = oSegment.DataElementValue(3)     && Identification Code Qualifier
                            sValue = oSegment.DataElementValue(4)     && Identification Code
         
                        case sSegmentID = "N3"
                            sValue = oSegment.DataElementValue(1)     && Address Information
         
                        case sSegmentID = "N4"
                            sValue = oSegment.DataElementValue(1)     && City Name
                            sValue = oSegment.DataElementValue(2)     && State or Province Code
                            sValue = oSegment.DataElementValue(3)     && Postal Code
                        endcase && sSegmentID                                        
                    endcase
                endcase && sLoopID
                
            case sLoopHLQlfr == "O"  && ORDERS
                do case 
                case sLoopSection= "HL"
                    do case
                    case sSegmentID = "PRF"
                        ? oSegment.DataElement(1).Description + " = " + oSegment.DataElementValue(1)     
                        ? oSegment.DataElement(2).Description + " = " + oSegment.DataElementValue(2)     
                        sValue = oSegment.DataElementValue(4)     
     
                    case sSegmentID = "REF"
                        sValue = oSegment.DataElementValue(1)     && Reference Identification Qualifier
                        ? oSegment.DataElement(2).Description + " = " + oSegment.DataElementValue(2)     && Reference Identification                    
                    endcase    && sSegmentID 
                endcase   && sLoopSection     
            
            case sLoopHLQlfr == "I"  && ITEMS
                do case 
                case sLoopSection= "HL"
                    do case
                    case sSegmentID = "LIN"
                        sValue = oSegment.DataElementValue(3)
                        ? oSegment.DataElement(3).Description + " = " + oSegment.DataElementValue(3)  
                        
                    case sSegmentID = "SN1"
                        sValue = oSegment.DataElementValue(2)     
                        ? oSegment.DataElement(2).Description + " = " + oSegment.DataElementValue(2)     
                        sValue = oSegment.DataElementValue(5)     
                        sValue = oSegment.DataElementValue(6)     
                        sValue = oSegment.DataElementValue(8)     

                    case sSegmentID = "PRF"
                        ? oSegment.DataElement(1).Description + " = " + oSegment.DataElementValue(1)     
                        sValue = oSegment.DataElementValue(2)     
                        sValue = oSegment.DataElementValue(4)     

                    case sSegmentID = "PID"
                        ? oSegment.DataElement(5).Description + " = " + oSegment.DataElementValue(5)                             
                    endcase  && sSegmentID 
                endcase  && sLoopSection       
            
            endcase
 
        case nArea = 3
            do case
            case sLoopSection== ""
                do case
                case sSegmentID = "CTT"
                    sValue = oSegment.DataElementValue(1)     && Number of Line Items
                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