I am writing some java code that creates a file on my zOS system via some java code running on the mainframe. After this file is created I want to be able to submit it as batch.
I have tried using the tso sub command with both the -o and -t flags in use, but have been told that since tso sub is an APF authorized command I cannot use it directly from Java. It was then recommended that I use a REXX script to get the job done, but I am trying to develop this program solely on Java. I am sure there must be a back-door way to submit a batch job via Java.
Can anyone help me???
Submit Batch via Java
-
- Posts: 48
- Joined: Tue Jun 12, 2007 2:46 pm
The following is a Java package to allow JCL submission
[code]
package com.healthmarkets.util;
/*
* submit.java
*
* Created on February 5, 2007, 1:51 PM
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
/**
*
* @author John.Mckown
*/
import com.ibm.jzos.*;
import java.io.*;
public class submit {
private BufferedWriter intrdr=null;
private String ddname=null;
private boolean debug=false;
private int cardCount=0;
/** Creates a new instance of submit */
public submit()
throws java.io.IOException
{
ddname=ZFile.allocDummyDDName();
ZFile.bpxwdyn("free fi("+ddname+")");
ZFile.bpxwdyn("alloc fi("+ddname+") sysout(x) writer(INTRDR) recfm(f) lrecl(80) msg(2) reuse");
intrdr=FileFactory.newBufferedWriter("//DD:"+ddname);
}
public void write(String statement)
throws java.io.IOException
{
if (debug) System.err.println("write String");
cardCount++;
if (statement.length() > 80) throw new java.io.IOException("Record too long");
intrdr.write(statement+"\n");
if (debug) System.err.println(statement+"\n");
}
public void write(String[] statements)
throws java.io.IOException
{
int i;
if (debug) System.err.println("write String[]");
for(i=0;i<statements.length;i++) {
if (statements[i].length() > 80) throw new java.io.IOException("Record too long");
intrdr.write(statements[i]+"\n");
if (debug) System.err.println(statements[i]+"\n");
cardCount++;
}
}
public void setDebug(boolean debug)
{
System.err.println("setDebug("+debug+")");
this.debug=debug;
}
public void write(ZFile file)
throws ZFileException, java.io.IOException
{
byte[] buffer= new byte[file.getLrecl()];
int bytesRead;
if (debug) System.err.println("write ZFile");
if (buffer.length > 80) throw new java.io.IOException("LRECL > 80");
while((bytesRead=file.read(buffer))>=0) {
intrdr.write(new String(buffer)+"\n");
if (debug) System.err.println(new String(buffer)+"\n");
cardCount++;
}
file.close();
}
public void write(java.io.File file)
throws java.io.IOException
{
if (debug) System.err.println("write java.io.File");
if (! file.exists()) throw new java.io.IOException("File does not exist");
if (! file.isFile()) throw new java.io.IOException("Not a valie UNIX file");
if (! file.canRead()) throw new java.io.IOException("Cannot read UNIX file");
BufferedReader input=new BufferedReader( new FileReader(file));
String line=null;
while ((line=input.readLine())!=null) {
intrdr.write(line+"\n");
if (debug) System.err.println(line+"\n");
cardCount++;
}
input.close();
input=null;
}
public void close()
throws java.io.IOException
{
if (debug) System.err.println("close");
intrdr.close();
ZFile.bpxwdyn("free fi("+ddname+") msg(2)");
System.err.println("Wrote "+cardCount+" JCL statements");
}
public void abort()
throws java.io.IOException
{
if (debug) System.err.println("abort");
write("/*PURGE");
close();
}
}
[/code]
[code]
package com.healthmarkets.util;
/*
* submit.java
*
* Created on February 5, 2007, 1:51 PM
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
/**
*
* @author John.Mckown
*/
import com.ibm.jzos.*;
import java.io.*;
public class submit {
private BufferedWriter intrdr=null;
private String ddname=null;
private boolean debug=false;
private int cardCount=0;
/** Creates a new instance of submit */
public submit()
throws java.io.IOException
{
ddname=ZFile.allocDummyDDName();
ZFile.bpxwdyn("free fi("+ddname+")");
ZFile.bpxwdyn("alloc fi("+ddname+") sysout(x) writer(INTRDR) recfm(f) lrecl(80) msg(2) reuse");
intrdr=FileFactory.newBufferedWriter("//DD:"+ddname);
}
public void write(String statement)
throws java.io.IOException
{
if (debug) System.err.println("write String");
cardCount++;
if (statement.length() > 80) throw new java.io.IOException("Record too long");
intrdr.write(statement+"\n");
if (debug) System.err.println(statement+"\n");
}
public void write(String[] statements)
throws java.io.IOException
{
int i;
if (debug) System.err.println("write String[]");
for(i=0;i<statements.length;i++) {
if (statements[i].length() > 80) throw new java.io.IOException("Record too long");
intrdr.write(statements[i]+"\n");
if (debug) System.err.println(statements[i]+"\n");
cardCount++;
}
}
public void setDebug(boolean debug)
{
System.err.println("setDebug("+debug+")");
this.debug=debug;
}
public void write(ZFile file)
throws ZFileException, java.io.IOException
{
byte[] buffer= new byte[file.getLrecl()];
int bytesRead;
if (debug) System.err.println("write ZFile");
if (buffer.length > 80) throw new java.io.IOException("LRECL > 80");
while((bytesRead=file.read(buffer))>=0) {
intrdr.write(new String(buffer)+"\n");
if (debug) System.err.println(new String(buffer)+"\n");
cardCount++;
}
file.close();
}
public void write(java.io.File file)
throws java.io.IOException
{
if (debug) System.err.println("write java.io.File");
if (! file.exists()) throw new java.io.IOException("File does not exist");
if (! file.isFile()) throw new java.io.IOException("Not a valie UNIX file");
if (! file.canRead()) throw new java.io.IOException("Cannot read UNIX file");
BufferedReader input=new BufferedReader( new FileReader(file));
String line=null;
while ((line=input.readLine())!=null) {
intrdr.write(line+"\n");
if (debug) System.err.println(line+"\n");
cardCount++;
}
input.close();
input=null;
}
public void close()
throws java.io.IOException
{
if (debug) System.err.println("close");
intrdr.close();
ZFile.bpxwdyn("free fi("+ddname+") msg(2)");
System.err.println("Wrote "+cardCount+" JCL statements");
}
public void abort()
throws java.io.IOException
{
if (debug) System.err.println("abort");
write("/*PURGE");
close();
}
}
[/code]
-
- Posts: 30
- Joined: Thu Jan 25, 2007 8:31 am
- Location: Bengaluru, India
Here is something more : Submit batch jobs from Java
Debugging tip:
When you have eliminated all which is impossible, then whatever remains, however improbable, must be the truth.
--Sherlock Holmes
When you have eliminated all which is impossible, then whatever remains, however improbable, must be the truth.
--Sherlock Holmes