Skip to main content

By clicking Submit, you agree to the developerWorks terms of use.

The first time you sign into developerWorks, a profile is created for you. Select information in your developerWorks profile is displayed to the public, but you may edit the information at any time. Your first name, last name (unless you choose to hide them), and display name will accompany the content that you post.

All information submitted is secure.

  • Close [x]

The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerworks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

By clicking Submit, you agree to the developerWorks terms of use.

All information submitted is secure.

  • Close [x]

Submit batch jobs from Java on z/OS

Nagesh Subrahmanyam (nsubrahm@in.ibm.com), Software Developer, IBM 
Nagesh Subrahmanyam is a Software Developer in IBM Global Services, India. He has a total of four and half years of experience in the software industry. His knowledge and skills are mainly related to mainframes, but he also uses Java, JavaScript, XML, and so forth whenever necessary. You can contact him at nsubrahm@in.ibm.com.

Summary:  Learn how to reuse programs while still accessing them from Web. Historically, the mainframe has had a huge capacity of processing high volumes of data in batch by running Job Control Language (JCL) statements that control the execution of programs. In this article, Nagesh Subrahmanyam provides step-by-step instructions on how to use a Java™ program to submit batch jobs from a z/OS® mainframe -- the missing link between the traditional batch processing capability of a mainframe and the flexibility of the Web.

Date:  15 Dec 2005
Level:  Intermediate

Activity:  9839 views
Comments:  

Introduction

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
                
//XXXXXXXJ JOB (ACCTCODE),'NAGESH',NOTIFY=D245241,CLASS=I,
//             MSGLEVEL=(1,1),MSGCLASS=C                   
//*                                                         
//STEP1    EXEC PGM=IEFBR14

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 
userid 
password 
quote site filetype=jes 
put job.txt 
quit


The Java solution

The Java solution extends the previous basic solution, as follows:
Listing 3. Java solution

                    
package fileTransferProtocol;

import org.apache.commons.net.ftp.*; 
import java.io.*;

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) { 
               e.printStackTrace(); 
     } 
     //Tell server that the file will have JCL records 
     try { 
               ftp.site ("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:http://jakarta.apache.org/commons/index.html.

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.


Conclusion

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.


Resources

Learn

  • 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.

  • The IBM developerWorks team hosts hundreds of technical briefings around the world which you can attend at no charge.

Discuss

About the author

Nagesh Subrahmanyam is a Software Developer in IBM Global Services, India. He has a total of four and half years of experience in the software industry. His knowledge and skills are mainly related to mainframes, but he also uses Java, JavaScript, XML, and so forth whenever necessary. You can contact him at nsubrahm@in.ibm.com.

Report abuse help

Report abuse

Thank you. This entry has been flagged for moderator attention.


Report abuse help

Report abuse

Report abuse submission failed. Please try again later.


developerWorks: Sign in


Need an IBM ID?
Forgot your IBM ID?


Forgot your password?
Change your password

By clicking Submit, you agree to the developerWorks terms of use.

 


The first time you sign into developerWorks, a profile is created for you. Select information in your developerWorks profile is displayed to the public, but you may edit the information at any time. Your first name, last name (unless you choose to hide them), and display name will accompany the content that you post.

Choose your display name

The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerWorks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

(Must be between 3 – 31 characters.)

By clicking Submit, you agree to the developerWorks terms of use.

 


Rate this article

Comments

Help: Update or add to My dW interests

What's this?

This little timesaver lets you update your My developerWorks profile with just one click! The general subject of this content (AIX and UNIX, Information Management, Lotus, Rational, Tivoli, WebSphere, Java, Linux, Open source, SOA and Web services, Web development, or XML) will be added to the interests section of your profile, if it's not there already. You only need to be logged in to My developerWorks.

And what's the point of adding your interests to your profile? That's how you find other users with the same interests as yours, and see what they're reading and contributing to the community. Your interests also help us recommend relevant developerWorks content to you.

View your My developerWorks profile

Return from help

Help: Remove from My dW interests

What's this?

Removing this interest does not alter your profile, but rather removes this piece of content from a list of all content for which you've indicated interest. In a future enhancement to My developerWorks, you'll be able to see a record of that content.

View your My developerWorks profile

Return from help

static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=Java technology
ArticleID=100786
ArticleTitle=Submit batch jobs from Java on z/OS
publish-date=12152005
author1-email=nsubrahm@in.ibm.com
author1-email-cc=

Tags

Help
Use the search field to find all types of content in My developerWorks with that tag.

Use the slider bar to see more or fewer tags.

For articles in technology zones (such as Java technology, Linux, Open source, XML), Popular tags shows the top tags for all technology zones. For articles in product zones (such as Info Mgmt, Rational, WebSphere), Popular tags shows the top tags for just that product zone.

For articles in technology zones (such as Java technology, Linux, Open source, XML), My tags shows your tags for all technology zones. For articles in product zones (such as Info Mgmt, Rational, WebSphere), My tags shows your tags for just that product zone.

Use the search field to find all types of content in My developerWorks with that tag. Popular tags shows the top tags for this particular content zone (for example, Java technology, Linux, WebSphere). My tags shows your tags for this particular content zone (for example, Java technology, Linux, WebSphere).

Special offers