Sequential File Processing Examples


EXAMPLE 1



* This program uses sequential processing to create text file

* from a jBASE hashed file. It illustrates the use of the commands:

*      OPENSEQ, WRITESEQ, WEOFSEQ, CLOSESEQ

*

* First, let's set the destination directory and file path

    Path = "d:\temp\textfile"

*

* Open the destination file path. If it does not exist it will be created.

* Note that "openseq_creates=true" must be set for the emulation in

* config_EMULATE.

    OPENSEQ Path TO MyPath THEN

        CRT "The file already exists and we don't want to overwrite it."

    END ELSE

        CRT "File is being created..."

    END

*

* Open the jBASE file

    OPEN "FileName" TO jBaseFile ELSE STOP

    SELECT jBaseFile          ;* Process all records

*

* Now, let's loop thru each item and build the ascii text file.

    LOOP WHILE READNEXT ID DO

        READ MyRec FROM jBaseFile, ID THEN

            Line = ""

*

* Process MyRec and build the Line variable with the information to be

* written to the file.

*

            WRITESEQ Line TO MyPath ELSE

                CRT "What happened to the file?"

                STOP

            END

        END

    REPEAT

*

* Wrapup

    WEOFSEQ MyPath

    CLOSESEQ MyPath

 

EXAMPLE 2

* This program uses sequential processing to read from an ascii text file

* and write to a jBASE hashed file. It illustrates the use of the commands:

*      OPENSEQ, READSEQ, CLOSESEQ

*

* First, let's define the path where the sequential file resides.

    Path = "d:\temp\textfile"

*

* Open the file. If it does not exist an error will be produced.

    OPENSEQ Path TO MyPath ELSE

        CRT "Can't find the specified directory or file."

        ABORT

    END

*

* Open the jBASE hashed file

    OPEN "FileName" TO jBaseFile ELSE STOP

*

* Now, let's read and process each line of the ascii (sequential) file.

    LOOP

        READSEQ Line FROM MyPath ELSE EXIT

* Initialize the record which will be written to the jBASE hashed file.

        MyRec = ""

*

* Process the Line variable. This involves extracting the information which

* define the key and data of the record to be written to the jBASE hashed

* file. This will be left up to the application developer since a "line"

* could either be fixed length or delimited by some character such as a

* tab or a comma. We will assume that Key & MyRec are assembled here.

*

* All that's left to do is to write to the jBASE hashed file.

        WRITE MyRec on jBaseFile, Key

    REPEAT

*

* Wrapup

    CLOSESEQ MyPath


jBC