Defining the input and output message classes

Before your JMP application can access the message queue, you must define input and output message classes by subclassing the com.ibm.ims.application.IMSFieldMessage class.

Recommendation: Use the IMS Enterprise Suite Explorer for Development to generate the necessary metadata class files from COBOL copybooks or PL/I resources when this support is available.

The IMS Java™ dependent region resource adapter provides the capability to process IMSFieldMessage objects.

Subclass IMSFieldMessage: input message sample code

This example code subclasses the com.ibm.ims.application.IMSFieldMessage class to make the fields in the message available to the program and creates an array of com.ibm.ims.base.DLITypeInfo objects for the fields in the message. For the DLITypeInfo class, the code identifies first the field name, then the data type, the position, and finally the length of the individual fields within the array. This allows the application to use the access functions within the IMSFieldMessage class hierarchy to automatically convert the data from its format in the message to a Java type that the application can process. In addition to the message-specific fields that it defines, the IMSFieldMessage class provides access functions that allow it to determine the transaction code and the length of the message.

This class defines an input message that accepts a 2-byte type code of a car model to query a car dealership database for available car models.

package dealership.application;
import com.ibm.ims.db.*;
import com.ibm.ims.base.*;
import com.ibm.ims.application.*;

/* Subclasses IMSFieldMessage to define application's input messages */
public class InputMessage extends IMSFieldMessage {

    /* Creates array of DLITypeInfo objects for the fields in message */
    final static DLITypeInfo[]fieldInfo={
        new DLITypeInfo("ModelTypeCode", DLITypeInfo.CHAR, 1, 2)
    };
                                               
    public InputMessage() {
        super(fieldInfo, 2, false);
    }
}

Subclass IMSFieldMessage: output message sample code

The following code example shows how to subclass the com.ibm.ims.application.IMSFieldMessage class to define an output message that displays the available car models from a type code query.

This sample code creates an array of com.ibm.ims.base.DLITypeInfo objects and then passes that array, the byte array length, and the Boolean value false, which indicates a non-SPA message, to the IMSFieldMessage constructor. For each DLITypeInfo object, you must first identify the field data type, then the field name, the field offset in the byte array, and finally the length of the byte array.

package dealership.application;
import com.ibm.ims.db.*;
import com.ibm.ims.base.*;
import com.ibm.ims.application.*;

/*Subclasses IMSFieldMessage to define application's output messages */  
public class ModelOutput extends IMSFieldMessage {                
    
s        /* Creates array of DLITypeInfo objects for the fields in message */
    final static DLITypeInfo[] fieldInfo={               
        new DLITypeInfo("Type",         DLITypeInfo.CHAR,    1,  2),
        new DLITypeInfo("Make",         DLITypeInfo.CHAR,    3, 10),
        new DLITypeInfo("Model",        DLITypeInfo.CHAR,   13, 10),
        new DLITypeInfo("Year",         DLITypeInfo.DOUBLE, 23,  4),
        new DLITypeInfo("CityMiles",    DLITypeInfo.CHAR,   27,  4),
        new DLITypeInfo("HighwayMiles", DLITypeInfo.CHAR,   31,  4),
        new DLITypeInfo("Horsepower",   DLITypeInfo.CHAR,   35,  4)
    };

    public ModelOutput() {
        super(fieldInfo, 38,false);
    }

}