URGENT: Getting Data From Flat File

nate100

Member
Hello,
I have a text file that has sample data as follows:

@@DOCUMENT
@@ACS FILE
@@DOC 02
6/15/04~1~12434~124322~err
@END
@@DOCUMENT
@@ACS FILE
@@DOC 02
6/15/04~1~12934~1235322~err
@END
@@DOCUMENT
@@ACS FILE
@@DOC 02
6/15/04~1~12234~163522~err
@END


As you can see most of the data that starts with @@ is repeated.
Only unique data is one that starts with the date.
How do I go about extracting the info after the second ~. This would be information such as 2434, 12934, etc. The data from @@DOCUMENT to @END is considered a record.

Depending on that value, I need to create another file and put that record ( From @@DOCUMENT to @END) or bypass that record.

Any help would be appreciated.

Thanks
 
I hope I understood you correctly but this is what I made of your question.

Code:
DEFINE VARIABLE cData AS CHARACTER   NO-UNDO.
DEFINE VARIABLE  iTmp AS INTEGER     NO-UNDO.
DEFINE VARIABLE lStart AS LOGICAL     NO-UNDO.
DEFINE VARIABLE cInfile AS CHARACTER   NO-UNDO.
DEFINE VARIABLE cOutfile AS CHARACTER   NO-UNDO.
ASSIGN cInFile  = 'c:\OpenEdge101B\wrk\PT\test.txt'
       cOutFile = 'c:\OpenEdge101B\wrk\PT\out.txt'.
 
DEFINE STREAM sIn.
DEFINE STREAM sOut.
/* temp-table to keep track of earlier records */
DEFINE TEMP-TABLE ttTrackInfo NO-UNDO 
    FIELD ctField1 AS CHARACTER
    FIELD ctField2 AS CHARACTER
    FIELD ctField3 AS CHARACTER
    FIELD ctField4 AS CHARACTER
    FIELD ctField5 AS CHARACTER.
 
INPUT STREAM sIn FROM VALUE(cInFile).
OUTPUT STREAM sOut TO value(cOutFile).
 
REPEAT:
    IMPORT STREAM sIn UNFORMATTED cData.
/*     DISPLAY cData. */
    ASSIGN lStart = cData = '@@DOCUMENT'.
 
    IF lStart
    THEN DO:
        iTmp = 1.
        IF AVAILABLE ttTrackInfo
        THEN DELETE ttTrackInfo.
        CREATE ttTrackInfo.
        ASSIGN ttTrackInfo.ctField1 = cData.
    END.
    ELSE DO:
        FIND FIRST ttTrackInfo.
        CASE iTmp:
            WHEN 2 THEN ASSIGN ttTrackInfo.ctField2 = cData.
            WHEN 3 THEN ASSIGN ttTrackInfo.ctField3 = cData.
            WHEN 4 THEN ASSIGN ttTrackInfo.ctField4 = cData.
            WHEN 5 THEN ASSIGN ttTrackInfo.ctField5 = cData.
        END CASE.
    END.
 
    iTmp = iTmp + 1. /* increment counter */
 
    /* at the end we output block to different file if the conditions are met */
    IF cData = "@END" and
       ENTRY(3,ttTrackInfo.ctField4,'~~') = '12434' 
    THEN DO:
        PUT STREAM sOut UNFORMATTED
            ttTrackInfo.ctField1 SKIP
            ttTrackInfo.ctField2 SKIP
            ttTrackInfo.ctField3 SKIP
            ttTrackInfo.ctField4 SKIP
            ttTrackInfo.ctField5 SKIP.
    END.
END.
OUTPUT STREAM sIn CLOSE.
OUTPUT STREAM sOut CLOSE.

HTH,

Casper
 
Casper,
Thanks for the reply.
Say if i have a string like the following:

6/15/04~1~12934~1235322~err

What function do I used to extract the data after the second ~

In this case, it should pull up 12934. Thanks
 
Say if I have a string like the following 'abc445098' and I want to see if it contains '445', how would I do this?

Meaning, I cannot use contains as it is stored in a variable.

example:

def ver x as char.
x = 'abc445098'.

How do I check to see if the string '445' is in the string x?
 
DEF VAR cStr AS CHAR INIT " 6/15/04~1~12934~1235322~err".
DEF VAR cRes AS CHAR.


cRes = ENTRY(3,cStr,'~').

I guess that would be ENTRY(3,cStr,'~~').

Since ~ is an escape sign you have to escape the escape sign.

Casper.
 
Back
Top