Hi,
I am aware that we can do a dfSort in java. But I have not seen an method to get the Output stream of multiple output files for DFSORT. Like if we want to split a file based on some condition we give OUTFIL,FNAMES=A,.. etc.. So is that not possible in jzos dfSort?
DfSort multiple sortout file in java/jzos
-
- Posts: 2
- Joined: Fri May 14, 2010 6:11 pm
- Skillset: JCL,COBOL,Eazytrieve
- Referer: through google search
-
- Global moderator
- Posts: 3805
- Joined: Tue Jan 25, 2011 12:02 am
- Skillset: Easytrieve Plus, Cobol, Utilities, that sort of stuff
- Referer: Google
Re: DfSort multiple sortout file in java/jzos
Can you show the documentation you a using (a link will do) and the Java code and the JCL. It should be possible.
-
- Posts: 2
- Joined: Fri May 14, 2010 6:11 pm
- Skillset: JCL,COBOL,Eazytrieve
- Referer: through google search
Re: DfSort multiple sortout file in java/jzos
Hi,
I am using this IBM manual as a reference to build a java program to invoke DfSort within java. Apparently there is only one dfSort.getChildStdoutStream() method which give the output stream for the sortout. Which makes me think we cant use OUTFIL,FNAMES= in the method dfSort.addControlStatement(""). If it can be used I want to get a separate getChildStdoutStream() for each of the output files. The sample java code given by IBM is below
http://www-01.ibm.com/support/knowledge ... oJava.html
I am using this IBM manual as a reference to build a java program to invoke DfSort within java. Apparently there is only one dfSort.getChildStdoutStream() method which give the output stream for the sortout. Which makes me think we cant use OUTFIL,FNAMES= in the method dfSort.addControlStatement(""). If it can be used I want to get a separate getChildStdoutStream() for each of the output files. The sample java code given by IBM is below
http://www-01.ibm.com/support/knowledge ... oJava.html
Code: Select all
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Iterator;
import java.util.List;
import com.ibm.jzos.DfSort;
import com.ibm.jzos.RcException;
import com.ibm.jzos.ZFile;
/**
* This example creates an instance of {@link DfSort} to sort an existing Dataset
* and read the sort output into Java.
* <p>
* Arguments (supplied as key=value pairs):
* <dl>
* <dt>sortin=<dsn></dt>
* <dd>The name of a RECFM=F dataset to sort. Supplied to DFSORT as SORTIN.</dd>
* <dt>[encoding=<codepage>]</dt>
* <dd>The character set of the SORTIN dataset. If not supplied, binary data is assumed.</dd>
* <dt>[shareas=<yes | no>]</dt>
* <dd>Determines that address space for DFSORT. If yes, DFSORT will run in the same address
* space as the JVM. If no, it will run in a separate address space.</dd>
* <dt>[loglevel=<n>]</dt>
* <dd>Sets the logging level for the child process and prints the resulting
* child process output is written to System.err. The valid levels are those defined
* in the ZUtil.LOG_* constants.</dd>
* </dl>
* <p>
* Features illustrated:
* <ul>
* <li>Specify an existing RECFM=F existing dataset as input (SORTIN) to DFSORT
* <li>Sort the records in Ascending order
* <li>Read the DFSORT (SORTOUT) results and process in Java
* </ul>
*/
public class DfSortFixedDatasetToJava {
public static void main(String[] args) throws Exception {
DfSortArguments dfsortArgs = new DfSortArguments(args);
if ((dfsortArgs.getSortinDataset() == null)) {
System.err.println("Usage: " + DfSortFixedDatasetToJava.class.getName() + " sortin=<dsn> [encoding=<codepage>] [shareas=<yes|NO>]");
System.err.println("Where:");
System.err.println("\tsortin is a RECFM=F dataset");
System.err.println("\tencoding is the source character set. If not supplied, raw bytes are processed.");
System.err.println("\tshareas = yes: DFSORT executes in the same address space as the JVM");
System.exit(4);
}
DsInfo inDs = dfsortArgs.getSortinDataset();
if (!inDs.isFixedRecfm()) {
System.err.println("Dataset " + inDs.getFullyQualifiedDsn() + " is not RECFM=F");
System.exit(8);
}
doSort(dfsortArgs);
}
private static void doSort(DfSortArguments dfsortArgs) throws Exception {
DsInfo inDs = dfsortArgs.getSortinDataset();
DfSort dfSort = new DfSort();
if (dfsortArgs.getLogLevel() != -1) {
dfSort.setLoggingLevel(dfsortArgs.getLogLevel());
}
//Direct DFSORT to get its input (SORTIN) from the supplied dataset.
dfSort.addAllocation("alloc fi(sortin) da("+inDs.getFullyQualifiedDsn()+") reuse shr msg(2)");
//Direct DFSORT to write output the the output named pipe.
dfSort.setOutputStreamRecLen(inDs.getLrecl());
//For this example, we sort the entire record (starting in column 1 for
//a length of lrecl. The data is treated as character data (CH) and the
//results are in ascending order (A)
dfSort.addControlStatement("SORT FIELDS=(1,"+inDs.getLrecl()+",CH,A)");
//Specify whether the DFSORT child process should be run in a separate address space.
//This allows multiple DFSORT processes to run simultaneously as each instance of
//the DFSORT DDs (SORTIN, SORTOUT, etc...) will be in their own address space.
dfSort.setSameAddressSpace(dfsortArgs.isSameAddressSpace());
//Kick off the sort.
long startTime = System.currentTimeMillis();
dfSort.execute();
//Once the child starts, open a BufferedInputStream on the child process' stdout
//and read the sort result.
BufferedInputStream bis = new BufferedInputStream(dfSort.getChildStdoutStream());
byte[] bytes = new byte[inDs.getLrecl()];
int recordCount = 0;
while (readRecord(bis,bytes)) {
//Process data
if (dfsortArgs.getEncoding() != null) {
String line = new String(bytes,dfsortArgs.getEncoding());
//Process encoded string...
} else {
//Process raw bytes...
}
recordCount++;
}
bis.close();
//Wait for dfSort to finish and check the result
int rc =0;
try {
rc = dfSort.getReturnCode();
} catch (RcException rce) {
System.out.println("Caught RcException: " + rce.getMessage());
rc = -1;
}
long runtime = System.currentTimeMillis() - startTime;
if (rc != 0 || dfsortArgs.getLogLevel() >= 0) {
List stderrLines = dfSort.getStderrLines();
for (Iterator i=stderrLines.iterator(); i.hasNext(); ) {
System.err.println(i.next());
}
}
System.out.println("RC=" + rc + " TIME=" + runtime + " RECORD COUNT=" + recordCount + " "
+ DfSortFixedDatasetToJava.class.getName());
}
/*
* Read exactly bytesToRead from the underlying stream (this call may block). Throw
* an IOException if EOF is encountered before all of the bytes are read.
*/
private static boolean readRecord(InputStream is, byte[] bytes) throws IOException {
int offset = 0;
int bytesToRead = bytes.length;
int c = is.read();
if (c == -1) {
return false;
} else {
bytes[offset++] = (byte) c;
--bytesToRead;
}
while (bytesToRead > 0) {
int bytesRead = is.read(bytes, offset, bytesToRead);
if (bytesRead == -1) {
throw new IOException("EOF encountered before all record bytes read");
}
bytesToRead -= bytesRead;
offset += bytesRead;
}
return true;
}
}
-
- Global moderator
- Posts: 3805
- Joined: Tue Jan 25, 2011 12:02 am
- Skillset: Easytrieve Plus, Cobol, Utilities, that sort of stuff
- Referer: Google
Re: DfSort multiple sortout file in java/jzos
Well, there were two things I was thinking of: secondly, within your program whilst processing the SORTOUT you can just write whatever data you like to as many files as you like (that is the "ordinary" way to do it in COBOL); firstly, to see if Java can use DFSPARM, where you would be able to code the OUTFILs exactly as you mentioned.
-
- Similar Topics
- Replies
- Views
- Last post
-
- 8
- 5018
-
by enrico-sorichetti
View the latest post
Fri Mar 12, 2021 4:09 pm
-
- 2
- 3995
-
by zbius
View the latest post
Wed Nov 06, 2024 2:16 pm
-
-
Create multiple records based on one record within a file.
by chillmo » Thu Aug 11, 2022 3:54 am » in Syncsort/Synctool - 5
- 7680
-
by sergeyken
View the latest post
Fri Aug 12, 2022 2:23 am
-
-
- 1
- 1330
-
by jcdm
View the latest post
Mon Oct 24, 2022 6:10 pm
-
-
Doubt about run Java into IMS and scheduling steps
by jcdm » Wed Nov 22, 2023 6:32 pm » in IMS DB/DC - 1
- 3578
-
by sergeyken
View the latest post
Wed Nov 22, 2023 8:24 pm
-