Jzos - Printing

General discussion on the JZOS batch launcher and toolkit
Post Reply
sporanki
Posts: 3
Joined: Thu Sep 21, 2006 11:16 am

Jzos - Printing

Post by sporanki »

Hello Folks

We are using DB2 on ZOS and java, j2ee for business logic etc.

Problem : Need to Print on a ZES printer

Q1. How do i create data sets from java -- for the data in the DB2
Q2. How do i send the created data sets to the printer.
Q3. Can i Use any type of datasets.

Please correct me if i am assuming anything wrong.

Thanks
Suren
dovetail
Site Admin
Posts: 2022
Joined: Thu Jul 29, 2004 12:12 pm

Post by dovetail »

You can use ZFile to write to a SYSOUT dataset (the JES spool).

There are examples in the sample package included with JZOS.
sporanki
Posts: 3
Joined: Thu Sep 21, 2006 11:16 am

jzos printing

Post by sporanki »

import java.io.BufferedWriter;
import java.io.IOException;
import java.io.UnsupportedEncodingException;

import java.util.Iterator;
import java.util.Map;
import java.util.Properties;

import com.dovetail.jzos.FileFactory;
import com.dovetail.jzos.RcException;
import com.dovetail.jzos.ZFile;
import com.dovetail.jzos.ZFileException;
import com.dovetail.jzos.ZUtil;

/**
* Sample program that prints an EBCDIC MVS dataset pointed to by //INPUT DD
* to System.out (stdout).
* <p>
* The dataset is opened using the ZFile class in record mode.
* Note that "noseek" is used so that the file is opened in sequential
* mode, which dramatically increases I/O performance.
*
* @see com.ibm.jzos.ZFile
*/

public class JzosTest {

public static void main(String args[]) {

//getServerProperties();
buildDataSet();

ZFile zFile = null;
try {
// Open the DD and read data
//zFile = new ZFile("//DD:INPUT", "rb,type=record,noseek");
zFile = new ZFile("//MY.DATASET", "rb,type=record,noseek");
byte[] recBuf = new byte[zFile.getLrecl()];
int nRead;
String encoding = ZUtil.getDefaultPlatformEncoding();
while((nRead = zFile.read(recBuf)) > 0) {
String line = new String(recBuf,0,nRead, encoding);
System.out.println(line);
};
} catch(ZFileException zfile) {
System.out.println("ZFileException:"+zfile);
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
try{
zFile.close();
} catch(ZFileException zfile) {
System.out.println("Closing ZFileException:"+zfile);
}
}


}

public static void buildDataSet(){

//to Dynamically create a Data set and write data to it
String ddname = getNextDDName();
// for testing
ddname = "Pnnnnnnn";
BufferedWriter wtr = null;
try {
ZFile.bpxwdyn("alloc fi(" +ddname+") sysout(a) spin(unalloc) recfm(v,b,a) lrecl(133) msg(2)" );

wtr = FileFactory.newBufferedWriter("//DD:" + ddname);
wtr.write("Test Program " + "\n");
wtr.write("Writing data to the created Data Set" + "\n");
wtr.write("End of Data set" + "\n");
}catch(RcException rce) {
System.out.println("RcException:"+rce);
} catch (IOException e) {
e.printStackTrace();
} finally {
if (wtr != null)
try { wtr.close(); } catch(IOException ignore) {}
try{
ZFile.bpxwdyn("free fi(" + ddname+ ") msg(2)");
} catch(RcException rce) {
System.out.println("RcException close :"+rce);
}
}

}
public static void getServerProperties() {

// To get the java properties set on the server
Properties props = System.getProperties();
for (Iterator i=props.entrySet().iterator(); i.hasNext();) {
Map.Entry e = (Map.Entry)i.next();
System.out.println(e.getKey() + " -> " + e.getValue());
}
System.out.println();
System.out.println("PATH=" + ZUtil.getEnv("PATH"));
System.out.println("LIBPATH=" + ZUtil.getEnv("LIBPATH"));
System.out.println("LANG=" + ZUtil.getEnv("LANG"));
System.out.println("TX=" + ZUtil.getEnv("TZ"));
System.out.println("_BPX_SHAREAS=" + ZUtil.getEnv("_BPX_SHAREAS"));
System.out.println("HOME=" + ZUtil.getEnv("HOME"));
}

private static String getNextDDName() {

double rawRandomNumber;

rawRandomNumber = Math.random();
System.out.println("random number : " + rawRandomNumber);

return "DD"+rawRandomNumber;
}


I am having trouble running the above program.
1. How do i send the data set to print on a printer (how do i call the printer from the code.)
2. Are there any sample data sets i can use to read and send it to the printer.

thanks for your patience

Thanks
Suren
dovetail
Site Admin
Posts: 2022
Joined: Thu Jul 29, 2004 12:12 pm

Post by dovetail »

What sort of trouble? An exception or error?
sporanki
Posts: 3
Joined: Thu Sep 21, 2006 11:16 am

Jzos - Printing

Post by sporanki »

We were able to resolve it .

I was under the opinion that we can run the program in windows env but i was wrong. we had to run the test program on zos env on mainframe.

There were some class path issues it was not finding the jzos.jar.

The printer name were using the DRS number but insted we had to use the Node number for the printer, our mainframe folks told us that.

any ways all is good and thanks for your response.

Surendra
Post Reply