Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JCL DD statement with multiple files #2

Closed
oli-ver opened this issue Oct 24, 2018 · 3 comments
Closed

JCL DD statement with multiple files #2

oli-ver opened this issue Oct 24, 2018 · 3 comments

Comments

@oli-ver
Copy link

oli-ver commented Oct 24, 2018

In JCL I can do something like this:

//SYS022  DD DSN=MY.FILE.NUMBER1,DISP=SHR
//        DD DSN=MY.FILE.NUMBER2,DISP=SHR

How do I allocate this for use in DFSORT in Java?
The examples always show that you fetch the "real" file name and assign it, but this does not work for a multi file DD statement.

@irisbaron
Copy link

irisbaron commented Nov 11, 2018

Hi @oli-ver , here is the response from the JZOS developers:
The JZOS DFSORT addAllocation API allows only one dataset at a time.
However, here is a workaround for the current jzos implementation. Hope this helps.

  1. First, sort each input dataset into an individual output dataset (because JZOS addAllocation with the SORT control statement takes only an input dataset with the ddname SORTIN)
  2. Then merge the sorted datasets into a single output (the MERGE allows multiple allocations with ddname SORTINnn where nn can be 00 to 99. For additional information, refer to https://www.ibm.com/support/knowledgecenter/en/SSLTBW_2.3.0/com.ibm.zos.v2r3.icea100/inpds.htm )

Below is the code snippet.

public static void main(String[] args) throws Exception {
	sortMergeDatasets();
}

private static void sortMergeDatasets() throws Exception {
	sort("TESTDATA.INPUT1", "TESTDATA.OUTPUT1");
	sort("TESTDATA.INPUT2", "TESTDATA.OUTPUT2");
	merge("TESTDTA.OUTPUT1", "TESTDATA.OUTPUT2", "TESTDATA.MERGE");
}

private static void sort(String inDs, String outDs) throws Exception {
	int lrecl = 20;
	
	DfSort dfSort = new DfSort();	
	dfSort.addAllocation("alloc fi(SORTIN) da(" + inDs + ") reuse shr msg(2)");
	dfSort.addAllocation("alloc fi(SORTOUT) da(" + outDs + ") reuse shr msg(2)");
	dfSort.addControlStatement("SORT FIELDS=(1," + lrecl + ",CH,A)");
	
	long startTime = System.currentTimeMillis();
	dfSort.execute();
	int rc =0;
	try {
		rc = dfSort.getReturnCode();
	} catch (RcException rce) {
		System.out.println("Caught RcException: " + rce.getMessage());
		rc = -1;
	}
	if (rc != 0) {
		List stderrLines = dfSort.getStderrLines();
		for (Iterator i=stderrLines.iterator(); i.hasNext(); ) {
			System.err.println(i.next());
		}
	}

}
private static void merge(String inDs1, String inDs2, String outDs) throws Exception {
	int lrecl = 20;
	
	DfSort dfSort = new DfSort();	
	dfSort.addAllocation("alloc fi(SORTIN01) da(" + inDs1 + ") reuse shr msg(2)");
	dfSort.addAllocation("alloc fi(SORTIN02) da(" + inDs2 + ") reuse shr msg(2)");
	dfSort.addAllocation("alloc fi(SORTOUT) da(" + outDs + ") reuse shr msg(2)");
	dfSort.addControlStatement("MERGE FIELDS=(1," + lrecl + ",CH,A)");
	
	long startTime = System.currentTimeMillis();
	dfSort.execute();
			
	int rc =0;
	try {
	    rc = dfSort.getReturnCode();
	} catch (RcException rce) {
		System.out.println("Caught RcException: " + rce.getMessage());
		rc = -1;
	}
	if (rc != 0) {
		List stderrLines = dfSort.getStderrLines();
		for (Iterator i=stderrLines.iterator(); i.hasNext(); ) {
			System.err.println(i.next());
		}
	}
}

@oli-ver
Copy link
Author

oli-ver commented Oct 12, 2019

@irisbaron Thank you very much for the detailed response. I obviously forgot to update the issue, sorry for that.

This is something worth mentioning in the documentation for Java Batch on z/OS, i. e. here:
https://www.ibm.com/support/knowledgecenter/en/SSYKE2_8.0.0/com.ibm.java.zsecurity.80.doc/zsecurity-component/jzos.html
ftp://public.dhe.ibm.com//software/Java/Java80/JZOS/jzos_users_guide_v8.pdf
Perhaps you could add a warning somewhere in chapter 4, subchapter "MVS Data Set I/O"?

In my opinion it's something you would nevery expect, because it's used in JCL all the time when not starting Java applications.

I ended up doing just the same with DFSort but in a step before the job. merging the file before assignment to the Java application. To use the explained workaround would lead to the necessity to change the code whenever one decides to add another file to the mix.

@oli-ver oli-ver closed this as completed Oct 12, 2019
@Rohitallawadhi8
Copy link

which dependency we have to add for Dfsort

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants