SET (initiate sequential file processing)

Top  Previous  Next

 

 

 

| file|

 

SET

( | file, key| )

 

 

| file, filepointer|

 

 

| key|

 

 

| key, key|

 

 

| key, keypointer|

 

 

| key, key, filepointer|

 

 

| view |

 

 

| view , number |

SET

Initializes sequential processing of a FILE or VIEW.

file

The label of a FILE declaration. This parameter specifies processing in the physical order in which records occur in the data file.

key

The label of a KEY or INDEX declaration. When used in the first parameter position, key specifies processing in the sort sequence of the KEY or INDEX.

filepointer

A numeric constant, variable, or expression for the value returned by the POINTER(file) procedure.

keypointer

A numeric constant, variable, or expression for the value returned by the POINTER(key) procedure.

View

The label of a VIEW.

Number

An integer constant, variable or expression that specifies the start position based on the first number of components of the ORDER attribute. If omitted, all ORDER attribute components are used.

SET initializes sequential processing for a FILE or VIEW. SET does not get a record, but only sets up processing order and starting point for the following NEXT or PREVIOUS statements.

FILE Usage

SET initializes sequential processing of a data file. The first parameter determines the order in which records are processed. The second and third parameters determine the starting point within the file. If the second and third parameters are omitted, processing begins at the beginning (or end) of the file.

SET(file)

Specifies physical record order processing and positions to the beginning (SET...NEXT) or end (SET...PREVIOUS) of the file.

SET(file,key)

Specifies physical record order processing and positions to the first record which contains values matching the values in the component fields of the key. NOTE: This form is rarely used and is only useful if the file has been physically sorted in the key order. A common mistake is to use this form when SET(key,key) is the actual form desired.

SET(file,filepointer)

Specifies physical record order processing and positions to the filepointer record within the file.

SET(key)

Specifies keyed sequence processing and positions to the beginning (SET...NEXT) or end (SET...PREVIOUS) of the file in that sequence.

SET(key,key)

Specifies keyed sequence processing and positions to the first or last record which contains values matching the values in the component fields of the key. Both key parameters must be the same.

SET(key,keypointer)

Specifies keyed sequence processing and positions to the keypointer record within the key.

SET(key,key,filepointer)

Specifies keyed sequence processing and positions to a record which contains values matching the values in the component fields of the key at the exact record number specified by filepointer. Both key parameters must be the same.

When key is the second parameter, processing begins at the first or last record containing values matching the values in all the component fields of the specified KEY or INDEX. If an exact match is found, NEXT will read the first matching record while PREVIOUS will read the last matching record. If no exact match is found, the record with the next greater value is read by NEXT, the record with next lesser value is read by PREVIOUS.

The values for filepointer and keypointer are dependent on the file driver. They could be a record number, the relative byte position within the file, or some other kind of "seek position" within the file. These parameters are used to begin processing at a specific record within the file.

For all file drivers, an attempt to SET past the end of the file will set the EOF procedure to true, and an attempt to SET before the beginning of the file will set the BOF procedure to true.

VIEW Usage

SET sets sequential processing for the VIEW to the beginning or end of the set of records specified by the FILTER attribute, sorted by the ORDER attribute. The optional number parameter limits the SET to assume that the values in the first specified number of expressions in the ORDER attribute are fixed. The VIEW must be OPEN before the SET.

Example:

ViewOrder  VIEW(Customer),FILTER('Hea:OrderTotal >= 500') |,ORDER('-Hea:OrderDate,Cus:Name')

           PROJECT(Cus:AcctNumber,Cus:Name)

           JOIN(Hea:AcctKey,Cus:AcctNumber)     !Join Header file

            PROJECT(Hea:OrderNumber,Hea:OrderTotal,Hea:OrderDate)

            JOIN(Dtl:OrderKey,Hea:OrderNumber)   !Join Detail file

             PROJECT(Det:Item,Det:Quantity)

             JOIN(Pro:ItemKey,Dtl:Item)      !Join Product file

              PROJECT(Pro:Description,Pro:Price)

             END

            END

           END

          END

CODE

DO OpenAllFiles

 

!Physical file order, beginning of file

SET(Customer)

 

Cus:Name = 'Smith'

!Physical file order, first record where Name = 'Smith'

SET(Customer,Cus:NameKey)

 

SavePtr = POINTER(Customer)

!Physical file order, physical record number = SavePtr

SET(Customer,SavePtr)

 

!NameKey order, beginning of file (relative to the key)

SET(Cus:NameKey)

 

SavePtr = POINTER(Cus:NameKey)

!NameKey order, key-relative record number = SavePtr

SET(Cus:NameKey,SavePtr)

 

Cus:Name = 'Smith'

!NameKey order, first record where Name = 'Smith'

SET(Cus:NameKey,Cus:NameKey)

             

Cus:Name = 'Smith'

SavePtr = POINTER(Customer)

!NameKey order, Name = 'Smith' and rec number = SavePtr

SET(Cus:NameKey,Cus:NameKey,SavePtr)

 

 

OPEN(ViewOrder)  

SET(ViewOrder)                   !Top of record set in ORDER sequence

LOOP                             !Read all records in file

 NEXT(ViewOrder)                 !read a record sequentially

 IF ERRORCODE() THEN BREAK END

 !Process the order

 END

END

Hea:OrderDate = TODAY()-1        !Assign yesterday's date

SET(ViewOrder,1)                 !and process just yesterday's orders

LOOP                             !Read all records in file

 NEXT(ViewOrder)                 !read a record sequentially

 IF ERRORCODE() THEN BREAK.

 !Process the order

 END

END

 

 

See Also:

NEXT

PREVIOUS

FILTER

ORDER

OPEN

POINTER(queue)

POINTER

GET

RESET

POSITION

SQL Related Topics:

ZERODATE