import com.ibm.jzos.*;
import java.io.BufferedInputStream;
import java.util.*;
import com.syncsort.zos.SyncSort;
public class dfexec1
{
public static void main(String args) throws Exception {
sort("<INPUT DSNAME>");
}
private static void sort(String inDs) throws Exception {
int key = 20;
SyncSort syncsort = new SyncSort();
syncsort.addAllocation("alloc fi(SORTIN) da(" + inDs + ") reuse shr msg(2)");
syncsort.setOutputStreamRecLen(80);
syncsort.addControlStatement("SORT FIELDS=(1," + key + ",CH,A)");
long startTime = System.currentTimeMillis();
syncsort.execute();
BufferedInputStream bis = new BufferedInputStream(syncsort.getChildStdoutStream());
byte buffer = new byte 80 ;
int bytesRead = 0;
while ((bytesRead = bis.read(buffer)) != -1) {
System.out.println(new String(buffer, 0, bytesRead));
}
int rc =0;
try {
rc = syncsort.getReturnCode();
} catch (RcException rce) {
System.out.println("Caught RcException: " + rce.getMessage());
rc = -1;
}
if (rc != 0) {
List stderrLines = syncsort.getStderrLines();
for (Iterator i=stderrLines.iterator(); i.hasNext(); ) {
System.err.println(i.next());
}
}
}
}