The ESQL Translation Process

The AcuSQL® pre-compiler identifies and translates ESQL statements into COBOL statements. It begins its work in the program's Data Division. The pre-compiler identifies ESQL statements by searching for the keywords EXEC SQL and END-EXEC in the source code. When it finds these markers, it encapsulates them with comments and line numbers and then parses and generates COBOL code, including CALLs to the AcuSQL library.

For example, if your code specifies an include file such as:

EXEC SQL INCLUDE SQLCA END-EXEC. 

This line is translated into:

*(( PREPROC ACUSQL LINE BEGIN 12 ))
   01  SQLCA IS EXTERNAL.
       05  SQLCAID                PIC X(8).
       05  SQLCABC         COMP-5 PIC S9(9).
       05  SQLCODE         COMP-5 PIC S9(9).
       05  SQLERRM.
           10  SQLERRML    COMP-5 PIC S9(4).
           10  SQLERRMC           PIC X(70).
       05  SQLERRP                PIC X(8).
       05  SQLERRD OCCURS 6 TIMES COMP-5 PIC S9(9).
       05  SQLWARN.
           10  SQLWARN0           PIC X.
           10  SQLWARN1           PIC X.
           10  SQLWARN2           PIC X.
           10  SQLWARN3           PIC X.
           10  SQLWARN4           PIC X.
           10  SQLWARN5           PIC X.
           10  SQLWARN6           PIC X.
           10  SQLWARN7           PIC X.
           10  SQLWARN8           PIC X.
           10  SQLWARN9           PIC X.
           10  SQLWARNA           PIC X.
       05  SQLSTATE               PIC X(5).
       05  SQLERRM-PREFIX.
           10  SQLERRPL    COMP-5 PIC S9(4).
           10  SQLERRPC           PIC X(70)
*EXEC SQL INCLUDE SQLCA END-EXEC.                             
*(( PREPROC ACUSQL LINE END 12 ))
           .                                    

The following ESQL statement:

EXEC SQL
    SELECT MIN(C_NUMBER)
        INTO :MIN-C-NUMBER
        FROM CUSTOMER
END-EXEC.

is translated into:

*(( PREPROC ACUSQL LINE BEGIN 41 ))
           PERFORM CALL "SQL$START" END-CALL CALL "SQL$PREPARE" USING 'S
      -    'QLISTM' "SELECT MIN(C_NUMBER) FROM CUSTOMER " END-CALL IF SQ
      -    LCODE OF SQLCA < 0 THEN GO TO Error-Exit END-IF CALL "SQL$BIN
      -    "DCOLUMN" USING 'SQLISTM' 1 MIN-C-NUMBER   END-CALL IF SQLCOD
      -    E OF SQLCA < 0 THEN GO TO Error-Exit END-IF CALL "SQL$CURSOR"
            USING 'SQLICUR' 'SQLISTM' IF SQLCODE OF SQLCA < 0 THEN GO TO
            Error-Exit END-IF CALL "SQL$OPEN" USING 'SQLICUR' IF SQLCODE
            OF SQLCA < 0 THEN GO TO Error-Exit END-IF CALL "SQL$FETCH" U
      -    SING 1 0 'SQLICUR' IF SQLCODE OF SQLCA < 0 THEN GO TO Error-E
      -    xit END-IF CALL "SQL$CLOSE" USING 'SQLICUR' IF SQLCODE OF SQL
      -    CA < 0 THEN GO TO Error-Exit END-IF CALL "SQL$UNPREPARE" USIN
      -    G 'SQLISTM'  END-CALL END-PERFORM
      *    EXEC SQL
      *        SELECT MIN(C_NUMBER)
      *            INTO :MIN-C-NUMBER
      *            FROM CUSTOMER
      *    END-EXEC.
      *(( PREPROC ACUSQL LINE END 45 ))
           .

The pre-compiler generates a standard 72-character line without regard for the end of statements or other formatting considerations.

The line numbers that appear in the comment lines specify the original line numbers in the input file.

Note: The precise results of these translations may vary depending on your version of the pre-compiler.