      $SET INITCALL"UTILS.LBR"
      $set osvs 
      $set sql(DBMAN=ODBC,TARGETDB=MSSQLSERVER) 
       ID  DIVISION.
       PROGRAM-ID. ACCTBTCH.
       ENVIRONMENT DIVISION.
       CONFIGURATION SECTION.
       SPECIAL-NAMES.
       DATA DIVISION.
       WORKING-STORAGE SECTION.
           EXEC SQL BEGIN DECLARE SECTION END-EXEC.

       01  ACCTREC.
	   EXEC SQL INCLUDE ACCTREC END-EXEC.

           EXEC SQL END DECLARE SECTION END-EXEC.

           EXEC SQL INCLUDE SQLCA END-EXEC.

       01   SQLCODE-DISP        PIC -9(9).

       PROCEDURE DIVISION.
       MAIN-LINE.
	   EXEC SQL WHENEVER SQLERROR GOTO BATCH-ERROR END-EXEC.
	   EXEC SQL WHENEVER NOT FOUND CONTINUE END-EXEC.
           DISPLAY "ACCTBTCH: DECLARE CURSOR".
           EXEC SQL
                DECLARE C1 CURSOR FOR
	        SELECT DOACCT, DOSNAME
	        FROM ACTREC
           END-EXEC.

           DISPLAY "ACCTBTCH: OPEN CURSOR".
	   EXEC SQL OPEN C1 END-EXEC.
	   IF SQLCODE NOT = 0
	      MOVE SQLCODE TO SQLCODE-DISP
	      DISPLAY "SQLEROR IN OPENING CURSOR" SQLCODE-DISP
	      GOBACK.
	   PERFORM FETCH-RECORD THRU FETCH-EXIT
		   UNTIL SQLCODE = 100.
	   EXEC SQL CLOSE C1 END-EXEC.
	   SET RETURN-CODE TO 0.
	   GOBACK.

       FETCH-RECORD.
           DISPLAY "ACCTBTCH: FETECH DATA".
	   EXEC SQL FETCH C1 INTO
	        :DOACCT, :DOSNAME
	   END-EXEC.
           IF SQLCODE NOT = 0
	      GO TO FETCH-EXIT.
           DISPLAY DOACCT, "   ",  DOSNAME.
       FETCH-EXIT.
	    EXIT.

       BATCH-ERROR.
	    MOVE SQLCODE TO SQLCODE-DISP.
	    DISPLAY "ACCTBTCH: SQLERROR " SQLCODE-DISP.
            DISPLAY "ACCTBTCH: SQLERRMC = " SQLERRMC.
	    GOBACK.
