Example: Creating a macro method to check data types

A typical usage for a COBOL macro method is to check data types, such as whether an item is alphabetic, numeric, or a space.

About this task

Deprecated feature:

Deprecation icon The COBOL code generation feature is deprecated in V8.5. This feature will be removed in a future release of the product. Use the COBOL Generation Project Migration wizard to migrate your Rules for COBOL project to a zRule Execution Server for z/OS® compatible rule project. See Deprecated features for migration details.

In COBOL, you use the IS ALPHABETIC clause to test whether a data item is numeric. The predefined method Util.isAlphabetic performs this check. This method is verbalized as {0} is Alphabetic.

For example, in the following COBOL item definition, age is a numeric data item:

01 Customer.
     05 age        PIC 9(3).

To check whether or not the AGE item has been initialized, you can write the following rule:

if
    the age of 'the customer' is Numeric
then
    set the age of 'the customer' to 30;
Note:

You can also add customized Util methods to support other clauses such as IS NUMERIC and IS SPACE.

To use IS NUMERIC, you must first import the cobol_extension BOM into your rule project. To import the extension, right-click the bom folder and then click COBOL Management > COBOL Code Generation > Add COBOL Extension BOM.

The following procedure describes how to enable alphabetic checks during rule authoring. The principle is the same for enabling space or numeric checking.

Procedure

To add IS ALPHABETIC checking:

  1. In Rule Designer, in the Rule Explorer, open the BOM editor for the Util class.
  2. Click New to add a new BOM class member.
  3. On the New Member page, select the Method radio button.
  4. In the Name field, type isAlphabetic.
  5. For Type, select boolean.
  6. Click Add to add a parameter named text, of type java.lang.String.
  7. Click OK to close the Method Argument dialog.
  8. Click Finish.
  9. Double-click the method isAlphabetic and then select the Static check box for this method.
  10. In the Member Verbalization section, type the following navigation phrase in the Template field: {0} is Alphabetic.
  11. In the COBOL Method section of the BOM Editor, click Create a macro method.
  12. In the COBOL Method Body Editor, add the following line of COBOL code to implement the method.

    {0} IS ALPHABETIC

  13. Save your work.

Results

You can now include in your rules a test for whether or not a data item is alphabetic.