Submit batch jobs from Java on z/OS


Typical mainframe batch applications involve payroll, leasing and financing, credit card processing, billing for telecom users, generating purchase orders and raising shipping requests for inventory maintenance applications, and so forth. These applications are initiated by running jobs, which are a set of Job Control Language (JCL) statements. These jobs control the execution of programs. For example, the first program might selectively extract records from a database. The next program might sort the records based on certain criteria and another program might perform some business logic (database updates, some math, and so forth). JCL also has a facility to selectively execute programs. For example, if the first program fails for any reason, the JCL might execute a program that notifies the appropriate people and so on.

Everyone is well aware of all the advantages of Java™ and the impact of the Internet. Generally speaking, a user from the Web can initiate a transaction that might communicate with a mainframe database (DB2®, Information Management System (IMS), and so forth), or even with a Virtual Storage Access Method (VSAM) file. As a result, the mainframe then returns the data in a well-formatted Web page. The Web user can also initiate an update on the mainframe database as well.

The missing link

On one side, you have the highly robust and scalable mainframe. On the other, you have the flexibility of Java and the Web world. As noted above, a typical Web application would initiate a transaction that would do a one-off database access. Is it not possible to trigger a batch cycle or a set of programs to achieve business logic? Since there have been programs already executing under the control of JCL, can't these programs be reused while still accessing them from Web? The answer is "yes", using the following solution.

The basic solution

Mainframes use File Transfer Protocol (FTP) to communicate with the external world. It's possible to submit a job on the mainframe from your desktop using FTP. Let's review the steps.

  1. Create a text file called job.txt, which has a typical mainframe job coded in it.
  2. On your Windows® machine, go to the Command Prompt.
  3. Start a FTP session by connecting to the mainframe. Enter the ID and the password.
  4. Use the quote site command to identify the file as having JCL statements.
  5. Send this file to the mainframe using the FTP put command.

The following is a sample job that can be saved in a text file as job.txt:

Listing 1. Sample text file
//             MSGLEVEL=(1,1),MSGCLASS=C                   

Note: Different mainframe installations have their own standards that might invalidate the previous job. You should talk to your system programmers to be advised of the correct standards.

A typical FTP session would look like the following:

Listing 2. Typical FTP session
ftp my.zos.mainframe 
quote site filetype=jes 
put job.txt 

The Java solution

The Java solution extends the previous basic solution, as follows:

Listing 3. Java solution
package fileTransferProtocol;


public class FileTransferProtocol {
     public static void main (String [ ] args)  { 
     String serverName ="my.zos.mainframe"  ; 
     String userName ="userid" ; 
     String password ="********" ; 
     FTPClient ftp = new FTPClient() ; 
     //Connect to the server 
     try { 
          ftp.connect (serverName) ; 
          String replyText =ftp.getReplyString()  ; 
          System.out.println (replyText) ; 
     catch (Exception  e)  {
               e.printStackTrace () ; 
     //Login to the server 
     try { 
               ftp.login (userName, password) ; 
               String replyText = ftp.getReplyString() ; 
               System.out.println (replyText); 
     } catch (Exception e) { 
     //Tell server that the file will have JCL records 
     try { 
      ("filetype=jes") ; 
               String replyText = ftp.getReplyString() ; 
               System.out.println (replyText) ; 
     catch 	(Exception e) { 
               e.printStackTrace() ; 
     //Submit the job from the text file.Use \\ to avoid using escape notation 
     try { 
               FileInputStream inputStream = new FileInputStream ("C:\\job.txt") ; 
               ftp.storeFile (serverName,inputStream) ; 
               String replyText = ftp.getReplyString() ; 
               System.out.println (replyText) ; 
     catch	(Exception e) { 
               e.printStackTrace() ; 
     //Quit the server 
     try { 
                 ftp.quit() ; 
     catch 	(Exception e) { 
                e.printStackTrace() ; 

In the previous example, a basic FTP package is imported that is used to do all of the FTP commands, as mentioned in the basic solution. The package used is Commons/Net from the Apache. It's available for download from:

For this program to compile successfully, the CLASSPATH must point to commons-net-1.0.0.jar.

As of now, the above code uses a hard-coded name for the text file. You can modify it to read in the file name automatically.


In this article, you learned how to use a Java program to submit batch jobs from a z/OS mainframe. This program is the missing link between the traditional batch processing capability of a mainframe and the flexibility of the Web. You can schedule batch jobs on demand rather than being dependent on certain date/time constraints. You can also reuse existing programs. No changes would be needed, as the mode of execution (through the job scheduler or Web using FTP) would be transparent to the program.

FTP, by design, is a clear text protocol and hence, vulnerable to eavesdropping. It is also possible to sneak in some jobs with malicious intent using FTP. However, you can tackle this threat by setting appropriate Resource and Access Control Facility (RACF) groups and/or firewalls.

Downloadable resources

Related topics

  • The Jakarta Commons project focuses on all aspects of reusable Java components.
  • Want more? The developerWorks eServer zone hosts hundreds of informative articles and introductory, intermediate, and advanced tutorials on the eServer brand.


Sign in or register to add and subscribe to comments.

Zone=Java development
ArticleTitle=Submit batch jobs from Java on z/OS