*VIEW* |
View-based File |
OPEN (chan[,fileopt]) "*VIEW*;viewname[;options] [...]"
chan |
Channel or logical file number. | ||||||||||
fileopt |
File options. Supported options for opening *VIEW* include:
| ||||||||||
viewname |
Defines the name of the View whose definition will determine the logical file contents. | ||||||||||
File options. Supported parameters separated by a ; (semi-colon). These include:
(The MINVAL, MAXVAL and SEQPFX file options were added in PxPlus 2022.) | |||||||||||
Case insensitive keyword. Special device file name, enclosed in quotation marks within OPEN directive. (Include * asterisks in syntax) |
The *VIEW* interface allows a View to be used to define the contents of a logical file for use by an application program. It allows the program to access the contents of a View as if it were a standard read-only file.
Opening the View
To open the contents of a View, specify the file name *VIEW* followed by the name of the View you wish to access, separated by ; (semi-colons):
open (1)"*VIEW*;CustomerView"
When opened, the system will process the View definition and return its contents in a memory file using the specified channel number. The entire data set is loaded into the memory file when opened.
By default, the memory file will have an external key based on the key defined for the View. This can be changed by specifying the KNO= parameter in the OPEN statement. In addition, by default, there is no IOList; however, you can specify the IOL=* parameter to use the View's internal IOList or specify an IOList definition such as IOL=IOList Acct$,CustName$,Balance:
open (1)"*VIEW*;AcctInfoView;KNO=1;IOL=*"
open (1,opt="IOL=IOLIST This$,That$,Another",err=*next)"*VIEW*;myView"
The contents of the returned memory file is a static data set for the specified View; that is, the file is a snapshot of the View results at the time the file was opened. No changes or updates to the original data sources are reflected in the file as it is processed. Closing the channel will free the memory file and free its contents.
If there is a possibility of duplicate keys in the resulting data set, data can be lost when the records with duplicate keys are overwritten. This can occur in Views that have a one-to-many relationship or use keys that allow duplicates. In this case, it is recommended that you use the SEQPFX=Y option, which prefixes the key with a 10-digit sequence number to guarantee unique keys and no data loss. When used, an alternate key, KNO=1, is available for IO processing to access the original key value of a record.
open (1,opt=" IOL=*;KNO=2;SEQPFX=Y")"*VIEW*;vInvoice;"
Descending Keys
If the key by which a *VIEW* is read has a descending segment, special key handling is required. The SEQPFX=Y option may be used to maintain proper record order. In this case, key functions on the primary key (i.e. KEY( ), KEC( ), KEF( ), KEL( ), etc.) will include the 10-digit sequence number. Using KNO=1 in these functions will return the original key but, in the case of duplicate keys, may not point to the right record.
Alternately, if the SEQPFX=Y option is not used, the key value returned by a key function will contain an altered value in the location of the descending segment to maintain the descending sequence. To revert the key to an unaltered value, it can be manipulated using the %_KeyMask$ variable, which is set when *VIEW* is opened:
open (hfn,opt="IOL=*;KNO=2;MINVAL="+startDate$+";MAXVAL="+endDate$)"*VIEW*;vInvoice"
Channel=lfo,keymask$=%_KeyMask$
:
read (channel)
k$=kec(channel);
TrueKeyValue$=xor(k$,keyMask$(1,len(k$)))
(The *VIEW* logical file name was added in PxPlus v10.00.)
(Support for descending keys was added in PxPlus 2019 Update 2.)