WebSphere Application Server & Liberty

JSR-352 (Java Batch) Post #93: Using the JZOS Library and Accessing Datasets

By David Follis posted Wed June 03, 2020 07:54 AM

This post is part of a series delving into the details of the JSR-352 (Java Batch) specification. Each post examines a very specific part of the specification and looks at how it works and how you might use it in a real batch application.

To start at the beginning, follow the link to the first post.

The next post in the series is here.

This series is also available as a podcast on iTunesGoogle PlayStitcher, or use the link to the RSS feed

Today’s topic isn’t really specific to writing JSR-352 Java Batch applications in Liberty.  It is just a question that often comes up when writing Java applications intended to run on z/OS.  In fact, as I’m writing this, a question popped up about it on IBM-Main. 

So, you have some pile of data that exists in a z/OS dataset.  Maybe it is a sequential dataset or a member of a PDS.  Or maybe you’ve got a VSAM dataset that’s been in use forever.  How do you access that stuff from Java?  Regular Java file access methods are going to look for files in the USS file system, but you could copy your dataset there.  And Java file access methods are going to assume ASCII encoding (which probably isn’t the case for you – although you can address this if you’re careful).  And, of course, it doesn’t help at all with VSAM.

JZOS to the rescue!  Originally created by Dovetail Technologies but long-since included in the z/OS JVM, is the JZOS library.  JZOS is actually two things.  There’s a JVM launcher which provides a handy way to spin up a JVM and run Java from JCL (simpler than using BPXBATCH to run a script that starts a JVM).  But JZOS is also a set of Java libraries usable from any Java program running on z/OS.

To access datasets (VSAM or otherwise) you’ll want to have a look at the ZFile class which provides methods to do all sorts of z/OS file operations.  One thing I’ve learned to be careful about is the allocation of new files using ZFile.  There’s no provision (at least that I know of) to specify much in the way of file attributes, especially size.  If you need to allocate a new, really big, file then you likely won’t get what you want just using the defaults ZFile will provide.  To get around this, ZFile includes an API called bpxwdyn which wrappers the USS BPXWDYN API which is really just a wrapper around native z/OS dynamic allocation (SVC 99).  Using that successfully to allocate a larger dataset (or one with other special attributes outside the defaults ZFile provides) will require some specialized knowledge and probably some research.

JZOS also provides a long list of other z/OS specific APIs to let you do things like issue WTOs (if your batch applications interact with your automation) and obtain ENQs (which are sometimes used to coordinate activity between clever, concurrently running batch applications).

Take a look…there’s some cool stuff in there.