Previous Topic Next topic Print topic


CICS Program Call with Channels and Containers

File SampleChannel.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.CommAreaSizeException;
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 java.util.List;


public class SampleChannel {
	
	public static void main(String[] args) throws UnsupportedEncodingException, CICSException, AbendException, MalformedResponseException, CommAreaSizeException {
		SampleChannel sc = new SampleChannel();
		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.NO_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_NO_EXTEND);
			
			aReq.setRequestParameter(theParams);
			aResp = aReq.send();
			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));
				}
			}
		        	
		} 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();
				}
			}	
		}
	}

}
Previous Topic Next topic Print topic