Exercise 1.3: Creating the Java method

Before you begin, you must complete Exercise 1.2: Setting up the Web project and Java Interface and Implementations .

Exercise 1.2 steps you through the creation of a Java method, getCustomerInfo. In this exercise you will

Creating a Java method

You will now create a Java method that will use the COBOL importer to map the data types between the COBOL source and the data in your Java method.

  1. In the Java Method page, click Add.
  2. In the Java method name field, type getCustomerInfo for the name of the operation. Click Next.

Creating the Input parameter Data Mapping

In this step, you will import the taderc25.cbl (COBOL) file that is needed to create your application. The taderc25.ccp file is located in <RSDP_installdir>\rad\eclipse\plugins\com.ibm.j2c.cheatsheet.content_6.0.0\Samples\CICS\taderc25, where <RSDP_installdir> is the directory where this product is installed. The COBOL file contains the program that runs on the CICS server. It has the definition of the structure to be passed to the CICS server via the communications area (COMMAREA). This structure represents the customer records being returned from the CICS application. Before you can work with a file, you must import it from the file system into the workbench.

  1. In the Specify the input/output type field of the Java Method page, click New.
  2. In the Data Import page, ensure Choose mapping field is COBOL_TO_JAVA.
  3. Click Browse beside the Cobol file name field.
  4. Locate the taderc25.cbl file in the file system, and click Open.
  5. Click Next.
  6. In the COBOL Importer page, select a communication data structure
  7. In the Saving properties page

Creating the multiple possible outputs for the output parameter

  1. In the Specify the input/output type in the Java Method page, click New beside the Output type area.
  2. In the Data Import page, ensure that the Choose mapping field is COBOL_MPO_TO_JAVA.
  3. Click New beside the multiple possible output area.
  4. Click Browse beside the Cobol file name field, and locate the file location of the taderc25.cbl file. Click Open.
  5. Click Next.
  6. In the COBOL Importer page, select a communication data structure.
  7. In the Specify data import configuration properites page page, you will see the three data types listed.
  8. Click Next.

Specifying the saving properties

  1. In the Saving Properties page, you will see default values set for each of the customer type record.
  2. In the Specify the Saving properties page, under the Data Binding section
  3. In the COBOL To Java Save Properties For "PREFCUST"
  4. In the COBOL To Java Save Properties For "REGCUST"
  5. In the COBOL To Java Save Properties For "BADCUST"
  6. Click Finish.You will see that OutputComm contains PrefCust, RegCust and BadCust in the output type.
  7. On the Java Method page, click Finish to complete the operation.
  8. In the Java methods page, Click Finish.

Adding the recognition pattern tag to the generate Java output data mapping file

Since the output coming back can be any one of the data types, the only way to match it is to have some pattern predefined in the data stream. The match method is to check the recognition pattern.

Add doclet tag

  1. To add the recognition pattern for PrefCust:
    1. Open the PrefCust.java file in a java editor.
    2. Navigate to the getPcustcode() method
    3. In the method comment area , add the tag @type-descriptor.recognition-desc pattern="PREC" or you can use the content assist by pressing CTRL-space and navigate down the list to find the tag and then enter "PREC" as the pattern.
    4. Save the changes and the code PrefCust.java will be regenerated.
    5. Navigate to the match method to make sure the change is there.
    6. /**
      	 * @generated
      	 
      	 */
      	public boolean match(Object obj) {
      		if (obj == null)
      			return (false);
      		if (obj.getClass().isArray()) {
      			byte[] currBytes = buffer_;
      			try {
      				byte[] objByteArray = (byte[]) obj;
      				buffer_ = objByteArray;
      				if (!("PREC".equals(getPcustcode().toString())))
      					return (false);
      			} catch (ClassCastException exc) {
      				return (false);
      			} finally {
      				buffer_ = currBytes;
      			}
      		} else
      			return (false);
      		return (true);
      	}
      
  2. To add the recognition pattern for RegCust:
    1. Open the RegCust.java file in the Java editor.
    2. Navigate to the getRcustcode() method
    3. In the method comment area , add the tag @type-descriptor.recognition-desc pattern="REGC" or you can use the content assist by pressing CTRL-space and navigate down the list to find the tag and then enter "REGC" as the pattern.
    4. Save the changes and the code RegCust.java will be regenerated.
    5. Navigate to the match method to make sure the change is there.
    6. /**
      	 * @generated
      	 
      	 */
      	public boolean match(Object obj) {
      		if (obj == null)
      			return (false);
      		if (obj.getClass().isArray()) {
      			byte[] currBytes = buffer_;
      			try {
      				byte[] objByteArray = (byte[]) obj;
      				buffer_ = objByteArray;
      				if (!("REGC".equals(getRcustcode().toString())))
      					return (false);
      			} catch (ClassCastException exc) {
      				return (false);
      			} finally {
      				buffer_ = currBytes;
      			}
      		} else
      			return (false);
      		return (true);
      	}
      
  3. To add the recognition pattern for BadCust
    1. Open the BadCust.java file in the Java editor.
    2. Navigate to the getBcustcode() method
    3. In the method comment area , add the tag @type-descriptor.recognition-desc pattern="BADC" or you can use the content assist by pressing CTRL-space and navigate down the list to find the tag and then enter "BADC" as the pattern.
    4. Save the changes and the code BadCust.java will be regenerated.
    5. Navigate to the match method to make sure the change is there.
    6. public boolean match(Object obj) {
      		if (obj == null)
      			return (false);
      		if (obj.getClass().isArray()) {
      			byte[] currBytes = buffer_;
      			try {
      				byte[] objByteArray = (byte[]) obj;
      				buffer_ = objByteArray;
      				if (!("BADC".equals(getBcustcode().toString())))
      					return (false);
      			} catch (ClassCastException exc) {
      				return (false);
      			} finally {
      				buffer_ = currBytes;
      			}
      		} else
      			return (false);
      		return (true);
      	}
      

Now you are ready to begin Exercise 1.4: Deploying the application.

Terms of use | Feedback

(C) Copyright IBM Corporation 2000, 2005. All Rights Reserved.