| Directives |
|
| Formats | 1.
Write: WRITE (chan[,fileopt])varlist 2. Write Lock: WRITE LOCK (chan[,fileopt])varlist Where:
|
|||||||||||||||||||||||||||||
| Description | Use
the WRITE directive to add/update a
record to a file (logical file number / channel).
ProvideX also supports use of the WRITE
directive with *MEMORY* (a
memory-resident file or queue of records. Automatic Padding with KEY=Option When you use KEY=string$:string$[:string$][...] ProvideX automatically pads key segments. This is valid only if you have Keyed files with segmented key definitions. ProvideX right-pads the key segment using $00$ (nulls) to the segment's full length. The last segment in a compound key is not padded; e.g.,
is the same as
|
|||||||||||||||||||||||||||||
| Format 1 | Write
If the specific record already exists (indexed, direct, or sort files) and you include the DOM=stmtref option, control transfers to the stmtref. Otherwise, the specified record is updated.
An IND=index clause is mandatory if you are writing to an indexed file; e.g.,
The KEY=string$ is mandatory if you are writing to a Keyed file with an external key or to a DIRECT or SORT file; e.g.,
No KEY= option is allowed if you are writing to a Keyed file whose primary key is composed of data fields embedded in the record data. |
|||||||||||||||||||||||||||||
| *Note* | When writing to a file without an external key and the 'BX' system parameter is on, the KEY= option will be ignored. This is an +PxPlus Exclusive | |||||||||||||||||||||||||||||
In
Keyed files with multiple keys, the WRITE
directive will automatically update all alternate keys.
For instance, alternate keys 0 [1:1:6] and 1 [2:1:10] are
updated as follows:
ProvideX uses the variables in the variable list either in delimited form or in accordance with any format specified (with headers, etc.). The contents of these fields are used to generate the actual data record. Numeric data converted during a WRITE directive does not use the 'DP' Decimal Point Symbol or 'TH' Thousands Separator system parameters for European decimal settings. The list of variables can refer to an IOList (using IOL=iolref) as above. The iolref can be the line number or statement label of the line containing the IOList, or it can be a string containing a compiled IOList. If you omit the list of variables from the WRITE directive, ProvideX uses the IOL specified (if any) on your OPEN statement for the file. A WRITE operation will check the last entry in the key table for the key being added before proceeding to the top of the key chain to determine the new entry point. This dramatically increases the speed of writing additional records in sequential order. You can use WRITE and/or WRITE RECORD directives to update records in a Memory file using an IOList or a string expression. You can add records by index, inserting records at the given index number. ProvideX will not overwrite existing records. Use the DOM= option when you write to a Memory file. The following two examples below insert a new record at index 3 without overwriting the current record at index 3. The record that was at index 3 is now at index 4 and the number of records in the file has increased by one.
To update a given record in a Memory file, use KEY= with a given key value:
|
||||||||||||||||||||||||||||||
| Format 2 | Write Lock WRITE (chan[,fileopt])varlist Use the WRITE LOCK format to ensure that once the file has been written to, it remains locked; e.g.,
When you use the LOCK option, ProvideX doesn't release an extracted record. It maintains the extraction to prevent potential timing problems and maintain counters and totals in batch processing, sparing you the need to re-extract; e.g.,
|
|||||||||||||||||||||||||||||
| *Note* | If a serial file is not locked before you write to it, an Error #13: File access mode invalid will occur on the WRITE directive. Use OPEN LOCK for your serial file to prevent this error from occurring on the WRITE. | |||||||||||||||||||||||||||||
Example:
|
||||||||||||||||||||||||||||||
| See Also | INSERT
Insert New Record in File UPDATE Update Existing Record in File WRITE RECORD Write Record OPEN Open a File for Processing, RCD( ) Function 'XI' System Parameter, *MEMORY* Create & Use Memory File |
|||||||||||||||||||||||||||||