Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Writing to output dataset using REXX 1

Status
Not open for further replies.

Sreen4u

Programmer
Mar 27, 2012
2
AU
Hi,
I am the REXX beginner and tried the below REXX but not writing the content from input dataset to output dataset.

/* REXX */
"alloc shr file(input) dataset('CSCSG1.REXX.INPUT')"
"alloc shr file(out) dataset('CSCSG1.REXX.OUTPUT')"
"execio * diskr input (finis stem input."
"free file(input)"
do i = 1 to input.0
"execio input.i diskw out (stem out. finis"
end
"free file(out)"
exit

The below REXX displaying the content:

/* REXX */
"alloc shr file(input) dataset('CSCSG1.REXX.INPUT')"
"execio * diskr input (finis stem input."
"free file(input)"
do i = 1 to input.0
say input.i
end
exit

Can you help me what's wrong in the above REXX ?
 
Can you help me what's wrong in the above REXX?

First, get into the habit of properly allocating DD's in TSO. There's no reason NOT to always use the REUSE keyword. So, re-do your allocations:

alloc shr reu fi(input) da('CSCSG1.REXX.INPUT')
alloc shr reu fi(out) da('CSCSG1.REXX.OUTPUT')

Next, your REXX code. This is fine for a limited amount of input:

"execio * diskr input (finis stem input."

to build a stem variable "input." with "n" number of elements. EXECIO will set the zero element, "input.0" to contain the total count of the elements in the stem variable.

If your concept is to just copy the entire contents of the stem variable to the output, then one command is enough:

"execio * diskw out (finis stem input." or, better,
"execio "input.0" diskw out (finis stem input."

There is no need to also loop through the stem variable.

So, a better way is:

/* REXX */
"alloc shr reu f(input) da('CSCSG1.REXX.INPUT')"
"alloc shr reu f(out) da('CSCSG1.REXX.OUTPUT')"
"execio * diskr input (finis stem input."
"free f(input)"
"execio "input.0" diskw out (stem out. finis"
"free f(out)"
exit

or,

/* REXX */
"alloc shr reu f(input) da('CSCSG1.REXX.INPUT')"
"alloc shr reu f(out) da('CSCSG1.REXX.OUTPUT')"
"execio * diskr input (finis stem input."
"free f(input)"
do loop = 1 to input.0
queue input.loop
end
"execio "queued()" diskw out (finis"
"free f(out)"
exit

or, if the input dataset is rather large,

/* REXX */
"alloc shr reu f(input) da('CSCSG1.REXX.INPUT')"
"alloc shr reu f(out) da('CSCSG1.REXX.OUTPUT')"
do forever
"execio 1 diskr input"
if rc <> 0 then leave
parse pull record
push record
"execio 1 diskw out"
end
"execio 0 diskr input"
"execio 0 diskw out"
"free f(input out)"
exit
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top