Using JCICS

You use the classes from the JCICS library like normal Java™ classes. Your applications declare a reference of the required type and a new instance of a class is created using the new operator.

About this task

You name CICS® resources using the setName method to supply the name of the underlying CICS resource. After you create the resource, you can manipulate objects using standard Java constructs. You can call methods of the declared objects in the usual way. Full details of the methods supported for each class are available in the supplied Javadoc.

Do not use finalizers in CICS Java programs. For an explanation of why finalizers are not recommended, see IBM SDK for z/OS, Java Technology Edition, Version 7, Troubleshooting and support section.

Do not end CICS Java programs by issuing a System.exit() call. When Java applications run in CICS, the public static void main() method is called through the use of another Java program called the Java wrapper. When you use the wrapper CICS initializes the environment for Java applications and, more importantly, cleans up any processes that are used during the life of the application. Terminating the JVM, even with a clean return code of 0, prevents this cleanup process from running, and might lead to data inconsistency. Using System.exit() when the application is running in a JVM server terminates the JVM server and quiesces CICS immediately.

Procedure

  1. Write the main method.
    CICS attempts to pass control to the method with a signature of main(CommAreaHolder) in the class specified by the JVMCLASS attribute of the PROGRAM resource. If this method is not found, CICS tries to invoke method main(String[]).
  2. To create an object using JCICS, follow these steps:
    1. Declare a reference:
         TSQ tsq;
       
    2. Use the new operator to create an object:
         tsq = new TSQ()
       
    3. Use the setName method to give the object a name:
         tsq.setName("JCICSTSQ");
       
  3. Use the object to interact with CICS.

Example

This example shows how to create a TSQ object, invoke the delete method on the temporary storage queue object you have just created, and catch the thrown exception if the queue is empty.
// Define a package name for the program
package unit_test;

// Import the JCICS package
import com.ibm.cics.server.*;

// Declare a class for a CICS application
public class JCICSTSQ 
{

    // The main method is called when the application runs
    public static void main(CommAreaHolder cah) 
    {

         try 
         {
             // Create and name a Temporary Storage queue object
             TSQ tsq = new TSQ();
             tsq.setName("JCICSTSQ");

             // Delete the queue if it exists
             try 
             {
                   tsq.delete();
             } 
             catch(InvalidQueueIdException e) 
             {
                  // Absorb QIDERR
                  System.out.println("QIDERR ignored!");
             }

             // Write an item to the queue
             String transaction = Task.getTask().getTransactionName();
             String message = "Transaction name is - " + transaction;
             tsq.writeItem(message.getBytes());

         } 
         catch(Throwable t) 
         {
             System.out.println("Unexpected Throwable: " + t.toString());
         }

         // Return from the application
         return;
    }
}