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

You can use COBOL mapped method to include an external paragraph file in the generated COBOL code and do actions in your rules that are defined in an external COBOL file. If you want to do 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 by 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.

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
.
.
.