WRITE Verb
Syntax
WRITE {(channelno{options})}{outputlist}
WRITE RECORD{(channelno{options})}{strvar}
NOTE: The PRINT and PRINT RECORD syntax is the same as WRITE and WRITE RECORD.
Description
For BBj-specific information, see WRITE Verb - BBj.
Applicable Verbs |
Option |
Description |
WRITE/PRINT |
,ERR=lineref |
Specifies a branch to be taken if an error occurs during the execution of the statement. Higher priority error branches override ERR=. |
WRITE/PRINT |
Specifies a branch to be taken at end-of-file. END= overrides ERR= for end-of-file errors. |
|
WRITE |
,DIR=int |
Following a successful WRITE, DIR=int moves the file pointer in the direction specified by the sign of int the number of records specified by the absolute value of int. |
WRITE |
,DOM=lineref |
Specifies a branch to be taken if the statement tries to add a key to a keyed file that already exists. PRO/5 ignores the error if the DOM= clause is not used. DOM= overrides ERR= for duplicate key errors. |
WRITE/PRINT |
Moves the file pointer to the specified record (or byte) before the data transfer takes place. |
|
WRITE |
Adds a new key
to a DIRECT or SORT file or rewrites an existing key. PRO/5 issues
an improper access error if the file is not a DIRECT or SORT file. |
|
WRITE (TCP Server Only) |
,KEY=<ip> |
Identifies the connected client to which to send the message. If not specified, WRITE defaults to the last connected client from which data was received. |
WRITE (UDP Only |
,KEY=<ip>:<port> |
Identifies the connected client and port to which to send the message. If not specified, WRITE defaults to the last connected client and port from which data was received. |
WRITE/PRINT |
Translates data as it is written. lineref must reference a TABLE statement. Key values are not translated. |
|
WRITE/PRINT |
If a device is busy or if a record is locked by another user, waits int seconds before returning an error. If no TIM= option is given, PRO/5 defaults to a ten-second timeout for disk files. The default timeout for devices may vary from system to system. PRO/5 guarantees a range of 0 to 255 for int. The TIM=int option is not available with I/O operations involving C-ISAM files. |
outputlist consists of items
or fields to be written. Separate each item with a comma. The end of the
list may have a trailing comma. The WRITE verb produces a linefeed character
following each field. PRINT produces a linefeed character only at the
end of the output list, unless the list ends with a comma. If no output
list is given, PRO/5 does not produce the linefeed character.
Allowable outputlist items follow:
string {: stringmask} |
Evaluates and outputs the string expression. If stringmask is used, the output is applied to the mask. See the STR() function for additional information on string masking. |
num {: string} |
Evaluates any numeric expression and outputs the results according to the rules for numeric output. See Numeric Output in the User's Reference Guide for additional information. num {: string} uses the optional colon and string as an output format mask. If no mask is given, PRINT outputs a space followed by the number. WRITE does not output a space. |
array[ALL] |
Outputs an entire numeric or string array. If array X is dimensioned to five elements (0 to 4), then X[ALL] is identical to X[0], X[1], X[2], X[3], and X[4]. Each output element is a field. |
'mnemonic' |
A mnemonic is a string of ASCII characters enclosed in tick marks (') and can be 2 to 16 characters long. Mnemonics perform special functions on some devices. For example, the mnemonic 'CS' clears the screen on a video terminal. Mnemonics allow device-independent programs to be written. |
@(col {,row}) |
On a terminal, the cursor moves to the location on the screen specified by col and row. col and row must be integers in the range of 0 to 255. If only col is given, PRO/5 assumes the current row on the screen. The top left corner of the screen is @(0,0). On a printer, col produces movement within the current print line, while row is ignored by printers. |
* |
PRO/5 treats an asterisk as a null field. Though the asterisk is significant in an input list, it is defined for an output list only because an IOLIST statement may be used for both input and output. |
Refers to the IOLIST statement at lineref for more outputlist items. PRO/5 behaves as if the items in the IOLIST were in place of the IOL= option. Several IOL= items can appear in an outputlist. An IOLIST can also invoke other IOLISTs with the IOL= option until memory runs out. If there is no IOLIST at lineref, PRO/5 issues an error. |
WRITE RECORD and PRINT RECORD use only a string variable as an outputlist. PRO/5 outputs the contents
of the string with no special treatment. No linefeed character is added.
This method of output is the most efficient.
SERIAL files must be LOCKed before being written to. A locked C-ISAM record
is released after any WRITE operation to that channel.
On some UNIX platforms, a WRITE from a TCP/IP client may not return an
error when the socket has already been closed by the TCP/IP server. Any
subsequent WRITE produces an !ERROR=4 tcb(10)=-10053.
Output Event Sequence
The following sequence of events occur during output:
-
PRO/5 evaluates the options.
-
PRO/5 evaluates the output data.
-
If KEY= or IND= is given, PRO/5 moves the file pointer to the appropriate record; otherwise, PRO/5 defaults to the current file pointer position and then writes the output data. KEY= is for keyed files only.
-
PRO/5 moves the file pointer to the next logical record in a record-oriented file or to the next byte in a byte-oriented file. If the DIR= option is used, the file pointer is moved accordingly.
Attempting to do the following will cause an end-of-file error !ERROR=2, which may be trapped with the END= option:
-
Add a record to a static keyed file that is full.
-
Add an index with a value that is too high to a static indexed file.
-
Write a record located in a file beyond a user's UNIX operating system ulimit.
When using WRITE and PRINT:
-
WRITE outputs a linefeed character after every item in the outputlist. PRINT outputs a linefeed character only at the end of the list, and only if there is no trailing comma.
-
PRINT outputs a space in front of a nonformatted numeric field.
A shortened form of the PRINT verb represents "PRINT" as a question mark:
?"print string"
Examples
WRITE (1,KEY="TEST KEY",ERR=9500)A$,B$,C$
WRITE RECORD(1,KEY="TEST KEY",ERR=9500)A$
PRINT @(0,21),'CE',@(0,0),'CL',