Directives
WRITE Add/Update Data in File
   
Formats 1. Write: WRITE (chan[,fileopt])varlist
 
2. Write Lock: WRITE LOCK (chan[,fileopt])varlist
 
Where:
chan Channel or logical file number of the file to which to write.
fileopt Supported file options (see also, File Options):
BSY=stmtref Traps Error #0: Record/file busy
DOM=stmtref Duplicate record transfer (taken when record of same primary key already exists).
END=stmtref END-OF-FILE transfer
ERR=stmtref Error transfer
IND=num Record index
KEY=string$ Record key (see Automatic Padding with KEY=Option)
REC=name$ Record prefix (REC=VIS(string$) can also be used to define the prefix)
RTY=num Number of retries (one second intervals). This overrides the value defined by the 'WT' system parameter.
TIM=num Maximum time-out (support write operations for TCP channels)
stmtref Program line number or statement label to which to transfer control.
varlist Comma-separated list of variables, literals, Mnemonics, IOL= options,
and/or location functions '@(...)'.
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.,

KEYED "TEST", [1:1:5]+[2:1:6]+[3:1:8] READ (1,KEY=A$:B$:C$)

is the same as

READ (1,KEY=PAD(A$,5,$00$)+PAD(B$,6,$00$)+C$)

   
Format 1 Write

WRITE (chan[,fileopt])varlist

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.

Examples:

0410 WRITE (1,ERR=1000,DOM=1200)A,B,Z9$

An IND=index clause is mandatory if you are writing to an indexed file; e.g.,

0810 LET I=0
0820 OPEN (8)"PVX_INDX"
0830 READ (8)IOL=110,ERR=0950
0840 LET I=I+1 ! This reserves an empty record at index 0
0850 CALL "SOMETHING",IOL=0110,ERR=950
0900 WRITE (8,IND=I,ERR=9000)IOL=0110
0910 GOTO 0830

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.,

0710 OPEN (7)"PVX_SORT"
0720 READ (6)CUST$,NAME$,*,*,*,*,*,*,*,*,*,ERR=0750
0730 WRITE (7,KEY=CUST$)

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:

KEYED "PVX_KEYD",[1:1:6],[2:1:10],,256

0210 OPEN (2)"PVX_KEYD"
0220 READ (6)CUST$,NAME$,*,*,*,*,*,START_DT$,CRED_LIM,TERMS,END_DT$,ERR=0250
0230 WRITE (2)IOL=0100

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.

Writing to *MEMORY*

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.  

WRITE (14,IND=3)IOL=2010
 
      or
WRITE RECORD (14,IND=3)"DOGCATPIG"

To update a given record in a Memory file, use KEY= with a given key value:

0910 WRITE (14,KEY=KK$,DOM=0920)IOL=2010
 
      or
WRITE RECORD (14,KEY=KK$)A$

   
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.,

9010 WRITE LOCK (9,ERR=2000)IOL=0110

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.,

9010 WRITE LOCK (9, KEY=K$)



*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:

SERIAL "PVX_SER",,256
0510 OPEN LOCK (5)"PVX_SER"
0520 READ (6)CUST$,NAME$,ADDR1$,ADDR2$,CITY$,PROV$,POSTAL$,START_DT$,CREDLIM,
0520:TERMS,END_DT$,ERR=0550
0530 WRITE (5)IOL=0090
0540 GOTO 0520
0550 STOP

   
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