Task 9: Building your COBOL application

To execute your ruleset, you call the RuleApp from your COBOL application and pass the ruleset parameters to the rule engine that is running an instance of zRule Execution Server for z/OS.

About this task

This tutorial includes a code sample that you can use to call a RuleApp from a COBOL application. The following procedure explains each part of the client code and the steps to follow.

Procedure

To build your COBOL application:

  1. Copy in the zRule Execution Server for z/OS runtime copybooks:
    01 WS-REASON-CODES. 
       COPY HBRC. 
       COPY HBRWS.

    HBRC contains constants that you can use in your application.

    HBRWS contains the working storage structure that is used for calling HBRCONN, HBRRULE, and HBRDISC.

  2. Add the ruleset parameters:
    MOVE LENGTH OF Borrower to HBRA-RA-DATA-LENGTH(1)
    MOVE "borrower" to HBRA-RA-PARAMETER-NAME(1)
    SET HBRA-RA-DATA-ADDRESS(1) to address of Borrower
    MOVE LENGTH OF Loan TO HBRA-RA-DATA-LENGTH(2)
    COMPUTE WS-MAX-TABLE-LEN = LENGTH OF Messages * 99
    ADD WS-MAX-TABLE-LEN TO HBRA-RA-DATA-LENGTH(2)
    MOVE "loan" to HBRA-RA-PARAMETER-NAME(2)
    SET HBRA-RA-DATA-ADDRESS(2) to address of Loan
  3. Specify the ruleset to call:
    MOVE "<your_rule_project_name>" to HBRA-CONN-RULEAPP-PATH
  4. Connect to zRule Execution Server for z/OS:
    call "HBRCONN" using
                        HBRA-CONN-AREA
  5. Call the ruleset and check the return codes:
    call "HBRRULE" using
                        HBRA-CONN-AREA
    
     IF HBRA-CONN-COMPLETION-CODE = HBR-CC-OK THEN
                     DISPLAY "Successful call"
               ELSE
                     DISPLAY "Error "
                             HBRA-CONN-COMPLETION-CODE
                             HBRA-CONN-REASON-CODE
  6. Disconnect from zRule Execution Server for z/OS:
    call "HBRDISC" using
                        HBRA-CONN-AREA

Example

You can find a sample program for the COBOL application in <InstallDir>/studio/tutorials/cobol/cobolstartresz/answer/reszminiloan-execution/cobol/HBRMTUT1.COBOL, where <InstallDir> is the Decision Server installation directory.