Directives
WRITE RECORD Write Record
   
Format WRITE RECORD (chan[,fileopt])contents$

Where:

chan Channel or logical file number of the file to which to write.
contents$ String (literal, expression, or variable) that contains the contents of the record 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.

 

   
Description Use the WRITE RECORD directive to add / update a record for a file (logical file number / channel). 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.

In Keyed files with multiple keys, the WRITE RECORD directive automatically updates all alternate keys. ProvideX supports use of the WRITE RECORD directive with *MEMORY*.

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

Example:

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$)

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$

   
Example 0010 OPEN (1)"OLDFIL"
0020 OPEN LOCK (2)"NEWFIL"
0030 READ RECORD (1,END=1000)R$
0040 WRITE RECORD (2)R$
0050 GOTO 0030
1000 CLOSE
1010 END
   
See Also WRITE Add/Update Data in File
INSERT Insert New Record in File
UPDATE Update Existing Record in File