//EXER2F   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. EXER2F.
       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 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 text-msg-with-counter        PIC X(45) VALUE SPACES.
       01 stop-loop-flag               PIC 9(1) COMP VALUE 0.
       01 loop-limit                   PIC 9(4) COMP VALUE 0.
       01 loop-counter                 PIC 9(4) COMP VALUE 0.
       01 loop-counter-text            PIC X(5) VALUE SPACES.

      * Procedures Section
       PROCEDURE DIVISION.
       MAINLINE SECTION.
           MOVE 'EXER2F'                       TO register-name.
           MOVE 'cccccc'                       TO daemongroup.
           MOVE 'nnnnnnn'                      TO node-name.
           MOVE 'sssssss'                      TO server-name.
      *
           MOVE 10                             TO loop-limit.
      *
           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 0 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.

           PERFORM UNTIL loop-counter EQUAL loop-limit

             COMPUTE loop-counter = loop-counter + 1

             INSPECT service-name CONVERTING ' ' to LOW-VALUES

             MOVE loop-counter TO loop-counter-text

             STRING
               loop-counter-text DELIMITED BY SIZE
               text-msg DELIMITED BY SIZE
               INTO text-msg-with-counter
             END-STRING

             MOVE text-msg-with-counter 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 Other-Work
             DISPLAY "This is your program coming back from other work"

      * RCLasync set to 0 (synchronous) above

             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

             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

           END-PERFORM.

           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.
           DISPLAY "Simulation of 'other work' when async=1".

      *  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>(EXER2F),DISP=SHR
//LKED.SYSPRINT DD SYSOUT=*
//LKED.SYSIN  DD  *
  NAME EXER2F(R)
/*
