HPlogo ALLBASE/SQL COBOL Application Programming Guide: HP 9000 Computer Systems > Chapter 2 Using the ALLBASE/SQL COBOL Preprocessor

Preprocessor Input and Output

» 

Technical documentation

Complete book in PDF
» Feedback

 » Table of Contents

 » Index

Regardless of the mode you use, the following files must be available when you invoke the COBOL preprocessor, as shown in Figure 2-2.

  • Source file: a file containing the COBOL ALLBASE/SQL program or subprogram with embedded SQL commands for one or more DBEnvironments.

    An alternative name can be specified by using the -i option as explained later in this chapter.

  • ALLBASE/SQL message catalog: a file containing preprocessor messages and ALLBASE/SQL error and warning messages. The fully qualified name for the default message catalog is:

    
    
              /usr/lib/nls/n-computer/hpsqlcat
    

    Note, the COBOL preprocessor does not currently support native language modes.

    As Figure 2-2 points out, the COBOL preprocessor creates the following output files:

  • ALLBASE/SQL message file: a file containing the preprocessor banner, error and warning messages, and other messages. The file is named:

    
    
              sqlmsg
    

  • Installable module file: a file containing a copy of the module created by the preprocessor. The default file name for this file is:

    
    
              SourceFileName.sqlm
    

    An alternative name can be specified by using the -m option as explained later in this chapter.

  • When you run the preprocessor in full preprocessing mode, the preprocessor also stores a module in the DBEnvironment accessed by your program. The module is used at run time to execute DBEnvironment operations.

Figure 2-2 COBOL Preprocessor Input and Output

[COBOL Preprocessor Input and Output]
  • Modified source file: a file containing a modified version of the source code in the source file. The default file name for this file is:

    
    
              SourceFileName.cbl
    

    An alternative name can be specified by using the -p option as described later in this chapter.

  • Copy files: After you use the preprocessor in full preprocessing mode, you use the modified source file and the following three copy files as input to the COBOL compiler, as shown in Figure 2-3.

    These copy files are generated by the preprocessor and contain definitions of variables and constants used by COBOL statements which the preprocessor has inserted into the modified source code file.

    • Constant copy file: This file, which contains constant definitions, is:

      
      
         SourceFileName.sqlc
      

    • Variable copy file: This file, which contains variable definitions, is:

      
      
         SourceFileName.sqlv
      

    The following copy file is not generated by the preprocessor, however, it is needed as input to the compiler.

    - System copy file: This file defines the ALLBASE/SQL subprogram call number. Its fully qualified name is:

    
    
           /usr/include/sqlcall.cbl
    
      

Figure 2-3 Compiling Preprocessor Output and the System Copy File

[Compiling Preprocessor Output and the System Copy File]

When you run the preprocessor in full preprocessing mode, also ensure that the DBEnvironment accessed by the program or subprogram is available.

Source File

The source file must be an ASCII file (numbered or unnumbered) that contains at a minimum the following statements:



        IDENTIFICATION DIVISION.

        PROGRAM-ID.    ProgramName.

        AnyStatement.


When parsing the source file, the COBOL preprocessor ignores COBOL statements and COBOL compiler directives except $INCLUDE. Only the following information is parsed by the COBOL preprocessor:

  • The Program Name. Unless you specify a module name in the preprocessor invocation line, the preprocessor uses the PROGRAM-ID to name the module it stores. A module name can contain as many as 20 characters and must follow the rules governing ALLBASE/SQL basic names (given in the ).

  • Statements found between the prefix EXEC SQL and the suffix END-EXEC. These statements follow the rules given in the chapter, "Embedding SQL Commands." for how and where to embed SQL statements.

  • Statements found between the BEGIN DECLARE SECTION and END DECLARE SECTION commands. These commands delimit a declare section which contains COBOL data description entries for the host variables used in the program. Host variables are described in the chapter, "Host Variables."

Figure 2-5 illustrates a source file containing a sample program using the following SQL commands:



          INCLUDE SQLCA

          BEGIN DECLARE SECTION

          END DECLARE SECTION

          WHENEVER

          CONNECT

          BEGIN WORK

          COMMIT WORK

          RELEASE

          SELECT

          SQLEXPLAIN


As the sample dialog in Figure 2-4 illustrates, the program begins a DBE session for PartsDBE, the sample DBEnvironment. It prompts the user for a part number, then displays information about the part from the table PURCHDB.PARTS. Warning and error conditions are handled with WHENEVER and SQLEXPLAIN commands with the exception of explicit error checking after the SELECT command. The program continues to prompt for a part number until a serious error is encountered or until the user enters a slash (/).

Figure 2-4 Runtime Dialog of Program COBEX2



 Program to SELECT specified rows from the Parts Table - COBEX2



 Event List:

  Connect to PartsDBE

  Begin Work

  SELECT specified Part Number from Parts Table until user enters "/"

  Commit Work

  Disconnect from PartsDBE



 Connect to PartsDBE

 Begin Work



 Enter Part Number within Parts Table or "/" to STOP> 1243-P-01

 SELECT PartNumber, PartName, SalesPrice

 Begin Work



 Part Number not found!

 Commit Work



 Enter Part Number within Parts Table or "/" to STOP> 1323-D-01

 SELECT PartNumber, PartName, SalesPrice

 Begin Work

 Commit Work



 Part Number:  1323-D-01

 Part Name:    Floppy Diskette Drive

 Sales Price:         $200.00



 Enter Part Number within Parts Table or "/" to STOP> 1199-M-01

 SELECT PartNumber, PartName, SalesPrice

 Begin Work

 Commit Work



 Part Number:  1199-M-01

 Part Name:    Modem

 Sales Price is NULL



 Enter Part Number within Parts Table or "/" to STOP> /



 END OF PROGRAM

Figure 2-5 Sample Source File



   * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

   * Program COBEX2:                                             *

   * This program illustrates the use of SQL's SELECT command to *

   * retrieve one row at a time.                                 *

   * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *



    IDENTIFICATION DIVISION.



    PROGRAM-ID.             COBEX2.

    AUTHOR.                 HP TRAINING.

    INSTALLATION.           HP.

    DATE-WRITTEN.           17 OCT 1987.

    DATE-COMPILED.          17 OCT 1987.



    ENVIRONMENT DIVISION.

    CONFIGURATION SECTION.

    SOURCE-COMPUTER.        HP-9000.

    OBJECT-COMPUTER.        HP-9000.



    INPUT-OUTPUT SECTION.



    FILE-CONTROL.

    SELECT TERM ASSIGN TO ":CO:".



    DATA DIVISION.



    FILE SECTION.

    FD TERM.

    01  PROMPT-USER             PIC X(34).



    WORKING-STORAGE SECTION.



    EXEC SQL INCLUDE SQLCA END-EXEC.



   * * * * * *   BEGIN HOST VARIABLE DECLARATIONS  * * * * * * *

    EXEC SQL BEGIN DECLARE SECTION END-EXEC.

    01  PARTNUMBER              PIC X(16).

    01  PARTNAME                PIC X(30).

    01  SALESPRICE              PIC S9(8)V99 COMP-3.

    01  SALESPRICEIND           SQLIND.

    01  SQLMESSAGE              PIC X(132).

    EXEC SQL END DECLARE SECTION END-EXEC.

   * * * * * *   END OF HOST VARIABLE DECLARATIONS * * * * * * *



       77  DONE-FLAG              PIC X(01)  VALUE 'N'.

	88  NOT-DONE           VALUE 'N'.

	88  DONE               VALUE 'Y'.



       77  ABORT-FLAG             PIC X(01)  VALUE 'N'.

	88  NOT-STOP           VALUE 'N'.

	88  ABORT              VALUE 'Y'.



       01  DEADLOCK               PIC S9(9) COMP VALUE -14024.



       01  RESPONSE.

	05  RESPONSE-PREFIX    PIC X(01) VALUE SPACE.

	05  RESPONSE-SUFFIX    PIC X(15) VALUE SPACES.



       01  DOLLARS                 PIC $$$,$$$,$$$.99.



       PROCEDURE DIVISION.



       A100-MAIN.



	ACCEPT RESPONSE.



	DISPLAY "Program to SELECT specified rows from "

		"the Parts Table - COBEX2".

	DISPLAY " ".

	DISPLAY "Event List:".

	DISPLAY "  Connect to PartsDBE".

	DISPLAY "  Begin Work".

	DISPLAY "  SELECT specified Part Number from the "

		"Parts Table until user enters '/' ".

	DISPLAY "  Commit Work".

	DISPLAY "  Disconnect from PartsDBE".

	DISPLAY " ".



	OPEN OUTPUT TERM.



	PERFORM A200-CONNECT-DBENVIRONMENT  THRU  A200-EXIT.



	PERFORM B100-SELECT-DATA THRU B100-EXIT

		UNTIL DONE.



	PERFORM A500-TERMINATE-PROGRAM THRU  A500-EXIT.



    A100-EXIT.

	EXIT.



       A200-CONNECT-DBENVIRONMENT.



	EXEC SQL

	     WHENEVER SQLERROR

	     GO TO S300-SERIOUS-ERROR

	END-EXEC.



	DISPLAY "Connect to ../sampledb/PartsDBE".



	EXEC SQL CONNECT TO '../sampledb/PartsDBE' END-EXEC.



       A200-EXIT.

	EXIT.



       A300-BEGIN-TRANSACTION.



	DISPLAY "Begin Work".

	EXEC SQL

	     BEGIN WORK

	END-EXEC.



       A300-EXIT.

	EXIT.



       A400-END-TRANSACTION.



	DISPLAY "Commit Work".

	EXEC SQL

	     COMMIT WORK

	END-EXEC.



       A400-EXIT.

	EXIT.



       A500-TERMINATE-PROGRAM.



	EXEC SQL

	     RELEASE

	END-EXEC.



	STOP RUN.



       A500-EXIT.

	EXIT.



       B100-SELECT-DATA.



	MOVE SPACES TO RESPONSE.

	MOVE "Enter Part Number within Parts Table or '/' to STOP> "

	     TO PROMPT-USER.

	DISPLAY " ".

	WRITE PROMPT-USER.

	ACCEPT RESPONSE.



	IF  RESPONSE-PREFIX = "/"

	    MOVE "Y" TO DONE-FLAG

	    GO TO B100-EXIT

	ELSE

	    MOVE RESPONSE TO PARTNUMBER.



	EXEC SQL

	     WHENEVER SQLERROR

	     GO TO S400-SQL-ERROR

	END-EXEC.



	EXEC SQL

	     WHENEVER SQLWARNING

	     GO TO S500-SQL-WARNING

	END-EXEC.



	EXEC SQL

	     WHENEVER NOT FOUND

	     GO TO S600-NOT-FOUND

	END-EXEC.



	DISPLAY "SELECT PartNumber, PartName and SalesPrice".



	PERFORM A300-BEGIN-TRANSACTION THRU A300-EXIT.



	EXEC SQL

	     SELECT  PARTNUMBER, PARTNAME, SALESPRICE

	       INTO :PARTNUMBER,

		    :PARTNAME,

		    :SALESPRICE :SALESPRICEIND

	       FROM  PURCHDB.PARTS

	      WHERE  PARTNUMBER = :PARTNUMBER

	END-EXEC.



	PERFORM A400-END-TRANSACTION THRU A400-EXIT.

	PERFORM B200-DISPLAY-ROW THRU B200-EXIT.



       B100-EXIT.

	EXIT.



       B200-DISPLAY-ROW.



	DISPLAY " ".

	DISPLAY "  Part Number:  " PARTNUMBER.

	DISPLAY "  Part Name:    " PARTNAME.



	IF  SALESPRICEIND < 0

	    DISPLAY "  Sales Price is NULL"

	ELSE

	    MOVE SALESPRICE  TO  DOLLARS

	    DISPLAY "  Sales Price:  " DOLLARS.



       B200-EXIT.

	EXIT.





       S100-STATUS-CHECK.



	IF  SQLCODE  <  DEADLOCK

	    MOVE 'Y' TO ABORT-FLAG.



	PERFORM S200-SQL-EXPLAIN THRU S200-EXIT

		UNTIL SQLCODE = 0.



       S100-EXIT.

	EXIT.



       S200-SQL-EXPLAIN.



	EXEC SQL

	     SQLEXPLAIN  :SQLMESSAGE

	END-EXEC.



	DISPLAY SQLMESSAGE.



       S200-EXIT.

	EXIT.



       S300-SERIOUS-ERROR.



	PERFORM S100-STATUS-CHECK  THRU  S100-EXIT.

	PERFORM A500-TERMINATE-PROGRAM  THRU  A500-EXIT.



       S300-EXIT.

	EXIT.



       S400-SQL-ERROR.



	PERFORM S100-STATUS-CHECK THRU S100-EXIT.



	IF  ABORT-FLAG = 'Y'

	    PERFORM A500-TERMINATE-PROGRAM

	ELSE

	    PERFORM A400-END-TRANSACTION THRU A400-EXIT

	    GO TO B100-EXIT.



       S400-EXIT.

	EXIT.



       S500-SQL-WARNING.



	DISPLAY "SQL WARNING has occurred.  The following row "

		"of data may not be valid:".



	PERFORM B200-DISPLAY-ROW THRU B200-EXIT.



	PERFORM A400-END-TRANSACTION  THRU A400-EXIT.



	GO TO B100-EXIT.



       S500-EXIT.

	EXIT.



       S600-NOT-FOUND.



	DISPLAY " ".

	DISPLAY "Part Number not found!".



	PERFORM A400-END-TRANSACTION THRU A400-EXIT.



	GO TO B100-EXIT.



       S600-EXIT.

	EXIT.


Output File Attributes

When the source file illustrated in Figure 2-5 is preprocessed, the attributes of the output files created are as follows:



       $  ll cobex2*



       -rw-rw-r--  1  joann  dbusers     25814  Jul  2  10:26  cobex2.cbl

       -rw-rw-r--  1  joann  dbusers      1539  Jul  2  10:26  cobex2.sqlc

       -rw-rw-rw-  1  joann  dbusers      1500  Jul  2  10:26  cobex2.sqlm

       -rw-rw-rw-  1  joann  dbusers      1148  Jul  2  10:26  cobex2.sqlv



       $  ll sqlmsg



       -rw-rw-rw-  1  joann  dbusers       451  Oct 30  10:26  sqlmsg

Modified Source File

As the COBOL preprocessor parses the source file, it copies lines from the source file and any copy file(s) into the modified source file, comments out embedded SQL commands, and inserts information around each embedded SQL command. The shaded portions of Figure 2-6 illustrate the boundaries of the original code commented out and the modified portions in the preprocessed file generated from the source file pictured in Figure 2-5.

In both preprocessing modes, the COBOL preprocessor:

  • Inserts an * in column 7 on each line containing an embedded SQL command to comment out the SQL command for the COBOL compiler.

  • Places any punctuation you place after an embedded command on the line following the last line generated for the embedded command. Note that the period following the INCLUDE SQLCA command in the source file is in the same column but on a different line in the modified source file. In the modified source file, the period is on the line following the last line generated by the preprocessor for the INCLUDE SQLCA command.

  • Inserts three COBOL compiler directives after the WORKING-STORAGE SECTION label. During compilation, these three COPY commands reference the copy files of the following syntax: SourceFileName.sqlc, SourceFileName.sqlv, and /usr/include/sqlcall.cbl.

  • Inserts a "Start SQL Preprocessor" comment before and an End SQL Preprocessor comment after code it modifies.

In full preprocessing mode, the preprocessor also:

  • Generates a COBOL declaration of the SQLCA following the INCLUDE SQLCA command.

  • Generates COBOL conditional instructions for the following SQL commands: WHENEVER SQLERROR, WHENEVER SQLWARNING, and WHENEVER NOT FOUND.

  • Generates COBOL sentences that call ALLBASE/SQL external procedures at run time. These calls reference the module stored by the preprocessor in the DBEnvironment. Parameters used by these external calls are defined in the copy files with the syntax SourceFileName.sqlc and SourceFileName.sqlv, and the system copy file /usr/include/sqlcall.cbl.

  • Inserts a "Start Inserted Statements" comment before generated information.

CAUTION: Although you can access the preprocessor output files with an editor, you should never change the information generated by the COBOL preprocessor. Your DBEnvironment could be damaged at run time if preprocessor-generated statements are altered.

If you need to change statements not generated by the preprocessor in preprocessor output files, make the changes to the source file(s), preprocess the source file(s), and compile the output files before putting the application program into production.

Figure 2-6 Sample Modified Source File



      * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *           

      * Program COBEX2:                                             *           

      * This program illustrates the use of SQL's SELECT command to *           

      * retrieve one row at a time.                                 *           

      * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *           

                                                                                

       IDENTIFICATION DIVISION.                                                 

                                                                                

       PROGRAM-ID.             COBEX2.                                          

       AUTHOR.                 HP TRAINING                                      

       INSTALLATION.           HP.                                              

       DATE-WRITTEN.           17 OCT 1987.                                     

       DATE-COMPILED.          17 OCT 1987.                                     

                                                                                

       ENVIRONMENT DIVISION.                                                    

       CONFIGURATION SECTION.                                                   

       SOURCE-COMPUTER.        HP-9000.                                         

       OBJECT-COMPUTER.        HP-9000.                                         

                                                                                

       INPUT-OUTPUT SECTION.                                                    

                                                                                

       FILE-CONTROL.                                                            

       SELECT TERM ASSIGN TO ":CO:".                                            

                                                                                

       DATA DIVISION.                                                           

                                                                                

       FILE SECTION.                                                            

       FD TERM.                                                                 

       01  PROMPT-USER                 PIC X(34).                               

                                                                                

       WORKING-STORAGE SECTION. 

 

      **** Start SQL Preprocessor ****

       COPY "cobex2.sqlc".

       COPY "cobex2.sqlv".

       COPY "/usr/include/sqlcall.cbl".

      **** End SQL Preprocessor   ****

       

      **** Start SQL Preprocessor ****

      *EXEC SQL INCLUDE SQLCA END-EXEC.

      **** Start Inserted Statements ****

       01  SQLCA.

           05  SQLCAID       PIC X(8).

           05  SQLCABC       PIC S9(9) COMP     SYNC.

           05  SQLCODE       PIC S9(9) COMP     SYNC.

           05  SQLERRM.

               49  SQLERRML  PIC S9(9) COMP     SYNC.

               49  SQLERRMC  PIC X(256).



           05  SQLERRP       PIC X(8).

           05  SQLERRD       OCCURS 6 TIMES

                             PIC S9(9) COMP     SYNC.

           05  SQLWARN.

               10  SQLWARN0  PIC X(1).

               10  SQLWARN1  PIC X(1).

               10  SQLWARN2  PIC X(1).

               10  SQLWARN3  PIC X(1).

               10  SQLWARN4  PIC X(1).

               10  SQLWARN5  PIC X(1).

               10  SQLWARN6  PIC X(1).

               10  SQLWARN7  PIC X(1).

           05  SQLEXT1       PIC X(4).

           05  SQLEXT2       PIC X(4).

      **** End SQL Preprocessor   ****

                                                                                

                                                                                

      * * * * * *   BEGIN HOST VARIABLE DECLARATIONS  * * * * * * *             

       

      **** Start SQL Preprocessor ****

      *EXEC SQL BEGIN DECLARE SECTION END-EXEC.

      **** End SQL Preprocessor   ****

                                                                                

       01  PARTNUMBER              PIC X(16).                                   

       01  PARTNAME                PIC X(30).                                   

       01  SALESPRICE              PIC S9(8)V99 COMP-3.                         

       01  SALESPRICEIND           PIC S9(4) COMP.                              

       01  SQLMESSAGE              PIC X(132).                                  

       

      **** Start SQL Preprocessor ****

      *EXEC SQL END DECLARE SECTION END-EXEC.

      **** End SQL Preprocessor   ****

                                                                                

      * * * * * *   END OF HOST VARIABLE DECLARATIONS * * * * * * *             

                                                                                

       77  DONE-FLAG              PIC X(01)  VALUE 'N'.                         

           88  NOT-DONE           VALUE 'N'.                                    

           88  DONE               VALUE 'Y'.                                    

                                                                                

       77  ABORT-FLAG             PIC X(01)  VALUE 'N'.                         

           88  NOT-STOP           VALUE 'N'.                                    

           88  ABORT              VALUE 'Y'.                                    

                                                                                

       01  DEADLOCK               PIC S9(9) COMP VALUE -14024.                  

                                                                                

       01  RESPONSE.                                                            

           05  RESPONSE-PREFIX    PIC X(01) VALUE SPACE.                        

           05  RESPONSE-SUFFIX    PIC X(15) VALUE SPACES.                       

                                                                                

       01  DOLLARS                 PIC $$$,$$$,$$$.99.                          

                                                                                

       PROCEDURE DIVISION.                                                      

                                                                                

       A100-MAIN.                                                               

                                                                                

           ACCEPT RESPONSE.                                                     

                                                                                

           DISPLAY SPACE.                                                       

                                                                                

           DISPLAY "Program to SELECT specified rows from "                     

                   "the Parts Table - COBEX2".                                  

           DISPLAY " ".                                                         

           DISPLAY "Event List:".                                               

           DISPLAY "  Connect to PartsDBE".                                     

           DISPLAY "  Begin Work".                                              

           DISPLAY "  SELECT specified Part Number from the "                   

                   "Parts Table until user enters '/' ".                        

           DISPLAY "  Commit Work".                                             

           DISPLAY "  Disconnect from PartsDBE".                                

           DISPLAY " ".                                                         

                                                                                

           OPEN OUTPUT TERM.                                                    

                                                                                

           PERFORM A200-CONNECT-DBENVIRONMENT  THRU  A200-EXIT.                 

                                                                                

           PERFORM B100-SELECT-DATA THRU B100-EXIT                              

                   UNTIL DONE.                                                  

                                                                                

           PERFORM A500-TERMINATE-PROGRAM THRU  A500-EXIT.                      

                                                                                

       A100-EXIT.                                                               

           EXIT.                                                                

                                                                                

       A200-CONNECT-DBENVIRONMENT.                                              



      **** Start SQL Preprocessor ****

      *    EXEC SQL                                                            

      *         WHENEVER SQLERROR                                              

      *         GO TO S300-SERIOUS-ERROR                                       

      *    END-EXEC

      **** Start Inserted Statements ****

           CONTINUE

      **** End SQL Preprocessor   ****

                   .                                                            

                                                                                

           DISPLAY "Connect to ../sampledb/PartsDBE".                           

           

      **** Start SQL Preprocessor ****

      *    EXEC SQL CONNECT TO '../sampledb/PartsDBE' END-EXEC

      **** Start Inserted Statements ****

           MOVE 264 TO SQLCONLEN

           CALL SQLXCBL USING SQLXCON, SQLCA, SQLCONLEN, SQLCONST1

           IF SQLCODE IS NEGATIVE

             GO TO S300-SERIOUS-ERROR

           END-IF

      **** End SQL Preprocessor   ****

                                                              .                 

                                                                                

       A200-EXIT.                                                               

           EXIT.                                                                

                                                                                

       A300-BEGIN-TRANSACTION.                                                  

                                                                                

           DISPLAY "Begin Work".                                                

           

      **** Start SQL Preprocessor ****

      *    EXEC SQL                                                            

      *         BEGIN WORK                                                     

      *    END-EXEC

      **** Start Inserted Statements ****

           MOVE 16 TO SQLCONLEN

           CALL SQLXCBL USING SQLXCON, SQLCA, SQLCONLEN, SQLCONST2

           IF SQLCODE IS NEGATIVE

             GO TO S300-SERIOUS-ERROR

           END-IF

      **** End SQL Preprocessor   ****



       A300-EXIT.                                                               

           EXIT.                                                                

                                                                                

       A400-END-TRANSACTION.                                                    

                                                                                

           DISPLAY "Commit Work".                                               

           

      **** Start SQL Preprocessor ****

      *    EXEC SQL                                                            

      *         COMMIT WORK                                                    

      *    END-EXEC

      **** Start Inserted Statements ****

           MOVE 8 TO SQLCONLEN

           CALL SQLXCBL USING SQLXCON, SQLCA, SQLCONLEN, SQLCONST3

           IF SQLCODE IS NEGATIVE

             GO TO S300-SERIOUS-ERROR

           END-IF

      **** End SQL Preprocessor   ****

                   .                                                            

                                                                                

       A400-EXIT.                                                               

           EXIT.                                                                

                                                                                

       A500-TERMINATE-PROGRAM.                                                  

                                                                                

           

      **** Start SQL Preprocessor ****

      *    EXEC SQL                                                            

      *         RELEASE                                                        

      *    END-EXEC

      **** Start Inserted Statements ****

           MOVE 56 TO SQLCONLEN

           CALL SQLXCBL USING SQLXCON, SQLCA, SQLCONLEN, SQLCONST4

           IF SQLCODE IS NEGATIVE

             GO TO S300-SERIOUS-ERROR

           END-IF

      **** End SQL Preprocessor   ****

                   .                                                            

                                                                                

           STOP RUN.                                                            

                                                                                

       A500-EXIT.                                                               

           EXIT.                                                                



       B100-SELECT-DATA.                                                        

                                                                                

           MOVE SPACES TO RESPONSE.                                             

                                                                                

           MOVE "Enter Part Number or '/' to STOP> "                            

                TO PROMPT-USER.                                                 

           DISPLAY " ".                                                         

           WRITE PROMPT-USER.                                                   

           ACCEPT RESPONSE.                                                     

                                                                                

           IF  RESPONSE-PREFIX = "/"                                            

               MOVE "Y" TO DONE-FLAG                                            

               GO TO B100-EXIT                                                  

           ELSE                                                                 

               MOVE RESPONSE TO PARTNUMBER.                                     

                                                                                

           

      **** Start SQL Preprocessor ****

      *    EXEC SQL                                                            

      *         WHENEVER SQLERROR                                              

      *         GO TO S400-SQL-ERROR                                           

      *    END-EXEC

      **** Start Inserted Statements ****

           CONTINUE

      **** End SQL Preprocessor   ****

                   .                                                            

                                                                                

           

      **** Start SQL Preprocessor ****

      *    EXEC SQL                                                            

      *         WHENEVER SQLWARNING                                            

      *         GO TO S500-SQL-WARNING                                         

      *    END-EXEC

      **** Start Inserted Statements ****

           CONTINUE

      **** End SQL Preprocessor   ****

                   .                                                            



      **** Start SQL Preprocessor ****

      *    EXEC SQL                                                            

      *         WHENEVER NOT FOUND                                             

      *         GO TO S600-NOT-FOUND                                           

      *    END-EXEC

      **** Start Inserted Statements ****

           CONTINUE

      **** End SQL Preprocessor   ****

           DISPLAY "SELECT PartNumber, PartName and SalesPrice".                

           PERFORM A300-BEGIN-TRANSACTION THRU A300-EXIT.                       

      **** Start SQL Preprocessor ****

      *    EXEC SQL                                                            

      *         SELECT  PARTNUMBER, PARTNAME, SALESPRICE                       

      *           INTO :PARTNUMBER,                                            

      *                :PARTNAME,                                              

      *                :SALESPRICE :SALESPRICEIND                              

      *           FROM  PURCHDB.PARTS                                          

      *          WHERE  PARTNUMBER = :PARTNUMBER                               

      *    END-EXEC

      **** Start Inserted Statements ****

           MOVE PARTNUMBER

             TO SQLREC1-FIELD1

           MOVE 1 TO SQLSECNUM

           MOVE 16 TO SQLINLEN

           MOVE 54 TO SQLOUTLEN

           CALL SQLXCBL USING SQLXFET, SQLCA, SQLOWNER, SQLMODNAME, 

             SQLSECNUM, SQLTEMPV, SQLINLEN, SQLOUTLEN, SQLTRUE

           IF SQLCODE IS ZERO

             MOVE SQLREC2-FIELD1

               TO PARTNUMBER

             MOVE SQLREC2-FIELD2

               TO PARTNAME

             MOVE SQLREC2-FIELD3-IND

               TO SALESPRICEIND

             IF SQLREC2-FIELD3-IND IS NOT NEGATIVE

               MOVE SQLREC2-FIELD3

                 TO SALESPRICE

             END-IF

             IF SQLWARN0 IS EQUAL TO "W"

               GO TO S500-SQL-WARNING

             END-IF

           ELSE

             IF SQLCODE IS EQUAL TO 100

               GO TO S600-NOT-FOUND

             END-IF

             IF SQLCODE IS NEGATIVE

               GO TO S400-SQL-ERROR

             END-IF

             CONTINUE

           END-IF

      **** End SQL Preprocessor   ****

                   .                                                            

                                                                                

           PERFORM A400-END-TRANSACTION THRU A400-EXIT.                         

                                                                                

           PERFORM B200-DISPLAY-ROW THRU B200-EXIT.                             

                                                                                

       B100-EXIT.                                                               

           EXIT.                                                                

                                                                                

       B200-DISPLAY-ROW.                                                        

                                                                                

           DISPLAY " ".                                                         

           DISPLAY "  Part Number:  " PARTNUMBER.                               

           DISPLAY "  Part Name:    " PARTNAME.                                 

                                                                                

           IF  SALESPRICEIND < 0                                                

               DISPLAY "  Sales Price is NULL"                                  

           ELSE                                                                 

               MOVE SALESPRICE  TO  DOLLARS                                     

               DISPLAY "  Sales Price:  " DOLLARS.                              

                                                                                

       B200-EXIT.                                                               

           EXIT.                                                                

                                                                                

       S100-STATUS-CHECK.                                                       

                                                                                

           IF  SQLCODE  <  DEADLOCK                                             

               MOVE 'Y' TO ABORT-FLAG.                                          

                                                                                

           PERFORM S200-SQL-EXPLAIN THRU S200-EXIT                              

                   UNTIL SQLCODE = 0.                                           

                                                                                

       S100-EXIT.                                                               

           EXIT.                                                                

                                                                                

       S200-SQL-EXPLAIN.                                                        



      **** Start SQL Preprocessor ****

      *    EXEC SQL                                                            

      *         SQLEXPLAIN  :SQLMESSAGE                                        

      *    END-EXEC

      **** Start Inserted Statements ****

           MOVE SPACES TO SQLREC4

           MOVE 132 TO SQLINLEN

           CALL SQLXCBL USING SQLXPLN, SQLCA, SQLTEMPV, SQLINLEN,

             SQLFALSE

           MOVE SQLREC4-FIELD1

             TO SQLMESSAGE

      **** End SQL Preprocessor   ****

                   .                                                            

                                                                                

           DISPLAY SQLMESSAGE.                                                  

                                                                                

       S200-EXIT.                                                               

           EXIT.                                                                

                                                                                

       S300-SERIOUS-ERROR.                                                      

                                                                                

           PERFORM S100-STATUS-CHECK  THRU  S100-EXIT.                          

           PERFORM A500-TERMINATE-PROGRAM  THRU  A500-EXIT.                     

                                                                                

       S300-EXIT.                                                               

           EXIT.                                                                

                                                                                

       S400-SQL-ERROR.                                                          

                                                                                

           PERFORM S100-STATUS-CHECK THRU S100-EXIT.                            

                                                                                

           IF  ABORT-FLAG = 'Y'                                                 

               PERFORM A500-TERMINATE-PROGRAM                                   

           ELSE                                                                 

               PERFORM A400-END-TRANSACTION THRU A400-EXIT                      

               GO TO B100-EXIT.                                                 

                                                                                

       S400-EXIT.                                                               

           EXIT.                                                                

                                                                                

       S500-SQL-WARNING.                                                        

                                                                                

           DISPLAY "SQL WARNING has occurred.  The following row "              

                   "of data may not be valid:".                                 

                                                                                

           PERFORM B200-DISPLAY-ROW THRU B200-EXIT.                             

                                                                                

           PERFORM A400-END-TRANSACTION  THRU A400-EXIT.                        

                                                                                

           GO TO B100-EXIT.                                                     

                                                                                

       S500-EXIT.                                                               

           EXIT.                                                                

                                                                                

       S600-NOT-FOUND.                                                          

                                                                                

           DISPLAY " ".                                                         

           DISPLAY "Part Number not found!".                                    

                                                                                

           PERFORM A400-END-TRANSACTION THRU A400-EXIT.                         

                                                                                

           GO TO B100-EXIT.                                                     

                                                                                

       S600-EXIT.                                                               

           EXIT.                                                                


Preprocessor-Generated Copy Files

The preprocessor generates two copy files which contain declarations for constants and variables referenced in preprocessor-generated statements in the modified source file. Figure 2-7 and Figure 2-8 illustrate generated files that correspond to the modified source file in Figure 2-6. Note that the preprocessor inserts the following two COBOL compiler directives to reference copy files of the following syntax:



        COPY "SourceFileName.sqlc".

        COPY "SourceFileName.sqlv".

In addition, a COPY directive, allowing the system copy file to be compiled with the modified source file, is inserted by the preprocessor. This file is illustrated in Figure 2-9.



        COPY "/usr/include/sqlcall.cbl".

These three COPY directives are always inserted in the WORKING-STORAGE SECTION of a modified source file.

Figure 2-7 Sample Constant Copy File



       01  SQLCONST1.

           05  SQL0  PIC X(48)

               VALUE "00AE00005061727473444245202020202020202020202020".

           05  SQL1  PIC X(48)

               VALUE "202020202020202020202020202020202020202020202020".

           05  SQL2  PIC X(48)

               VALUE "202020202020202020202020202020202020202020202020".

           05  SQL3  PIC X(48)

               VALUE "202020202020202020202020202020202020202020202020".

           05  SQL4  PIC X(48)

               VALUE "202020202020202020202020202020202020202020202020".

           05  SQL5  PIC X(24)

               VALUE "202020202020202020202020".

       01  SQLCONST2.

           05  SQL0  PIC X(16)

               VALUE "00A6007F00110061".

       01  SQLCONST3.

           05  SQL0  PIC X(8)

               VALUE "00A10000".

       01  SQLCONST4.

           05  SQL0  PIC X(48)

               VALUE "00B200002020202020202020202020202020202020202020".

           05  SQL1  PIC X(8)

               VALUE "FFFFFFFF".

       77  SQLKPCUR     PIC S9(9) COMP.

       77  SQLINLEN     PIC S9(9) COMP.

       77  SQLOUTLEN    PIC S9(9) COMP.

       77  SQLCONLEN    PIC S9(9) COMP.

       77  SQLSECNUM    PIC S9(9) COMP.

       77  SQLCURNUM    PIC S9(9) COMP.

       77  SQLRECLEN    PIC S9(9) COMP.

       77  SQLRECCOUNT  PIC S9(9) COMP.

       77  SQLSTARTREC  PIC S9(9) COMP.

       77  SQLNUMROWS   PIC S9(9) COMP.

       77  SQLTRUE      PIC S9(9) COMP VALUE  1.

       77  SQLFALSE     PIC S9(9) COMP VALUE  0.

       77  SQLOWNER     PIC X(20) VALUE "LELAND@ROYS         ".

       77  SQLMODNAME   PIC X(20) VALUE "COBEX2              ".

       01  SQLTEMPV     PIC X(132) VALUE " ".


Figure 2-8 Sample Variable Copy File



          01  SQLREC1 REDEFINES SQLTEMPV.

	   05  SQL-1-PARTNUMBER           PIC X(16).

          01  SQLREC2 REDEFINES SQLTEMPV.

	   05  SQL-1-PARTNUMBER           PIC X(16).

	   05  SQL-2-PARTNAME             PIC X(30).

	   05  SQL-3-SALESPRICE           PIC S9(8)V9(2) COMP-3.

	   05  SQL-4-SALESPRICEIND        PIC S9(4) COMP.

          01  SQLREC3 REDEFINES SQLTEMPV.

	   05  SQL-TWOROWDUMMY  PIC X(108).

          01  SQLREC4 REDEFINES SQLTEMPV.

	   05  SQL-SQLMESSAGE           PIC X(132).

          01  SQLKPCUR    PIC 9(9) COMP.

          01  SQLINLEN    PIC 9(9) COMP.

          01  SQLOUTLEN   PIC 9(9) COMP.

          01  SQLCONLEN   PIC 9(9) COMP.

          01  SQLSECNUM   PIC 9(9) COMP.

          01  SQLCURNUM   PIC 9(9) COMP.

          01  SQLTRUE     PIC 9(9) COMP VALUE 1.

          01  SQLFALSE    PIC 9(9) COMP VALUE 0.

          01  SQLRECLEN   PIC 9(9) COMP.

          01  SQLRECCOUNT PIC 9(9) COMP.

          01  SQLSTARTREC PIC 9(9) COMP.

          01  SQLNUMROWS  PIC 9(9) COMP.

          01  SQLOWNER  PIC X(20) VALUE "SOMEUSER@SOMEACCT   ".

          01  SQLMODNAME PIC X(20) VALUE "COBEX2              ".

          01  SQLRETURN-CODE PIC 9(4).

Figure 2-9 Sample System Copy File



     01 SQLXCBL PIC X(3) VALUE "120".

COPY Statement Support

ALLBASE/SQL supports the COBOL COPY statement. The preprocessor scans your source code and inserts the indicated copy files into the preprocessed code. The REPLACING clause, if specified, is expanded during compilation (not during preprocessing).

Two compiler directives are used in your source code to set and unset the COPY statement feature. These are shown in the table below.

Table 2-1 Compiler Directives for Implementing the COBOL COPY Statement

DirectiveHow Used
$SQL COPYTurns on ALLBASE/SQL COPY statement processing.
$SQL NOCOPYTurns off ALLBASE/SQL COPY statement processing.

 

$SQL NOCOPY is the default. To be recognized by the preprocessor, the $ must appear in column 7 of your source code. A directive that begins with $SQL is not recognized by the compiler.

You can use the directives at any point in your source code. Perhaps your application has many COPY statements, some of which reference files containing ALLBASE/SQL commands. If you want only ALLBASE/SQL copy code expanded in your preprocessor listing, delimit the appropriate COPY statements with the $SQL COPY and $SQL NOCOPY directives. If you want all copy code expanded at preprocessing time, put the $SQL COPY statement at the beginning of your file. When you do not use these compiler directives, COPY statements are processed at compile time. This is appropriate when your copy code files do not contain ALLBASE/SQL commands.

The following sections are presented in this section:

  • Using the COPY Statement with ALLBASE/SQL.

  • COPY Statement Code Example.

Using the COPY Statement with ALLBASE/SQL

COPY statement syntax and a complete explanation of its use in COBOL are found in chapter 8 of the and chapter 6 of the .

The following syntax requirements reflect the expanded functionality provided by the ALLBASE/SQL preprocessor. Italicized names refer to syntax elements.

  • text-name must be the full file name and path name (if the file is not in the current directory or the library-name or library-name-literal is not specified) of the file to be copied. Compiler defaults for path name and file extensions are not supported by ALLBASE/SQL.

  • external-file-name-literal is the name of a file delimited by quotation marks. This file name may have an extension and may include a path name if no library-name or library-name-literal is specified.

  • library-name must be the name of a directory or a path. text-name or external-file-name-literal is searched for in this location if it is specified.

  • library-name-literal must be the name of a directory or a path name within quotation marks. text-name or external-file-name-literal is searched for in this location if it is specified.

  • The reserved word SUPPRESS can be used to suppress printing the contents of the copy file in the compiler listing.

  • Any ALLBASE/SQL commands within a copy file will be preprocessed, but the REPLACING phrase will have no effect on them.

  • The COPY statement cannot be used within an ALLBASE/SQL command.

COPY Statement Code Example

Suppose you want to copy a generic error checking routine into your application. The routine is located in a copy file named ERRORCOPY. You embed the following COBOL COPY statement in your source code:

 

         $SQL COPY

          COPY ERRORCOPY

         $SQL NOCOPY

 

The preprocessed output file will be as follows. (Note that ALLBASE/SQL commands within the copy file have been expanded just as they would have been if the code had been a part of the main source file.)



         **** Start SQL Preprocessor ****

         *SQL COPY 

         **** End SQL Preprocessor   ****



         **** Start SQL Preprocessor ****

         *COPY ERRORCOPY.

         **** Start insertion of text from: ERRORCOPY

          S100-STATUS-CHECK.



              IF  SQLCODE  <  DEADLOCK

                  MOVE 'Y' TO ABORT-FLAG.



              PERFORM S200-SQL-EXPLAIN THRU S200-EXIT

                      UNTIL SQLCODE = 0.



          S100-EXIT.

              EXIT.



          S200-SQL-EXPLAIN.





         **** Start SQL Preprocessor ****

         *    EXEC SQL

         *         SQLEXPLAIN  :SQLMESSAGE

         *    END-EXEC

         **** Start Inserted Statements ****

              MOVE SPACES TO SQLREC2

              MOVE 2 TO SQLINLEN

              CALL SQLXCBL USING SQLXPLN, SQLCA, SQLTEMPV, SQLINLEN,

                SQLFALSE

              MOVE SQLREC2-FIELD1

                TO SQLMESSAGE

         **** End SQL Preprocessor   ****





              DISPLAY SQLMESSAGE.



          S200-EXIT.

              EXIT. 

         **** End insertion of text from: ERRORCOPY

         **** End SQL Preprocessor   ****



         **** Start SQL Preprocessor ****

         *SQL NOCOPY 

         **** End SQL Preprocessor   ****

                                                                                

ALLBASE/SQL Message File

Messages placed in the SQL message file, named sqlmsg, come from the ALLBASE/SQL message catalog, named /usr/lib/hpsqlcat by default. Ensure that the message catalog is available when you invoke the COBOL preprocessor.

Each SQL message contains four parts:

  • A banner:

    
    
                                                  MON, MAY 21, 1990, 12:48 PM
    
         HP36217-02A.E1.00          COBOL Preprocessor/9000       ALLBASE/SQL 
    
         (C)COPYRIGHT HEWLETT-PACKARD CO. 1982,1983,1984,1985,1986,1987,1988,
    
         1989,1990,1991. ALL RIGHTS RESERVED.
    

  • A summary of the preprocessor invocation conditions:

    
    
         DBEnvironment        = ../sampledb/PartsDBE
    
         Module Name          = COBEX2
    

  • Warnings and errors encountered during preprocessing:

    
    
             34          01 PARTNUMBER               PIC X(16) COMP.
    
    
    
         ******  Syntax error in host variable declaration.   (DBERR 10932)
    
            .
    
    		.
    
    		.
    
         There are errors.  No sections stored.
    
    
    

  • A summary of the results of preprocessing:

    
    
          2 ERRORS    0 WARNINGS
    
         END OF PREPROCESSING.
    
    
    

Both the banner and the preprocessing summary results are echoed to the terminal. Note that sqlmsg is recreated each time the preprocessor is invoked.

As illustrated in Figure 2-10, a line number is often provided in sqlmsg. This line number references the line in the source file containing the command in question. A message accompanied by a number may also appear. You can refer to the for additional information on the exception condition when these numbered messages appear.

Figure 2-10 Sample sqlmsg Showing Error



   $ more sqlmsg

	       .

	       .

	       .

   DBEnvironment        = ../sampledbe/PartsDBE



   Module Name          = COBEX2



          SELECT PARTNUMBER, PARTNAME, SALESPRICE INTO :PARTNUMBER, :PARTNAME,

          :SALESPRICE :SALESPRICEIND FROM PURCHDB.PARTS WHERE PARTNUMBER =

          :PARTNUMBER ;



   ******  ALLBASE/SQL errors (DBERR 10977)

   ******  in SQL statement ending in line 176

   ***     Syntax error.  (DBERR 1001)



   There are errors.  No sections stored.



    1 ERRORS   0 WARNINGS

   END OF PREPROCESSING.

As Figure 2-11 illustrates, the preprocessor can terminate with the warning message

****** ALLBASE/SQL warnings (DBWARN 10602)

when the name of an object in the source file does not match the name of any object in the system catalog. Although a section is stored for the semantically incorrect command, the section is marked as invalid and will not execute at run time if it cannot be validated.

Figure 2-11 Sample sqlmsg Showing Warnings




$ more sqlmsg

  .

  .

  .

DBEnvironment        = ../sampledb/PartsDBE

Module Name          = COBEX2



       SELECT PARNUMBER, PARTNAME, SALESPRICE INTO :PARTNUMBER, :PARTNAME,

       :SALESPRICE :SALESPRICEIND FROM PURCHDB.PARTS WHERE PARTNUMBER =

       :PARTNUMBER ;



******  ALLBASE/SQL warnings   (DBWARN 10602)

******  in SQL statement ending in line 176

***  Column PARNUMBER not found.  (DBERR 2211)



  1 Sections stored in DBEnvironment.



 0 ERRORS   1 WARNINGS

END OF PREPROCESSING

Installable Module File

When the COBOL preprocessor stores a module in the system catalog of a DBEnvironment at preprocessing time, it places a copy of the module in an installable module file. The name of this file is of the syntax SourceFileName.sqlm. This file can be installed into a DBEnvironment different from the DBEnvironment accessed at preprocessing time by using the INSTALL command in ISQL.



        :isql



	   In order to install the module, you need CONNECT

      or DBA authority in the target DBEnvironment:



        isql=> CONNECT TO ../sampledb/PartsDBE

        isql=> INSTALL;



        File name> COBEX2.sqlm

        Name of module in this file:  login.COBEX2

        Number of sections installed:  1

        COMMIT WORK to save to DBEnvironment.



        isql=> COMMIT WORK;

        isql=>

Stored Sections

In full preprocessing mode, the preprocessor stores a section for each embedded command except:



   BEGIN DECLARE SECTION             INCLUDE

   BEGIN WORK                        OPEN

   CLOSE                             PREPARE

   COMMIT WORK                       RELEASE

   CONNECT                           ROLLBACK WORK

   DECLARE CURSOR                    SAVEPOINT

   DELETE WHERE CURRENT              START DBE

   DESCRIBE                          STOP DBE

   END DECLARE SECTION               SQLEXPLAIN

   EXECUTE                           TERMINATE USER

   EXECUTE IMMEDIATE                 UPDATE WHERE CURRENT

                                     WHENEVER

The commands listed above either require no authorization to execute or are executed based on information contained in the compilable preprocessor output files. Note that if the DELETE WHERE CURRENT or UPDATE WHERE CURRENT command is dynamically preprocessed, a section does exist in the module.

When the preprocessor stores a section, it actually stores what is known as an input tree and a run tree. The input tree consists of an uncompiled command. The run tree is the compiled, executable form of the command.

If a section is valid at run time, ALLBASE/SQL executes the appropriate run tree when the SQL command is encountered in the application program. If a section is invalid, ALLBASE/SQL determines whether the objects referenced in the sections exist and whether current authorization criteria are satisfied. When an invalid section can be validated, ALLBASE/SQL dynamically recompiles the input tree to create an executable run tree and executes the command. When a section cannot be validated, the command is not executed, and an error condition is returned to the program.

There are three types of sections:

  • Sections for executing the SELECT command associated with a DECLARE CURSOR command.

  • Sections for executing the SELECT command associated with a CREATE VIEW command.

  • Sections for all other commands for which the preprocessor stores a section.

Figure 2-12 illustrates the kinds of information in the system catalog that describe each type of stored section. The query result illustrated was extracted from the system view named SYSTEM.SECTION by using ISQL. The columns in Figure 2-12 have the following meanings:

  • NAME: This column contains the name of the module to which a section belongs. You specify a module name when you invoke the preprocessor; the module name is by default the PROGRAM-ID.

  • OWNER: This column identifies the owner of the module. You specify an owner name when you invoke the preprocessor; the owner name is by default the userid associated with the preprocessing session.

  • DBEFILESET: This column indicates the DBEFileSet with which DBEFiles housing the section are associated.

  • SECTION: This column gives the section number. Each section associated with a module is assigned a number by the preprocessor as it parses the related SQL command at preprocessing time.

  • TYPE: This column identifies the type of section:

    
    
    	      1 = SELECT associated with a cursor
    
    	      2 = SELECT defining a view
    
    	      0 = All other sections
    
      

  • VALID: This column identifies whether a section is valid or invalid:

    
    
    	      0 = invalid
    
    	      1 = valid
    

Figure 2-12 Information in SYSTEM.SECTION on Stored Sections

isql=>SELECT NAME,OWNER,DBEFILESET,SECTION,TYPE,VALID FROM SYSTEM.SECTION;

SELECT NAME,OWNER,DBEFILESET,SECTION,TYPE,VALID FROM SYSTEM.SECTION;

---------------------------------------------------------------------------
NAME              |OWNER        |DBEFILESET       |SECTION  |TYPE  |VALID
---------------------------------------------------------------------------
TABLE             |SYSTEM       |SYSTEM           |        0|     2|     0
COLUMN            |SYSTEM       |SYSTEM           |        0|     2|     0
INDEX             |SYSTEM       |SYSTEM           |        0|     2|     0
SECTION           |SYSTEM       |SYSTEM           |        0|     2|     0
DBEFILESET        |SYSTEM       |SYSTEM           |        0|     2|     0
DBEFILE           |SYSTEM       |SYSTEM           |        0|     2|     0
SPECAUTH          |SYSTEM       |SYSTEM           |        0|     2|     0
TABAUTH           |SYSTEM       |SYSTEM           |        0|     2|     0
COLAUTH           |SYSTEM       |SYSTEM           |        0|     2|     0
MODAUTH           |SYSTEM       |SYSTEM           |        0|     2|     0
GROUP             |SYSTEM       |SYSTEM           |        0|     2|     0
VIEWDEF           |SYSTEM       |SYSTEM           |        0|     2|     0
HASH              |SYSTEM       |SYSTEM           |        0|     2|     0
CONSTRAINT        |SYSTEM       |SYSTEM           |        0|     2|     0
CONSTRAINTCOL     |SYSTEM       |SYSTEM           |        0|     2|     0
CONSTRAINTINDEX   |SYSTEM       |SYSTEM           |        0|     2|     0
COLDEFAULT        |SYSTEM       |SYSTEM           |        0|     2|     0
TEMPSPACE         |SYSTEM       |SYSTEM           |        0|     2|     0
PARTINFO          |PURCHDB      |SYSTEM           |        0|     2|     0
VENDORSTATISTICS  |PURCHDB      |SYSTEM           |        0|     2|     0
COBEX2            |GRAY         |SYSTEM           |        1|     0|     1
COBEX8            |GRAY         |SYSTEM           |        1|     1|     1
COBEX8            |GRAY         |SYSTEM           |        2|     0|     1

The first eighteen rows in this query result describe the sections stored for the system views. The next two rows describe the two views in the sample database: PURCHDB.PARTINFO and PURCHDB.VENDORSTATISTICS. Views are always stored as invalid sections, because the run tree is always generated at run time.

The remaining rows describe sections associated with two preprocessed programs. COBEX2 contains only one section, for executing the SELECT command in the program illustrated in Figure 2-5. COBEX8 contains two sections, one for executing the SELECT command associated with a DECLARE CURSOR command and one for executing a FETCH command.

Stored sections remain in the system catalog until they are deleted with the DROP MODULE command or by invoking the preprocessor with the -d option:


       isql=> DROP MODULE COBEX2;

      or

       $ psqlcbl ../sampledb/PartsDBE -i cobex2 -d

Stored sections are marked invalid when:
  • The UPDATE STATISTICS command is executed.
  • Tables accessed in the program are dropped, altered, or assigned new owners.
  • Indexes or DBEFileSets related to tables accessed in the program are changed.
  • Module owner authorization changes occur that affect the execution of embedded commands.
When an invalid section is validated at run time, the validated section is committed when the program issues a COMMIT WORK command. If a COMMIT WORK command is not executed, ALLBASE/SQL must revalidate the section again the next time the program is executed. For this reason, you should embed COMMIT WORK commands even following SELECT commands, since the COMMIT WORK command may be needed even when data is not changed by a program.