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 Worldinto the file referenced by the OUTDATA statement:WRITE OUTDATA “Hello World” - To write
A B Cto the external data queue which would allow the data to be processed by a subsequentREADstatement,OPTIONS POSTPROC(Y), or a REXX program that called Workload Automation Programming Language:WRITE * “A B C” - To write the contents of the
FILEobject variable@MYOBJto 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 ENDNote: Because theWRITEcommand exploits the REXX interpreter, it is sometimes better to use the REXX variable notation to avoid resolution errors. BecauseOBJECTvariables are not accessible in REXX mode, use theVARSETcommand to transfer the value to a REXX variable without resolution issues.
Consider that:
- If a
WRITEcommand is followed by aREADcommand to the same file, the output file is closed so that theREADcommand 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.