WRITE – Echo information to a file or the external data queue
Use the WRITE
command to echo information
to a file or to the external data queue.
WRITE <file>[+|-] | *
<expression>
where:
<file>
- Any valid output DD statement.
[+|-]
- Specifies whether the output file can be written by further commands or is to be closed, allowing the subsequent commands in the same step to read it. The plus sing (+) allows additional writing; the minus sign (-) closes the output file. The plus or minus sign must be appended immediately after the end of the DD statement. The default is the plus sign (+), meaning that a DD statement without a suffix allows subsequent writing to the file.
*
- Indicates write to the external data queue.
<expression>
- Can be any valid REXX expression.
For more details about REXX expressions and available functions, see TSO/E REXX Reference.
For example:
- To write the text
Hello World
into the file referenced by the OUTDATA statement:WRITE OUTDATA “Hello World”
- To write
A B C
to the external data queue which would allow the data to be processed by a subsequentREAD
statement,OPTIONS POSTPROC(Y)
, or a REXX program that called Workload Automation Programming Language:WRITE * “A B C”
- To write the contents of the
FILE
object variable@MYOBJ
to the OUTDATA DD statement:DO I = 1 TO !@MYOBJ VARSET THISLINE @V(@MYOBJ-!I) WRITE OUTDATA "!THISLINE" END
- To use the REXX variable notation to avoid resolution
issues:
DO FOREVER VARSCAN MYOBJ TARGET(Oh) CURSOR(RX,CX) DISTINCT(Y) CASE(N) COLS(001,080) ACTION(LEAVE) VARSET MYLINE VARIABLE(@MYOBJ-!RX) WRITE OUTDATA com.VAR.MYLINE END
Note: Because theWRITE
command exploits the REXX interpreter, it is sometimes better to use the REXX variable notation to avoid resolution errors. BecauseOBJECT
variables are not accessible in REXX mode, use theVARSET
command to transfer the value to a REXX variable without resolution issues.
Consider that:
- If a
WRITE
command is followed by aREAD
command to the same file, the output file is closed so that theREAD
command can read the data. - When an output file is closed, either explicitly or by a subsequent READ command, if you write to it again, all previous output is lost and output is resumed at record 1. The only exception is when the file is a SYSOUT file, in which case all output data is kept.
- When an output file is closed, all buffered data for that file is committed to disk.