Previous Topic Next topic Print topic


Multiple CICS Program Calls with Channels and Containers

Shows the contents of a sample program that executes multiple CICS program calls using Channel and extended LUW.
File SampleCChannelWithELUW.java:
import java.io.UnsupportedEncodingException;

import com.microfocus.cics.client.AbendException;
import com.microfocus.cics.client.CCLCallType;
import com.microfocus.cics.client.CCLChannel;
import com.microfocus.cics.client.CCLContainer;
import com.microfocus.cics.client.CCLExtendMode;
import com.microfocus.cics.client.CCLParams;
import com.microfocus.cics.client.CCLVersion;
import com.microfocus.cics.client.CICSException;
import com.microfocus.cics.client.ConnectionType;
import com.microfocus.cics.client.ContainerData;
import com.microfocus.cics.client.ECIBINPConnection;
import com.microfocus.cics.client.ECIBINPRequest;
import com.microfocus.cics.client.ECIConnection;
import com.microfocus.cics.client.ECIRequest;
import com.microfocus.cics.client.ECIResponse;
import com.microfocus.cics.client.MalformedResponseException;
import com.microfocus.cics.client.CommAreaSizeException;
import java.util.List;


public class SampleChannelWithELUW {
	
	public static void main(String[] args) throws UnsupportedEncodingException, CICSException, AbendException, MalformedResponseException, CommAreaSizeException {
		SampleChannelWithELUW sc = new SampleChannelWithELUW();
		sc.containerTest1();
	}
	
	public void containerTest1() throws CICSException, UnsupportedEncodingException, AbendException, MalformedResponseException, CommAreaSizeException {
		ECIConnection aConn = null;
		ECIRequest aReq = null;
		ECIResponse aResp = null;
		CCLChannel ca = null;
		CCLParams theParams = null;
		try {
			aConn = new ECIBINPConnection()
					.setConnectionType(ConnectionType.LUW)
					.setHost("localhost").setPort(9003)
					.setTrace(true);
			aConn.open();
			aReq = new ECIBINPRequest(aConn);

			// set parameters
			ca = new CCLChannel("Bonjour le monde");
			CCLContainer aContainer = new CCLContainer("Container1");
			ContainerData data = new ContainerData();
			data.setContainerData("Hello1".getBytes());	
			aContainer.setContainerData(data);
			ca.addContainer(aContainer);
			
			CCLContainer aContainer2 = new CCLContainer("Container2");
			ContainerData data2 = new ContainerData();
			data2.setContainerData("Hello2".getBytes());	
			aContainer2.setContainerData(data2);
			ca.addContainer(aContainer2);
			
			theParams = new CCLParams();
			theParams.setVersion(CCLVersion.CCL_VERSION_2);
			theParams.setCallType(CCLCallType.CCL_SYNC);
			theParams.setProgramName("OKTEST");
			theParams.setUserId("SYSAD");
			theParams.setPassword("SYSAD");
			theParams.setChannel(ca);
			theParams.setUseChannel(true);
			theParams.setExtendMode(CCLExtendMode.CCL_EXTENDED);
			
			aReq.setRequestParameter(theParams);
			aResp = aReq.send();
			handleResponse(aResp);

			// Set data for second call
			CCLChannel ca2 = new CCLChannel("Bonjour le monde2");
			CCLContainer aContainer3 = new CCLContainer("Container3");
			ContainerData data3 = new ContainerData();
			data3.setContainerData("Hello3".getBytes());	
			aContainer3.setContainerData(data3);
			ca2.addContainer(aContainer3);
			
			CCLContainer aContainer4 = new CCLContainer("Container4");
			ContainerData data4 = new ContainerData();
			data4.setContainerData("Hello4".getBytes());	
			aContainer4.setContainerData(data4);
			ca2.addContainer(aContainer4);

			theParams.setVersion(CCLVersion.CCL_VERSION_2);
			theParams.setCallType(CCLCallType.CCL_SYNC);
			theParams.setProgramName("OKTEST");
			theParams.setUserId("SYSAD");
			theParams.setPassword("SYSAD");
			theParams.setChannel(ca);
			theParams.setUseChannel(true);
			theParams.setExtendMode(CCLExtendMode.CCL_EXTENDED);

			aReq.setRequestParameter(theParams);
			aResp = aReq.send();
			handleResponse(aResp);

			// mark end of ELUW
			CCLChannel ca3 = new CCLChannel("Au Revoir");
			CCLContainer aContainer5 = new CCLContainer("Container5");
			ContainerData data5 = new ContainerData();
			data5.setContainerData("Bye1".getBytes());	
			aContainer5.setContainerData(data5);
			ca3.addContainer(aContainer5);
			
			CCLContainer aContainer6 = new CCLContainer("Container6");
			ContainerData data6 = new ContainerData();
			data6.setContainerData("Bye2".getBytes());	
			aContainer6.setContainerData(data6);
			ca3.addContainer(aContainer6);

			theParams.setVersion(CCLVersion.CCL_VERSION_2);
			theParams.setCallType(CCLCallType.CCL_SYNC);
			theParams.setProgramName("OKTEST");
			theParams.setUserId("SYSAD");
			theParams.setPassword("SYSAD");
			theParams.setChannel(ca);
			theParams.setUseChannel(true);
			theParams.setExtendMode(CCLExtendMode.CCL_NO_EXTEND);

			aReq.setRequestParameter(theParams);
			aResp = aReq.send();
			handleResponse(aResp);

			// commit
			theParams.setVersion(CCLVersion.CCL_VERSION_2);
			theParams.setCallType(CCLCallType.CCL_SYNC);
			theParams.setProgramName("OKTEST");
			theParams.setUserId("SYSAD");
			theParams.setPassword("SYSAD");
			theParams.setExtendMode(CCLExtendMode.CCL_COMMIT);
			aReq.setRequestParameter(theParams);
			aResp = aReq.send();
			handleResponse(aResp);			
		} finally {
			ca = null;
			theParams = null;
			if (aReq != null)
				aReq.close();
			if (aResp != null)
				aResp.close();
			if (aConn != null) {
				try {
					aConn.close();
				} catch (CICSException e) {
					e.printStackTrace();
				}
			}	
		}
	}

	private void handleResponse(ECIResponse aResp) throws UnsupportedEncodingException {
		List<CCLContainer> containers = aResp.getChannel().getContainers();
			for(CCLContainer c: containers) {
				ContainerData cd = c.getContainerData();
				if(cd != null) {
					byte[] cData = cd.getContainerData();
					System.out.println(new String(cData));
				}
			}
	}


}
Previous Topic Next topic Print topic