Conversational transactions

The IMS Java™ dependent region resource adapter supports access to IMS conversational transactions.

Conversational transactions

A conversational transaction does not process the entire transaction at the same time. A conversational program divides processing into a connected series of terminal-to-program-to-terminal interactions. Use conversational processing when one transaction contains several parts. In contrast, a nonconversational program receives a message from a terminal, processes the request, and sends a message back to the terminal.

A conversational program receives a message from a terminal and replies to the terminal, but it saves the data from the transaction in a scratchpad area (SPA). When the user at the terminal enters more data, the program has the data it saved from the last message in the SPA, so it can continue processing the request without the user at the terminal having to enter the data again.

Conversational transaction sample

The following code example shows how to write a JMP application to process a conversational transaction.

package mytest.jdbo;

import com.ibm.ims.dli.DLIException;
import com.ibm.ims.dli.tm.*;

public class MyConversationalSample {

  public static void main(String[] args) {
    Transaction tran = null;
    try {
      Application app 
         = ApplicationFactory.createApplication();
      IOMessage spaMessage 
         = app.getIOMessage("class://mytest.jdbo.SPAMessage");
      IOMessage inputMessage 
         = app.getIOMessage("class://mytest.jdbo.InMessage");
      IOMessage outputMessage 
         = app.getIOMessage("class://mytest.jdbo.OutMessage");
      MessageQueue msgQueue = app.getMessageQueue();
      tran = app.getTransaction();

      // Read the SPA message
      while (msgQueue.getUnique(spaMessage)) {
        // before reading the application messages.
        if (msgQueue.getNext(inputMessage)) {
          String inField 
            = inputMessage.getString("Message").trim();
          try {
            int sum = (new Integer(inField)).intValue();
            spaMessage.setString("Message", "" + sum);
            msgQueue.insert(spaMessage, 
              MessageQueue.DEFAULT_DESTINATION);
            outputMessage.setString("Message", 
              "The initial value is: " + sum);
            msgQueue.insert(outputMessage, 
              MessageQueue.DEFAULT_DESTINATION);
          } catch (NumberFormatException e) {
            if (inField.equalsIgnoreCase("stop")) {
              // End the conversation
              spaMessage.setString("Message", 
                "Exit requested, so I am exiting");
spaMessage.setTransactionName(IOMessage.END_CONVERSATION_BLANKS);
msgQueue.insert(spaMessage, MessageQueue.DEFAULT_DESTINATION);
            }
          }
        }
      }
      tran.commit();
    } catch (DLIException e) {
      e.printStackTrace();
      try {
        // Roll back the transaction
        if (tran != null) {
          tran.rollback();
        }
      } catch (DLIException e1) {
        e1.printStackTrace();
      }
    }
   }
}

Conversational transaction sequence of events

When the message is a conversational transaction, the following sequence of events occurs:

  1. IMS removes the transaction code and places it at the beginning of a message segment. The message segment is equal in length to the SPA that was defined for this transaction during system definition. The transaction code is the first segment of the input message that is made available to the program. The second through the nth segments from the terminal, minus the transaction code, become the remainder of the message that is presented to the application program.
  2. After the conversational program prepares its reply, it inserts the SPA to IMS. The program then inserts the actual text of the reply as segments of an output message.
  3. IMS saves the SPA and routes the message to the input LTERM (logical terminal).
  4. If the SPA insert specifies that another program is to continue the same conversation, the total reply (including the SPA) is retained on the message queue as input to the next program. This program then receives the message in a similar form.
  5. A conversational program must be scheduled for each input exchange. The other processing continues while the operator at the input terminal examines the reply and prepares new input messages.
  6. To terminate a conversation, the program places blanks in the transaction code field of the SPA and inserts the SPA to IMS. To terminate a conversation when using the IMS Java dependent region resource adapter, set the SPA transaction code to the constant IOMessage.END_CONVERSATION_BLANKS.
  7. The conversation can also be terminated if the transaction code in the SPA is replaced by any transaction code from a nonconversational program, and the SPA is inserted to IMS. After the next terminal input, IMS routes that message to the queue of the other program in the normal way.