*MEMORY* |
Create and Use Memory File |
OPEN (chan[, option])"*MEMORY*[; keydef]"
chan |
Channel or logical file number. |
option |
BSZ=num file option for specifying record size (number of bytes). The default record size is 1024 bytes unless it is overridden via BSZ=. |
keydef |
The keydef field, if supplied, can be used to define alternate logical keys for the data in the *MEMORY* file. See Alternate Keys. |
*MEMORY* |
Keyword, not case sensitive. Logical filename, enclosed in quotation marks within OPEN directive. (Include * asterisks in syntax) |
PxPlus supports a memory-resident logical file called *MEMORY*; i.e. this file is a memory-resident queue of records. Create the memory-queue file and assign the given logical file number (channel) via the OPEN directive.
PxPlus recognizes *MEMORY* at run time and deals with it internally. Once *MEMORY* is open, you can gain I/O access to memory-resident records in the same manner as you can to Direct files – by record index or by key using the following I/O directives:
|
|
|
|
|
|
|
|
|
|
|
|
|
The first WRITE determines the file access method (i.e. the IND= option specifies Indexed file handling), and KEY= specifies Direct file handling (externally keyed files).
The functions IND( ), KEF( ), KEL( ), KEN( ), KEP( ), KEY( ) and RNO( ) can be used with memory-queue files.
Use CLOSE (chan) to delete a memory file and return memory to the system.
Memory files can have alternate keys specified. When opening a memory file, you can add a KEYDEF= option that defines the alternate key definition. Standard PxPlus alternate key definitions can be used as follows:
Code |
Description |
"A" |
Ascending key (assumed). |
"B[.n]" |
Indicates that the segment contains a numeric value. Field will internally be converted to its binary equivalent and stored into the data file. Negative numbers will occur before position numbers in ordinary numeric value sequence. If '.n' is provided, the value in 'n' is assumed to be the number of digits to the right of the decimal point that are to be maintained. Before the internal value is created, the value will be TRUNCATED to the number of decimal places specified. See Numeric Key Segments. (Numeric key support was added in PxPlus v6.30.) |
"C" |
Force uppercase for individual key segments to create uppercase insensitive keys. |
"D" |
Descending order (default is ascending). |
"K[:n]" |
Null key suppression.n is the Hex value of the character to suppress if all characters match (defaults to $00$ if not specified). If the entire key evaluates to null, the key will not be a part of this key tree. This cannot be used on a primary key. Unlike standard keyed files, this can be used in conjunction with the "N" option. |
"L" |
Force lowercase for individual key segments to create lowercase insensitive keys. |
"N[:n]" |
Null segment suppression.n is the Hex value of the character to suppress if all characters match. If any segment within the key evaluates to null, the key will not be a part of this key tree. Unlike standard keyed files, this can be used in conjunction with the "N" option. |
"T" |
Force automatic accent translation for individual key segments (i.e. to translate accented/extended characters to their non-accented counterparts), useful when sorting multilingual characters into a single unified sort sequence. |
"U" |
If you declare an alternate key segment as unique, then no duplicate keys are allowed on writing a record. System will generate an Error #11: Record not found or Duplicate key on write if the key being added already exists on the file. If any segment in a key definition is marked as unique, then the entire key is considered unique. |
Example:
To create and open a memory file with a 6-byte external key, an 8-byte UNIQUE key on field 2 and a 30-byte key on field 3, you could use:
open (1)"*memory*;KEYDEF=6,[2:1:8:""U""],[3:1:30]"
Key names can also be specified, if desired.
DIRECT Create File with Keyed Access
KEYED Create Single/Multi-Keyed File
This example illustrates how to open and use the memory file:
0010 mmf=hfn
0020 open (mmf)"*memory*"
0030 print 'CS'
0040 input "Name (Press F4 to end):",name$
0050 if ctl=4 then goto 0100
0060 input "Address:",addr$
0070 input "Position:",pos$
0080 write (mmf,key=name$)iol=mmfLst
0090 goto 0030
0100 print 'CS'
0110 select iol=mmfLst from mmf begin "" end "z"
0120 print "Name:",name$
0130 print "Address:",addr$
0140 print "Position:",pos$
0150 print "----------"
0160 next record
0170 end
0180 mmfLst: iolist name$,addr$,pos$