CICS Program Call with Commarea

Shows the contents of a sample program that executes a CICS program call using a Commarea and non-extended LUW.
File: SampleCommArea.java
import java.io.UnsupportedEncodingException;

import com.microfocus.cics.client.AbendException;
import com.microfocus.cics.client.CCLCallType;
import com.microfocus.cics.client.CommArea;
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 com.microfocus.cics.client.ExciRespException;
import com.microfocus.cics.client.AbendCodeType;
import java.util.List;


public class SampleCommArea {
    
    public static void main(String[] args) throws UnsupportedEncodingException, CICSException, AbendException, MalformedResponseException, CommAreaSizeException {
        SampleCommArea sc = new SampleCommArea();
        sc.commareaTest1();
    }
    
    public void commareaTest1() throws CICSException, UnsupportedEncodingException, AbendException, MalformedResponseException, CommAreaSizeException {
                ECIConnection aConn = null;
        ECIRequest aReq = null;
        ECIResponse aResp = null;
        CommArea 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 CommArea(" COMMIT  _JAVA _01_LUW ");
            ca = new CommArea("Bonjour le monde");
            theParams = new CCLParams();
            theParams.setVersion(CCLVersion.CCL_VERSION_2);
            theParams.setCallType(CCLCallType.CCL_SYNC);
            theParams.setProgramName("OKTEST");
            theParams.setUserId("SYSAD");
            theParams.setPassword("SYSAD");
            theParams.setCommArea(ca);
            theParams.setExtendMode(CCLExtendMode.CCL_NO_EXTEND);
            aReq.setRequestParameter(theParams);
            aResp = aReq.send();
            handleResponse(aResp, CommArea.ISO_8859_1);
        } catch (CICSException e) {
            System.out.println(e.getMessage());
        } catch (AbendException ae) {
            String abCode = ae.getAbendCode();
            AbendCodeType abendCodeType = ae.getAbendCodeType();
            System.out.println("Abend Code = " + abCode);
            System.out.println("Abend Code Type= " + abendCodeType);
        } catch (MalformedResponseException bre) {
            bre.printStackTrace();
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        } catch (CommAreaSizeException ce) {
            ce.printStackTrace();
        } catch(ExciRespException e) {
                e.printStackTrace();
                System.out.println("ExciResp1 = " + e.getExciResp1() + " and ExciResp2 = " + e.getExciResp2() + " and rc = " + e.getRcMsg());
        } 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, String encoding)
            throws UnsupportedEncodingException {
        System.out.println("Response1 = " + aResp.getExciResp1());
        System.out.println("Response2 = " + aResp.getExciResp2());
        CommArea ca = aResp.getCommArea();
        if (ca != null) {
            byte[] caBytes = ca.getCommArea();
            if (caBytes != null) {
                String asciiCommArea = new String(ca.getCommArea(), encoding);
                System.out.println("CommArea = " + asciiCommArea);
            } else {
                System.out.println("CommArea = null");
            }
        }
        System.out.println("Abend code = " + aResp.getAbendCode());
        System.out.println("Abend code type = " + aResp.getAbendCodeType());
    }
    
}