//EXER2G   JOB (),'<name>',REGION=0M,
//   MSGCLASS=H,NOTIFY=&SYSUID
//* ***************************************************************
//* The following code is sample code created by IBM Corporation. 
//* This sample code is not part of any standard IBM product and  
//* is provided to you solely for the purpose of assisting you in 
//* the development of your applications.  The code is provided   
//* 'as is', without warranty or condition of any kind.  IBM shall
//* not be liable for any damages arising out of your use of the  
//* sample code, even if IBM has been advised of the possibility  
//* of such damages.                                              
//* ***************************************************************
//MYPROCS JCLLIB ORDER=SYS1.ECOBOL.SIGYPROC
//*
//COBOL EXEC IGYWCL,
//     PARM.COBOL='NODYNAM,LIST,DATA(31),RENT',
//     PARM.LKED='LIST,XREF,LET,MAP,AMODE(31),RMODE(ANY),CALL'
/*
//COBOL.SYSIN  DD  *
       IDENTIFICATION DIVISION.
       PROGRAM-ID. EXER2G.
       ENVIRONMENT DIVISION.
       DATA DIVISION.
       WORKING-STORAGE SECTION.
      * API Parms
       01 daemongroup                  PIC X(8) VALUE LOW-VALUES.
       01 node-name                    PIC X(8).
       01 server-name                  PIC X(8).
       01 register-name                PIC X(12) VALUE SPACES.
       01 minconn                      PIC 9(8) COMP VALUE 1.
       01 maxconn                      PIC 9(8) COMP VALUE 10.
       01 regopts                      PIC 9(8) COMP VALUE 0.
       01 urgopts                      PIC 9(8) COMP VALUE 0.
       01 service-name                 PIC X(255).
       01 service-name-length          PIC 9(8) COMP.
       01 rqst-area                    PIC X(100) VALUE SPACES.
       01 rqst-area-addr               USAGE POINTER.
       01 rqst-area-length             PIC 9(8) COMP VALUE 100.
       01 resp-area                    PIC X(100) VALUE SPACES.
       01 resp-area-addr               USAGE POINTER.
       01 resp-area-length             PIC 9(8) COMP VALUE 100.
       01 resp-area-length-char REDEFINES resp-area-length PIC X(4).
       01 connect-handle               PIC X(12) VALUE LOW-VALUES.
       01 wait-time                    PIC 9(8) USAGE BINARY.
       01 rqst-type                    PIC 9(8) COMP VALUE 1.
       01 SRQasync                     PIC 9(8) COMP VALUE 0.
       01 RCLasync                     PIC 9(8) COMP VALUE 0.
       01 rc                           PIC 9(8) COMP VALUE 0.
       01 rsn                          PIC 9(8) COMP VALUE 0.
       01 rv                           PIC 9(8) COMP VALUE 0.
      * Working Variables
       01 text-msg                     PIC X(40) VALUE SPACES.
       01 good-RCL-flag                PIC 9(1) COMP VALUE 0.
       01 RCL-attempts                 PIC 9(4) COMP VALUE 0.
       01 other-work-counter           PIC 9(8) COMP VALUE 0.

      * Procedures Section
       PROCEDURE DIVISION.
       MAINLINE SECTION.
           MOVE 'EXER2G'                       TO register-name.
           MOVE 'cccccc'                       TO daemongroup.
           MOVE 'nnnnnnn'                      TO node-name.
           MOVE 'sssssss'                      TO server-name.
      *
           MOVE 'This is a test message'       TO text-msg.
           MOVE 'ejb/com/ibm/ola/olasample1_echoHome'
                TO service-name.

           INSPECT daemongroup CONVERTING ' ' to LOW-VALUES.

           CALL 'BBOA1REG' USING
                 daemongroup,
                 node-name,
                 server-name,
                 register-name,
                 minconn,
                 maxconn,
                 regopts,
                 rc,
                 rsn.

           IF rc > 0 THEN
             DISPLAY "OLA - BBOA1REG problem -- rc/rsn : " rc "/" rsn
             GO TO Bad-RC
           ELSE
             DISPLAY "Successfully registered into " daemongroup
           END-IF.

      *  Asynch BBOA1SRQ with synchronous BBOA1RCL

           MOVE 1 TO SRQasync.
           MOVE 1 TO RCLasync.

           CALL 'BBOA1CNG' USING
                 register-name,
                 connect-handle,
                 wait-time,
                 rc,
                 rsn.

           IF rc > 0 THEN
             DISPLAY "OLA - BBOA1CNG problem, rc/rsn: " rc "/" rsn
             GO TO Bad-RC
           END-IF.

           INSPECT service-name CONVERTING ' ' to LOW-VALUES.

           MOVE text-msg TO rqst-area.
           MOVE LENGTH OF rqst-area TO rqst-area-length.

           SET rqst-area-addr TO ADDRESS OF rqst-area.
           SET resp-area-addr TO ADDRESS OF resp-area.

           CALL 'BBOA1SRQ' USING
                 connect-handle,
                 rqst-type,
                 service-name,
                 service-name-length,
                 rqst-area-addr,
                 rqst-area-length,
                 SRQasync,
                 resp-area-length,
                 rc,
                 rsn.

           IF rc > 0 THEN
             DISPLAY "OLA - BBOA1SRQ problem, rc/rsn: " rc "/" rsn
             GO TO Bad-RC
           END-IF.

           PERFORM UNTIL good-RCL-flag EQUAL 1

             PERFORM Other-Work

             CALL 'BBOA1RCL' USING
                   connect-handle,
                   RCLasync,
                   resp-area-length,
                   rc,
                   rsn

             IF rc > 0 THEN
               DISPLAY "OLA - BBOA1RCL problem, rc/rsn: " rc "/" rsn
               GO TO Bad-RC
             END-IF

             IF resp-area-length-char EQUAL HIGH-VALUES THEN
               COMPUTE RCL-attempts = RCL-attempts + 1
             ELSE
               DISPLAY "Good RCL on attempt: " RCL-attempts
               MOVE 0 TO RCL-attempts
               MOVE 1 TO good-RCL-flag
             END-IF

           END-PERFORM.

           CALL 'BBOA1GET' USING
                 connect-handle,
                 resp-area-addr,
                 resp-area-length,
                 rc,
                 rsn,
                 rv

           IF rc > 0 THEN
             DISPLAY "OLA - BBOA1GET problem, rc/rsn: " rc "/" rsn
             GO TO Bad-RC
           ELSE
             DISPLAY "Message sent: " rqst-area
             DISPLAY "Message back: " resp-area
           END-IF

           CALL 'BBOA1CNR' USING
                 connect-handle,
                 rc,
                 rsn.

           IF rc > 0 THEN
             DISPLAY "OLA - BBOA1CNR problem, rc/rsn: " rc "/" rsn
             GO TO Bad-RC
           END-IF.

      *  Unregister from the Daemon group using BBOA1URG API           *

           CALL 'BBOA1URG' USING
               register-name,
               urgopts,
               rc,
               rsn.

           IF rc > 0 THEN
             DISPLAY "OLA - BBOA1URG problem -- rc/rsn: " rc "/" rsn
             GO TO Bad-RC
           ELSE
             DISPLAY "Successfully unregistered from " daemongroup
           END-IF.

           GOBACK.

      *  Used to doing other work when asych=1 specified

       Other-Work.
           PERFORM UNTIL other-work-counter EQUAL 10000
             COMPUTE other-work-counter = other-work-counter + 1
           END-PERFORM.
           MOVE 0 TO other-work-counter.

      *  Section used to exit batch if any API returned RC>0

       Bad-RC.

           DISPLAY "OLA - EXITING program due to non-RC=0."
           GOBACK.

/*
//LKED.SYSLIB DD DSN=<your hlq.SCEELKED>,DISP=SHR
//            DD DSN=<your WOLA module loadlib,DISP=SHR
//LKED.SYSLMOD DD DSN=<your_loadlib>(EXER2G),DISP=SHR
//LKED.SYSPRINT DD SYSOUT=*
//LKED.SYSIN  DD  *
  NAME EXER2G(R)
/*
