Entries in Reporter (1)

Tuesday
Jan272009

Revision Time (PROCESS REC)

PROCESS REC is an essential part of virtually any data retrieval in a case-structured database, here a short article from Report Issue No 1 (Feb 1996) runs us through the basics.

PROCESS REC VIA | WITH
Via and With are actually synonymous, but they cause some new users a good deal of grief so it may be useful to run through some examples.

PROCESS REC N
A loop over all records of type N within the current case (as defined by the PROCESS CASE loop). The loop ends with an END PROCESS REC or an END REC command. If the case has no records of type N, execution skips to the command after the END REC.

PROCESS REC N VIA (1)
A loop over all records of type N in the current case, where the first keyfield (sometimes called a sort-id) variable takes a value equal to 1. If the record has only one keyfield this will be at most a single record; if there are other keyfields they can vary freely. If the current case has no record(s) where the first keyfield is equal to 1, execution skips to the command after the END REC.

PROCESS REC N VIA (4,5,6)
A loop over all records type N (in the current case) where the first key field is equal to 4, the second keyfield is 5 and the third keyfield is 6. This command would be invalid unless there were at least three key fields. With exactly three keyfields this would define a single record which may or may not exist for the current case. If there are more than three keyfields, the fourth and succeeding keyfields can take any value.

The examples above use constant values as the arguments in the brackets, but you may use any mixture of constants and local (sometimes called summary) variables. Eg PROCESS REC N WITH (A,B,C) will only compile if A, B and C are the names of local variables (created with GET VARS, COMPUTE etc). If you do not know what your keyfields are, there are various options under the Database menu item which will show you. In the COMPANY database the OCCUP record has one keyfield called POSITION, which means that the command:
PROCESS REC OCCUP VIA (10)
will retrieve the OCCUP records where POSITION has value 10. Because it specifies a keyfield value and thereby uses the indexes, it is much faster than its functional equivalent:
PROCESS REC OCCUP
. IFNOT (POSITION = 10) NEXT REC
which has to read every OCCUP record.

The keyword VIA (or WITH) matches exact values; ranges are supported with the keywords FROM, THRU, AFTER and UNTIL.