Task 5: 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 inside 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.

You can find the sample COBOL application in <InstallDir>/studio/tutorials/cobol/bomstartrez/answer/SharingZMiniloan-execution/cobol/HBRMTUT2.COBOL where <InstallDir> is the Decision Server installation directory.

Procedure

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