| United States-English |
|
|
|
![]() |
ALLBASE/SQL COBOL Application Programming Guide: HP 3000 MPE/iX Computer Systems > Chapter 2 Using the ALLBASE/SQL COBOL PreprocessorPreprocessor Input and Output |
|
Regardless of the mode you use, the following files must be available when you invoke the COBOL preprocessor, as shown in Figure 2-2:
When you run the preprocessor in full preprocessing mode, also ensure that the DBEnvironment accessed by the program or subprogram is available. As Figure 2-2 points out, the COBOL preprocessor creates the following temporary output files:
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. If you want to preprocess several ALLBASE/SQL application programs in the same group and account and compile and link the programs later, or you plan to compile a preprocessed program during a future session, you should do the following for each program:
When you are ready to compile the program, you must equate the include file names to their standard ALLBASE/SQL names. See "Preprocessor Generated Include Files" in this chapter for more information. The source file (SQLIN) must be an ASCII file (numbered or unnumbered) that contains at a minimum the following statements:
When parsing SQLIN, the COBOL preprocessor ignores COBOL statements and COBOL compiler directives in SQLIN except $SET, $IF, and $INCLUDE. Only the following information is parsed by the COBOL preprocessor:
Figure 2-5 illustrates an SQLIN file containing a sample program using the following SQL commands highlighted by shading in the figure:
As the runtime 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
Figure 2-5 Program COBEX2
The COBOL preprocessor output files are temporary files. When the SQLIN illustrated in Figure 2-5 is preprocessed, the attributes of the output files created are as follows:
As the COBOL preprocessor parses SQLIN, it copies lines from SQLIN and any file(s) included from SQLIN into SQLOUT, comments out embedded SQL commands, and inserts information around each embedded SQL command. Figure 2-6 illustrates the SQLOUT generated for the SQLIN pictured in Figure 2-5. In both preprocessing modes, the COBOL preprocessor:
In full preprocessing mode, the preprocessor also:
If you need to change statements in SQLOUT, make the changes to SQLIN, re-preprocess SQLIN, and re-compile the output files before putting the application program into production. Figure 2-6 Modified Source File for Program COBEX2
SQLCONST and SQLVAR are preprocessor generated include files which contain declarations for variables and constants referenced in preprocessor generated sentences in SQLOUT. Figure 2-7 and Figure 2-8 illustrate, respectively, the SQLCONST and SQLVAR files that correspond to the SQLOUT file in Figure 2-6. Note that the preprocessor inserts the following two COBOL compiler directives to reference SQLCONST and SQLVAR:
These two directives are always inserted into the WORKING-STORAGE SECTION. Even if you use file equations to redirect the include files, the preprocessor still inserts the same $INCLUDE directives. Therefore when you compile preprocessor output, ensure that the preprocess-time file equations are in effect so the correct include files are compiled:
Figure 2-7 Sample Constant Include File
Figure 2-8 Sample Variable Include File
ALLBASE/SQL now supports the COBOL COPY statement. The preprocessor scans your source code and inserts the indicated copylib modules into the preprocessed code. The REPLACING clause, if specified, is expanded during compilation (not during preprocessing). Two new 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
You can use the directives at any point in your source code. Perhaps your application has many COPY statements, some of which reference modules 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 modules do not contain ALLBASE/SQL commands.
The following sections are presented in this section:
COPY statement syntax and a complete explanation of its use in COBOL is found in chapter 13 of the HP COBOL II/XL Reference Manual. No syntactical differences exist between COBOL and ALLBASE/SQL implementation of the COPY statement. However, you should be aware of the following specifics:
Suppose you want to copy a generic error checking routine into your application. The routine is located in a module named ERRORCPY in the errorlib library. You embed the following COBOL COPY statement in your source code:
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.)
ALLBASE/SQL supports the COBOL SET and IF compiler directives. If you want to preprocess only certain parts of your source code to send to the COBOL compiler, you can set up to ten switches to either ON or OFF. You can then test a flag for ON by testing whether it evaluates to a boolean value of true. If the switch evaluates to true, source records are sent to the compiler, beginning with the first one following the IF statement, and continuing until another IF statement evaluates to false. The SET statement is used to turn a switch off and on. Up to ten named software switches of the form Xn are available, where n is an integer in the range of 0 through 9. The SET statement has the following syntax: $SET [Xn={ ON OFF } [,Xr={ ON OFF }] ...] $IF [Xn={ ON OFF }] Initially, all compilation switches are set to OFF. A SET statement can appear anywhere in the source text. IF the SET statement is used without parameters in the form of SET, all switches are set to OFF. The IF statement interrogates any of the ten compilations switches. If the condition specified in the IF statement evaluates to true, source records are sent to the compiler. An appearance of an IF statement always terminates the influence of any previous IF statement. An IF statement that appears without parameters has the same effect as an IF satement that evaluates to true. When an IF statement evaluates to false, no source records are sent to the compiler until an IF statement evaluates to true is encountered. Suppose you want to conditionally preprocess some parts of your source code and send it to the compiler, and not preprocess other parts of your source code, you could use SET and IF statements in your source code, as follows:
SET and IF statement syntax and a complete explanation of their use in COBOL is found in chapter 13 of the HP COBOL II/XL Reference Manual. No syntactical differences exist between COBOL and ALLBASE/SQL implementation of the SET and IF statements. However, you should be aware of the following specifics:
Messages placed in the ALLBASE/SQL message file (SQLMSG) come from the ALLBASE/SQL message catalog. The formal file designator for the message catalog is:
where xxx is the numerical value for the current language. If this catalog cannot be opened, ALLBASE/SQL looks for the default NATIVE-3000 message catalog:
If the default catalog cannot be opened, ALLBASE/SQL returns an error message saying that the catalog file is not available. If the NATIVE-3000 catalog is available, the user sees a warning message indicating that the default catalog is being used. SQLMSG messages contain four parts:
When you equate SQLMSG to $STDLIST, all these messages appear at the terminal during your session or in the job stream listing. When SQLMSG is not equated to $STDLIST, parts 1 and 4 are still sent to $STDLIST, and all parts appear in the file equated to SQLMSG:
If you want to keep the message file, you should save the file you equate to SQLMSG. It is created as a temporary file. As illustrated in Figure 2-9, a line number is often provided in SQLMSG. This line number references the line in SQLIN containing the command in question. A message accompanied by a number may also appear. You can refer to the ALLBASE/SQL Message Manual for additional information on the exception condition when these numbered messages appear. Figure 2-9 Sample SQLMSG Showing Error
As Figure 2-11 illustrates, the preprocessor can terminate with a warning message. 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-10 Sample SQLMSG Showing Warning
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. By default the installable module file is named SQLMOD. The module in this file can be installed into a DBEnvironment different from the DBEnvironment accessed at preprocessing time by using the INSTALL command in ISQL. For example:
In full preprocessing mode, the preprocessor stores a section for each embedded command except:
The commands listed above either require no authorization to execute or are executed based on information contained in the compilable preprocessor output files. 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:
Figure 2-11 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-11 have the following meanings:
Figure 2-11 Information in SYSTEM.SECTION on Stored Sections
The first eleven 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-6. EXP11 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 DROP option:
Stored sections are marked invalid when:
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. |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||