Example: Creating a mapped method to call external COBOL code

A typical usage of a COBOL macro method is to include an external paragraph file in the generated COBOL code.

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.

You can use COBOL mapped method to include an external paragraph file in the generated COBOL code and perform actions in your rules that are defined in an external COBOL file. If you want to perform actions in your rules that are defined in an external COBOL file, you can include the file in the PROCEDURE SECTION of the generated COBOL code. You include an external paragraph file using a macro method.

Procedure

To include an external paragraph file:

  1. Define the required paragraph or paragraphs in an external file. For example, a file named EXTERNAL-PARA has two paragraphs:
    PARAGRAPH-1.
       IF AMOUNT > 2000
           MOVE 1 TO FLAG
       END-IF.
    
    PARAGRAPH-2.
       IF TYPES ='DOLLAR'
           MOVE 1 TO ACCEPTED
       END-IF.
  2. In Rule Designer, create methods to include the paragraphs you have defined. For example, using the paragraphs in Step 1, add the following methods:
    • public static void performAmountCheck ()

    • public static void performTypeCheck ()

  3. Scroll down to the COBOL Method section of the BOM Editor.
  4. To implement the performAmountCheck () method:
    1. In the Outline view, click Create a macro method.
    2. In the COBOL Method Body Editor, add the following line of COBOL code to implement the method.

      PERFORM PARAGRAPH-1

  5. To implement the performTypeCheck () method, create it as a macro method and then add the following code:

    PERFORM PARAGRAPH-2

  6. Save your work.

    You can now write the action part of the rule as follows:

    then
      perform Amount Check ;
      perform Type Check ;
  7. When you generate the COBOL code, specify the external filename to include the file in the PROCEDURE SECTION of the COBOL code. You specify the external filename as a project property:
    1. In the Rule Explorer, right-click the rule project and then select Properties > COBOL Management > COBOL Code Generation.
    2. On the COBOL Code Generation properties page, in the Procedure Copy field, enter the name of the external file.
    3. Click OK to close the Properties page.

Results

In the following example, the PROCEDURE DIVISION of the generated COBOL code includes an external file named EXTERNAL-PARA:

PROCEDURE DIVISION.
* Rule testExternalParagraph
RULE-1TESTEXTERNALPARAGRAPH.
    PERFORM PARAGRAPH-1.
    PERFORM PARAGRAPH-2.
.
.
.
COPY EXTERNAL-PARA
.
.
.