       *>
       *> Micro Focus Server Express XA switch module for DB2.
       *>
       *> (C) Copyright 2003-2007 Micro Focus (IP) Limited.
       *> All Rights Reserved.
       *>

       IDENTIFICATION DIVISION.
       PROGRAM-ID. ESDB2XA.
       ENVIRONMENT DIVISION.

       CONFIGURATION SECTION.
       SPECIAL-NAMES.

       DATA DIVISION.

       WORKING-STORAGE SECTION.

          01 subpptr     USAGE PROCEDURE-POINTER VALUE NULL.
          01 XASwitchPtr USAGE POINTER VALUE NULL.

       *> Database Access structure used by Enterprise Server.

       78 78-XA-ONEPHASE-SUPPORT              VALUE H'80000000'.

       01 esdb2xa-dbaccess-struct.
          03 esdb2xa-xa-structure.
             05 esdb2xa-RM-name               PIC X(32).
             05 esdb2xa-flags                 PIC S9(9) COMP-5.
             05 esdb2xa-version               PIC S9(9) COMP-5.
             05 esdb2xa-open-entry            PROCEDURE-POINTER.
             05 esdb2xa-close-entry           PROCEDURE-POINTER.
             05 esdb2xa-start-entry           PROCEDURE-POINTER.
             05 esdb2xa-end-entry             PROCEDURE-POINTER.
             05 esdb2xa-rollback-entry        PROCEDURE-POINTER.
             05 esdb2xa-prepare-entry         PROCEDURE-POINTER.
             05 esdb2xa-commit-entry          PROCEDURE-POINTER.
             05 esdb2xa-recover-entry         PROCEDURE-POINTER.
             05 esdb2xa-forget-entry          PROCEDURE-POINTER.
             05 esdb2xa-complete-entry        PROCEDURE-POINTER.
       78 78-XA-STRUCTURE-LEN                 VALUE
                               NEXT - START OF esdb2xa-xa-structure.
             05 esdb2xa-1phase.
                07 esdb2xa-1phase-flags            PIC X(8).
                07 esdb2xa-1phase-connect-entry    PROCEDURE-POINTER.
                07 esdb2xa-1phase-disconnect-entry PROCEDURE-POINTER.
                07 esdb2xa-1phase-commit-entry     PROCEDURE-POINTER.
                07 esdb2xa-1phase-rollback-entry   PROCEDURE-POINTER.
       78 78-XA-DBACCESS-STRUCT-LEN           VALUE
                               NEXT - START OF esdb2xa-xa-structure.

       LINKAGE SECTION.
       01  lk-switch-area              PIC X.

       PROCEDURE DIVISION.

          INITIALIZE esdb2xa-dbaccess-struct

          CALL "db2xacic" RETURNING XASwitchPtr
          END-CALL

           IF XASwitchPtr NOT = NULL
               SET ADDRESS OF lk-switch-area
                                       TO XASwitchPtr
               move LK-SWITCH-AREA(1:78-XA-STRUCTURE-LEN)
                                       TO esdb2xa-xa-structure

               SET subpptr TO ENTRY "ESDB2OPC.so"
               IF subpptr NOT = NULL

                  SET esdb2xa-1phase-commit-entry
                                  TO ENTRY 'esdb2opc_1pc_commit'    
                  SET esdb2xa-1phase-rollback-entry  
                                  TO ENTRY 'esdb2opc_1pc_rollback'
                  SET esdb2xa-1phase-connect-entry
                                  TO ENTRY 'esdb2opc_1pc_connect'
                  SET esdb2xa-1phase-disconnect-entry
                                  TO ENTRY 'esdb2opc_1pc_disconnect'
                  COMPUTE esdb2xa-flags = 
                       esdb2xa-flags B-OR 78-XA-ONEPHASE-SUPPORT
               END-IF
               SET XASwitchPtr TO ADDRESS OF esdb2xa-dbaccess-struct
           END-IF

          GOBACK RETURNING XASwitchPtr
          .

