FILTER Examples


Example 1 - Simple filtering

 

IFILE

IFILE

 

KEY

INIT

"mykey"

.

 

 

 

OPEN

IFILE,...

 

...

 

 

FILTER

IFILE,"CompanyName = 'Sunbelt' AND ID = 10"

or

 

 

 

FILTER

IFILE,"CompanyName LIKE '%bel%'"

 

The first FILTER statement limits the data retrieved from the ISAM file to records containing a company name of "Sunbelt" and and ID value of 10. The second FILTER statement limits the ISAM file to records that have a company name containing the string "bel".

 

Example 2 - Using 'SKIPKEYS=nnn' keyword option

 

IFILE

IFILE

 

ONE

INTEGER

1,"1"

.

 

 

 

OPEN

IFILE,"test"

.

 

 

 

FILTER

IFILE,"",SKIPKEYS=ONE

 

LOOP

 

 

READKS

IFILE;S$CMDLIN

 

UNTIL

OVER

 

DISPLAY

"Data:",*LL,S$CMDLIN

 

REPEAT

 

.

 

 

 

FILTER

IFILE;S$CMDLIN //Clears all filtering!

 

...

 

 

In this example, every other record is skipped.

 

Example 3 - Using '$SKIPKEYS$[nnn]' string name operator

 

 

...

 

IFILE

IFILE

 

.

 

 

 

OPEN

IFILE,"test"

.

 

 

 

FILTER

IFILE,"$SKIPKEYS$[1]"

 

LOOP

 

 

READKS

IFILE;S$CMDLIN

 

UNTIL

OVER

 

DISPLAY

"Data:",*LL,S$CMDLIN

 

REPEAT

 

.

 

 

 

FILTER

IFILE;S$CMDLIN //Clears all filtering!

 

In this example, every other record is skipped.

 

Example 4 - Using 'SKIPKEYS=nnn' keyword option

 

 

. Read IFILE KEY to position in ISI file key tree.

. Set SKIPKEYS keyword to skip 20 keys for every READKS.

. After first READKS, clear the skip count to read

. every record after the first 20 keys have been skipped.

.

IFILE

IFILE

 

KEY

DIM

10

.

 

 

 

OPEN

IFILE,"test"

 

MOVE

"SOMEKEY",KEY

 

READ

IFILE,KEY;S$CMDLIN // Position to ISI Key

.

 

 

 

FILTER

IFILE, "", SKIPKEYS=20 // Set to skip 20 ISI keys

 

LOOP

 

.

. Read IFILE KEY to position in ISI file key tree.

. Set SKIPKEYS keyword to skip 20 keys for every READKS.

. After first READKS, clear the skip count to read

. every record after the first 20 keys have been skipped.

.

 

READKS

IFILE;S$CMDLIN

 

UNTIL

OVER

 

DISPLAY

"Data:",*LL,S$CMDLIN

.

. After the first 20 keys have been, the skip count is cleared

. to allow every ISI key to be accessed.

.

 

FILTER

IFILE,"", SKIPKEYS=0 // Explicitly clear skip count

 

REPEAT

 

.

 

 

 

Example 5 - Using '$SKIPKEYS$[nnn]' string name operator

 

. Read IFILE KEY to position in ISI file key tree.

. Set $SKIPKEYS$ to skip 20 keys for every READKS.

. After first READKS, clear the skip count to read

. every record after the first 20 keys have been skipped.

.

 

 

IFILE

IFILE

 

KEY

DIM

10

.

 

 

 

OPEN

IFILE,"test"

.

 

 

 

MOVE

"SOMEKEY",KEY

 

READ

IFILE,KEY;S$CMDLIN // Position to ISI key

.

 

 

 

FILTER

IFILE, "$SKIPKEYS$[20]" // Set to skip 20 ISI keys

 

LOOP

 

.

. This READKS skips 20 ISI keys and returns the record for

. the 21 key. An OVER can be returned if skip count is larger

. than the number of keys the remain in the ISI tree.

.

 

READKS

IFILE;S$CMDLIN

 

UNTIL

OVER

 

DISPLAY

"Data:",*LL,S$CMDLIN

.

. After the first 20 keys have been, the skip count is cleared

. to allow every ISI key to be accessed.

.

 

FILTER

IFILE,"$SKIPKEYS$[0]" // Explicitly clear skip count

 

REPEAT

 

.

 

 

 

Example 6 - Using 'SKIPONCE=nnn' keyword option

 

. Set SKIPONCE keyword to skip count 1 key (First key!)

. Read IFILE by KEY using a skip count.

. This example checks for a duplicate key in a single read operation.

.

IFILE

IFILE

 

KEY

DIM

10

.

 

 

 

OPEN

IFILE,"test"

.

 

 

 

FILTER

IFILE, "", SKIPONCE=1 // Set to skip 1st key!

.

 

 

 

MOVE

"ValidKey",Key

 

READ

IFILE,KEY;S$CMDLIN // Reading with SKIPONCE Filter

 

 

                    // Skip count cleared after read

 

IF

OVER

 

DISPLAY

"No duplicate key!"

 

ELSE

 

 

DISPLAY

"Duplicate key exists!"

 

ENDIF

 

 

Example 7 - Using '$SKIPKEYS$[nnn]' string name operator

 

. Set SKIPONCE keyword to skip count 1 key (First key!)

. Read IFILE by KEY using a skip count.

. This example checks for a duplicate key in a single read operation.

.

IFILE

IFILE

 

KEY

DIM

10

.

 

 

 

OPEN

IFILE,"test"

.

 

 

 

FILTER

IFILE, "$SKIPONCE$[1]" // Set to skip 1st key!

.

 

 

 

MOVE

"ValidKey",Key

 

READ

IFILE,KEY;S$CMDLIN // Reading with SKIPONCE Filter

 

 

                    // Skip count cleared after read

 

IF

OVER

 

DISPLAY

"No duplicate key!"

 

ELSE

 

 

DISPLAY

"Duplicate key exists!"

 

ENDIF

 

 



PL/B Language Reference