Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to handle Unix text file with stem vars

1,195 views
Skip to first unread message

Donald Johnson

unread,
Jan 17, 2012, 8:32:57 AM1/17/12
to
Hello Rexxperts near and far!

I am expanding my use of the Unix files on z/OS, and have a couple
questions that Google did not readily answer. I know that someone here must
have done this (John M, at least), so I would appreciate your pointing me
in the right direction.

First, is there any easy way, from my Rexx program, to get the directory
entries from this Unix directory, without doing FTP and capturing the
output? I would like to get the filename, size and date/time attributes.

Then, once I have the file listing, I would like to read the contents of
one of these files into Rexx stem variables, directly if possible, without
having to FTP the file to some temporary z/OS file.

Finally, after modifying some of the data in these variables (possibly
adding some lines), I would like to put the whole, updated file back into
the directory.

I am sure that if this can be done, someone here can point me toward
examples or provide me the bones on which I can put the meat.

Thanks so much for your kind assistance!
*don*

----------------------------------------------------------------------
For TSO-REXX subscribe / signoff / archive access instructions,
send email to LIST...@VM.MARIST.EDU with the message: INFO TSO-REXX

Donald Johnson

unread,
Jan 17, 2012, 9:07:25 AM1/17/12
to
Incidentally, this is via TSO interactive, not batch.
*don*

Ward Able, Grant

unread,
Jan 17, 2012, 9:18:23 AM1/17/12
to
Don - I don't know if you are aware of it or not, but there is a manual specifically on using Rexx with USS and it ought to cover this request of yours:

http://publib.boulder.ibm.com/infocenter/zos/v1r12/topic/com.ibm.zos.r12.bpxb600/toc.htm



If that isn't sufficient, just yell & we'll take it from there.....



Regards - Grant.

Telephone Internal: x1496 London

Telephone External: +44 (0)207 650 1496



-----Original Message-----

From: TSO REXX Discussion List [mailto:TSO-...@VM.MARIST.EDU] On Behalf Of Donald Johnson

Sent: 17 January 2012 13:32

To: TSO-...@VM.MARIST.EDU

Subject: [TSO-REXX] How to handle Unix text file with stem vars
<BR>_____________________________________________________________

<FONT size=2><BR>

DTCC DISCLAIMER: This email and any files transmitted with it are

confidential and intended solely for the use of the individual or

entity to whom they are addressed. If you have received this email

in error, please notify us immediately and delete the email and any

attachments from your system. The recipient should check this email

and any attachments for the presence of viruses. The company

accepts no liability for any damage caused by any virus transmitted

by this email.</FONT>

Jeff Byrum

unread,
Jan 17, 2012, 9:21:40 AM1/17/12
to
See IBM Manual "Using REXX and z/OS UNIX System Services"

-----Original Message-----
From: TSO REXX Discussion List [mailto:TSO-...@VM.MARIST.EDU] On Behalf Of Donald Johnson

Paul Gilmartin

unread,
Jan 17, 2012, 9:24:49 AM1/17/12
to
On Jan 17, 2012, at 06:32, Donald Johnson wrote:
>
> I am expanding my use of the Unix files on z/OS, and have a couple
> questions that Google did not readily answer. I know that someone here must
> have done this (John M, at least), so I would appreciate your pointing me
> in the right direction.
>
"address SYSCALL" is your friend. And it can be used alike
from TSO, shell, or IRXJCL.

> First, is there any easy way, from my Rexx program, to get the directory
> entries from this Unix directory, without doing FTP and capturing the
> output? I would like to get the filename, size and date/time attributes.
>
address SYSCALL opendir ...; address SYSCALL readdir ...

(FSVO "easy")

> Then, once I have the file listing, I would like to read the contents of
> one of these files into Rexx stem variables, directly if possible, without
> having to FTP the file to some temporary z/OS file.
>
address SYSCALL readfile ...
- or -
call BPXWDYN 'alloc path(''...'') ...'; address MVS 'execio * diskr ...'

You seem quite fixated on FTP. I'd use IEBGENER for much of this.
I seem quite fixated on IEBGENER.

> Finally, after modifying some of the data in these variables (possibly
> adding some lines), I would like to put the whole, updated file back into
> the directory.
>
address SYSCALL writefile ...

> I am sure that if this can be done, someone here can point me toward
> examples or provide me the bones on which I can put the meat.
>
http://publibz.boulder.ibm.com/cgi-bin/bookmgr_OS390/BOOKS/bpxzb6a0

Title: z/OS V1R12.0 Using REXX and z/OS UNIX System Services
Document Number: SA22-7806-13

On Jan 17, 2012, at 07:06, Donald Johnson wrote:

> Incidentally, this is via TSO interactive, not batch.
>
Don't. Use rlogin or ssh directly to shell.

-- gil

Donald Johnson

unread,
Jan 17, 2012, 9:29:13 AM1/17/12
to
Thanks to everyone for the manual reference...off to do some reading...I
will be back if I have problems, but I think I will get it.
*don*

Paul Gilmartin

unread,
Jan 17, 2012, 11:02:20 AM1/17/12
to
On Jan 17, 2012, at 06:32, Donald Johnson wrote:
>
> First, is there any easy way, from my Rexx program, to get the directory
> entries from this Unix directory, without doing FTP and capturing the
> output? I would like to get the filename, size and date/time attributes.
>
From various environments you can use "BPXWUNIX ... 'ls -al'" directly
to a stem.

From shell, you can use "address SH 'ls -al >tempfile'" then
readfile tempfile

from TMP you can "address TSO 'BPXBATCH ...'" and perhaps
OUTTRAP the result (I haven't tried this).

You might consider subscribing to MVS-OE:

http://vm.marist.edu/htbin/wlvindex?MVS-OE

... or not; John M. and I tend to hang out there.

-- gil

Donald Johnson

unread,
Jan 17, 2012, 1:22:21 PM1/17/12
to
Based on what I have read so far, I think I will not be able to accomplish
this. Am I correct that I will not be able to access the file directory and
files on another Unix server? In other words, the files are not in Unix USS
on my machine, but are on an actual *nix server on a separate physical
machine. Is my only option then to use FTP?
*don*

Robert Zenuk

unread,
Jan 17, 2012, 1:33:41 PM1/17/12
to
Have you looked into NFS? Mount the target directory using the z/OS NFS client, then the same stuff you just read can be used...

Rob



-----Original Message-----
From: Donald Johnson <dej...@GMAIL.COM>
To: TSO-REXX <TSO-...@VM.MARIST.EDU>
Sent: Tue, Jan 17, 2012 11:17 am
Subject: Re: How to handle Unix text file with stem vars


Based on what I have read so far, I think I will not be able to accomplish
his. Am I correct that I will not be able to access the file directory and
iles on another Unix server? In other words, the files are not in Unix USS
n my machine, but are on an actual *nix server on a separate physical
achine. Is my only option then to use FTP?

John McKown

unread,
Jan 17, 2012, 9:27:59 PM1/17/12
to
I hang out here, too. That is, if I am the "John M." of whom you write.
I just don't say much here as I don't do as much with TSO/REXX any
more.

I have a vague memory of someone here indicating that this forum is, as
the name implies, for REXX use within the TSO environment __ONLY__. No
general REXX questions (IRXJCL) or UNIX REXX questions. Now, use of UNIX
facilities while in a REXX program invoked in TSO is a bit "iffy".

But, since I'm mouthing off anyway, I'd go with the posted URL and use
"syscalls" with readdir(). The methods you mentioned, though useful in a
general sense, have more overhead than I like, since the bpxunix() does
at least two fork()'s (one to run the /bin/sh -c, which then does
another to run the actual program - this may or may not require creating
more address spaces, a "costly" proposition on z/OS compared to other
UNIX systems). I do use bpxwunix for more complicated stuff, such as
running an awk program. I wish I could figure out how to do regex stuff
in native REXX!

I also use readfile() and writefile() to read and write from/to a UNIX
file and a REXX stem variable. I don't have any real liking for EXECIO
and never have had. Especially for UNIX files since I also need to do an
allocate, which is more complicated (to me). If the file may be too
large, I'd use read() and write() in a loop.
--
John McKown
Maranatha! <><

John McKown

unread,
Jan 17, 2012, 9:44:32 PM1/17/12
to
Well, unless the remote files are NFS mounted to z/OS, you are stuck
with some sort of file transfer such as ftp or sftp (ftp-like function
of ssh, if you have ssh on z/OS. I don't think all shops implement ssh).
Oh, or a Samba (CIFS) mount could possibly work as well. That's all that
I can think of which could be considered "standard".

Totally off-topic to REXX, but maybe of use for your needs:
Have you looked at the Co:Z product from Dovetailed Technologies? It is
freely licensed (zero cost!) and can be simply downloaded from their web
site. No registration required. No special authorities in z/OS needed to
to install or run, so if you're smart enough in z/OS UNIX, you could
install your own personal copy.
http://dovetail.com/products/dspipes.html
Consists of both a z/OS and UNIX (AIX, Linux/Intel, z/Linux) portion.
Does some really neat things to run "remote" UNIX commands over an SSH
connection between z/OS and the UNIX system. I.e. you basically have an
ssh session from z/OS as the client to the UNIX system, running programs
on the UNIX systems, with the output coming back to your z/OS "job".
Comes with a couple of programs to install on the UNIX system so which
can "pipe" dataset records from z/OS into the UNIX system and then back
to the z/OS system, and put the results in another z/OS dataset
(sequential dataset, not z/OS UNIX file). Oh, also supports Windows,
somehow. I don't __do__ Windows, so I know nothing of that.

On Tue, 2012-01-17 at 13:12 -0500, Donald Johnson wrote:
> Based on what I have read so far, I think I will not be able to accomplish
> this. Am I correct that I will not be able to access the file directory and
> files on another Unix server? In other words, the files are not in Unix USS
> on my machine, but are on an actual *nix server on a separate physical
> machine. Is my only option then to use FTP?
> *don*
>

--
John McKown
Maranatha! <><

Donald Johnson

unread,
Jan 18, 2012, 8:49:47 AM1/18/12
to
John, there is some great info here, and I appreciate your guidance. I have
found out that we have an appliance here to share file systems - probably a
Samba server. I hope to learn more from those infrastructure guys today. I
will also look at Co:Z to see what that offers.

Thanks again - I will let you know if I run into anything else
*don*

Robert Zenuk

unread,
Jan 18, 2012, 12:25:25 PM1/18/12
to
If you can use the TSO MOUNT command to mount the directory using NFS from z/OS everything should work as explained. You might check to see if you have the MVSNFSC task (z/OS NFS Client) running (default name). The other challenges are file permissions and your effective GID/UID. Assuming you can work through these, the REXX is pretty simple. I have some example code that does what you want. In my case it was simply removing line numbers from the end of each record that had line numbers and rewriting the file.

Here is the code (not pretty - include lots of debugging mesages).

000001 /*********************************************************************/
000002 /* REXX */
000003 /*********************************************************************/
000004 /* Purpose: Sample USS REXX EXEC */
000005 /*-------------------------------------------------------------------*/
000006 /* Syntax: USSRDRF path */
000007 /*-------------------------------------------------------------------*/
000008 /* Parms: PATH - Fully qualified path to a directory */
000009 /* */
000010 /*********************************************************************/
000011 /* Change Log */
000012 /* */
000013 /* Author Date Reason */
000014 /* -------- --------- ----------------------------------------- */
000015 /* R. Zenuk Jan 2012 Initial Creation */
000016 /* */
000017 /*********************************************************************/
000018 parse arg path
000019 /*********************************************************************/
000020 /* Dub the address space to allow it to use USS REXX commands */
000021 /*********************************************************************/
000022 if syscalls('ON') <> 0 then say 'Error dubbing address space'
000023 /*********************************************************************/
000024 /* Use the readdir command */
000025 /*********************************************************************/
000026 EXITRC = ussapi('readdir' path 'file.' 'stat.')
000027 /*********************************************************************/
000028 /* Print the results */
000029 /*********************************************************************/
000030 say 'Files found in' path
000031 do i=1 to file.0
000032 select
000033 when stat.i.ST_TYPE = S_ISDIR then say file.i 'DIRECTORY'
000034 when stat.i.ST_TYPE = S_ISREG then
000035 do
000036 filepath = path||file.i
000037 EXITRC = ussapi('readfile' filepath 'rec.')
000038 if EXITRC = 0 then
000039 do
000040 say center(' FILE:' file.i 'BEGIN ',78,'-')
000041 do j=1 to rec.0
000042 say 'BEFORE RECORD:'j 'LENGTH:'length(rec.j)': 'rec.j
000043 if datatype(right(rec.j,8)) = 'NUM' then
000044 rec.j = strip(substr(rec.j,1,length(rec.j)-8))
000045 say 'AFTER RECORD:'j 'LENGTH:'length(rec.j)': 'rec.j
000046 mode = '777'
000047 EXITRC = ussapi('writefile' filepath mode 'rec.')
000048 end
000049 say center(' FILE:' file.i rec.0 'RECORDS ',78,'-')
000050 end
000051 end
000052 otherwise say file.i 'TYPE='stat.i.ST_TYPE
000053 end
000054 end
000055 /*********************************************************************/
000056 /* Undub */
000057 /*********************************************************************/
000058 call syscalls('OFF')
000059 exit(EXITRC)
000060 /*********************************************************************/
000061 /* USS API subroutine - execute API and generic error handling */
000062 /*********************************************************************/
000063 ussapi: parse arg usscmd
000064 say center(' Before' usscmd' ',76,'-')
000065 address SYSCALL usscmd
000066 say 'RETVAL='RETVAL 'ERRNO='ERRNO 'ERRNOJR='ERRNOJR
000067 if ERRNO <> 0 | ERRNOJR <> 0 then
000068 do
000069 address SYSCALL 'strerror' ERRNO ERRNOJR 'err.'
000070 say
000071 say err.SE_ERRNO
000072 say
000073 parse var err.SE_REASON . '15'x errmsg
000074 say errmsg
000075 say
000076 say err.SE_ACTION
000077 end
000078 say center(' After' usscmd' ',76,'-')
000079 return RETVAL


Rob



-----Original Message-----
From: Donald Johnson <dej...@GMAIL.COM>
To: TSO-REXX <TSO-...@VM.MARIST.EDU>
Sent: Wed, Jan 18, 2012 6:48 am
Subject: Re: How to handle Unix text file with stem vars


John, there is some great info here, and I appreciate your guidance. I have
ound out that we have an appliance here to share file systems - probably a
amba server. I hope to learn more from those infrastructure guys today. I
ill also look at Co:Z to see what that offers.
Thanks again - I will let you know if I run into anything else
don*
0 new messages