Handling data type differences between Java and COBOL

You must make sure that the data types, and any calculations that are used with them, match the expected results of the COBOL application from which the rules were extracted.

When you extract rules from an existing COBOL application, you must consider which rule execution environment you are going to use.

If you use the COBOL rule subprogram generation option for rule execution, the rules are executed as generated COBOL code. In this case, the data types that are used in the execution are COBOL data types. These data types, and any calculations that are used with them, normally match the expected results of the COBOL application from which the rules were extracted.

When you use the zRule Execution Server for z/OS® execution environment, the COBOL data types are mapped to Java™ data types and the rules are executed internally within a Java run time. The COBOL management tool in Rule Designer provides the default mapping between the COBOL data types and the Java data types. In most cases, rule execution matches that of the COBOL application from which the rules were extracted, but to make sure, you can use the Decision Center simulation and testing capabilities to verify the expected rule execution characteristics. If required, you can then adjust the authored rule.

The following table shows an example of how data types can differ between Java and COBOL. It compares the Java String type and the COBOL alphanumeric type of PIC X(n).

Java String type COBOL PIC X(n)
The Java String type is a variable-length container for alphanumeric types. If a certain length is required, spaces are appended to the data placed in the String value.
When the COBOL alphanumeric type is mapped to the Java String type, you can choose how blank characters are trimmed in the Java String. You can select one of the following options:
  • Remove all blank characters.
  • Remove trailing blank characters only.
  • Do not remove blank characters.

At run time, when the Java String type is mapped back to the COBOL alphanumeric or alphabetic type, spaces are appended if the data in the Java String type is shorter than the COBOL type. If the data in the Java String exceeds the capacity of the COBOL type, a run time error is returned.

This COBOL type defines a field as a character array for string data of fixed-length ‘n’. You must set the value of ‘n’ to the maximum size of data that the field can contain. If you place a value smaller than ‘n’ into the field, the unused characters are populated with spaces. You cannot determine if the spaces are significant.

To avoid this potential issue, make sure that the underlying COBOL types have sufficient capacity to store the required information.

You can also find differing execution characteristics with certain specific numeric calculations:
  • In Java, you normally perform complex numeric calculations by using float or double types. In this case, the numeric calculation uses a fully floating point calculation.

  • In COBOL, numbers are often represented by 9(n)V9(m) packed decimal types. This type defines a decimal number with the n numeric characters for the integral part, and m numeric characters for the fractional part. If all the operands of a calculation are of this format, the calculations occur within the bounds of the highest precision available in the calculation.

    For example, if the largest number of decimal places within any data type is 3, all calculations occur with a fixed decimal length of 3, and any higher precision is truncated.

To illustrate this example, suppose that you have the following variables and values:
Price PIC 9(5) value 200
NumPayments PIC 9(3) value3
SalesTax  PIC 9(2)V(3) 0.196

The code might contain the following calculations showing the output of the calculations as full precision, full precision with the result rounded to two decimal places, and a fixed precision calculation:

Calculation Full precision Full precision (2 digits displayed) Fixed precision (2 digits)
Payment = Price / NumPayments 66.6666666r 66.67 66.67
Price * (1 + SalesTax) 79.73333333r 79.73 79.74

In this particular case, the results from the COBOL execution differ slightly from the Java execution of the calculation. However, if any value in the COBOL calculation is of floating point type (COMP-1 or COMP-2), or if any literal value is used, the calculation is carried out as a floating point calculation. This calculation gives similar results to the Java calculation, but some precision is still lost.