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
- Create a Java method
- Create the input data mapping between COBOL and Java
- Create the output data mapping between COBOL and Java
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.
- In the Java Method page, click Add.
- 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.
- In the Specify the input/output type field of the Java Method page, click New.
- In the Data Import page, ensure Choose mapping field is COBOL_TO_JAVA.
- Click Browse beside the Cobol file name field.
- Locate the taderc25.cbl file in the file system, and click Open.
- Click Next.
- In the COBOL Importer page, select a communication data structure
- Select Win32 for Platform Name.
- Select ISO-8859-1 for Code page
- Click Query.
- Select ICOMMAREA for Data structures. Click Next
- In the Saving properties page
- Select Default for Generation Style.
- Click Browse to choose the Web project Taderc25Sample
- In the Package Name field, enter sample.cics.data
- In the Class Name field, the default value is ICOMMAREA; replace it with InputComm.
Click Finish.
Creating the multiple possible outputs for the output parameter
- In the Specify the input/output type in the Java Method page, click New beside the Output type area.
- In the Data Import page, ensure that the Choose mapping field is COBOL_MPO_TO_JAVA.
-
Click New beside the multiple possible output area.
- Click Browse beside the Cobol file name field, and locate the file location of the taderc25.cbl file. Click Open.
- Click Next.
- In the COBOL Importer page, select a communication data structure.
- Select Win32 for Platform Name.
- Select ISO-8859-1 for Code page
- Click on the Query button to select Data structures
- Select PREFCUST, REGCUST and BADCUST for Data structures.
- Click Finish.
- In the Specify data import configuration properites page page, you will see the three data types listed.
- Click Next.
Specifying the saving properties
- In the Saving Properties page, you will see default values set for each of the customer type record.
- In the Specify the Saving properties page, under the Data Binding section
- Accept Java project Taderc25Sample.
- In the Package Name field, type sample.cics.data.
- In the Class Name field, type OutputComm.
- In the COBOL To Java Save Properties For "PREFCUST"
- Accept Project nameTaderc25Sample.
- In the Package Name field, type sample.cics.data.
- In the Class Name field, type PrefCust.
- In the COBOL To Java Save Properties For "REGCUST"
- Click Browse to choose the Web project Taderc25Sample.
- In the Package name field, type sample.cics.data.
- In the Class Name field, type RegCust.
- In the COBOL To Java Save Properties For "BADCUST"
- Click Browse to choose the Web project Taderc25Sample.
- In the Package name field, type sample.cics.data.
- In the Class Name field, type BadCust.
- Click Finish.You will see that OutputComm contains PrefCust, RegCust and BadCust in the output type.
- On the Java Method page, click Finish to complete the operation.
- In the Java methods page,
- Type the COBOL program id (TADERC25) in the functionName field.
- Enter 50 in the commareaLength field.
- Select the value SYNC_RECEIVE(1) in the interactionVerb field.
- Enter -1 in the replyLength field
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.
- To add the recognition pattern for PrefCust:
- Open the PrefCust.java file in a java editor.
- Navigate to the getPcustcode() method
- 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.
- Save the changes and the code PrefCust.java will be regenerated.
- Navigate to the match method to make sure the change is there.
/**
* @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);
}
- To add the recognition pattern for RegCust:
- Open the RegCust.java file in the Java editor.
- Navigate to the getRcustcode() method
- 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.
- Save the changes and the code RegCust.java will be regenerated.
- Navigate to the match method to make sure the change is there.
/**
* @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);
}
- To add the recognition pattern for BadCust
- Open the BadCust.java file in the Java editor.
- Navigate to the getBcustcode() method
- 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.
- Save the changes and the code BadCust.java will be regenerated.
- Navigate to the match method to make sure the change is there.
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.