Submit Batch via Java

General discussion on the JZOS batch launcher and toolkit
Post Reply
butters83
Posts: 6
Joined: Tue May 29, 2007 9:52 am

Submit Batch via Java

Post by butters83 »

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???

:(
john.mckown
Posts: 48
Joined: Tue Jun 12, 2007 2:46 pm

Post by john.mckown »

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]
Cogito-Ergo-Sum
Posts: 30
Joined: Thu Jan 25, 2007 8:31 am
Location: Bengaluru, India

Post by Cogito-Ergo-Sum »

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
dovetail
Site Admin
Posts: 2022
Joined: Thu Jul 29, 2004 12:12 pm

Post by dovetail »

BTW - the latest version of JZOS on alphaWorks (2.1.1) has sample code for submitting JCL and getting job status via a REXX child process. This has the advantage of returning the jobname and jobid of the submitted job.
mwilliam
Posts: 37
Joined: Mon Oct 11, 2004 3:21 pm

Post by mwilliam »

Just curious? :roll:
Is it possible, alone with obtaining the Job Id, to get the start and ending times of a particular Jobname, with the above REXX child process?
Post Reply