Coder Social home page Coder Social logo

Comments (3)

irisbaron avatar irisbaron commented on July 21, 2024

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());
		}
	}
}

from java-samples.

oli-ver avatar oli-ver commented on July 21, 2024

@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.

from java-samples.

Rohitallawadhi8 avatar Rohitallawadhi8 commented on July 21, 2024

which dependency we have to add for Dfsort

from java-samples.

Related Issues (6)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.