HP 3000 Manuals

Preprocessor Input and Output [ ALLBASE/SQL COBOL Application Programming Guide ] MPE/iX 5.0 Documentation


ALLBASE/SQL COBOL Application Programming Guide

Preprocessor 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:

   *   source file:  a file containing the source code for the COBOL
       ALLBASE/SQL program or subprogram with embedded SQL commands for a
       DBEnvironment.  The formal file designator for this input file is:

              SQLIN

   *   ALLBASE/SQL message catalog:  a file containing preprocessor
       messages and ALLBASE/SQL error and warning messages.  The formal
       file designator for the message catalog is as follows, with xxx 
       being the numeric representation of the current native language:

              SQLCTxxx.PUB.SYS

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:

   *   modified source file:  a file containing a modified version of the
       source code in SQLIN. The formal file designator for this file is:

              SQLOUT

       After you use the preprocessor in full preprocessing mode, you use
       SQLOUT and the following two include files as input files for the
       COBOL compiler, as shown in Figure 2-4.

   *   include files:  files containing definitions of variables and
       constants used by COBOL statements the preprocessor inserts into
       SQLOUT. The formal file designators for these files are:

              SQLVAR

              SQLCONST

   *   ALLBASE/SQL message file:  a file containing the preprocessor
       banner, error and warning messages, and other messages.  The
       formal file designator for this file is:

              SQLMSG

   *   installable module file:  a file containing a copy of the module
       created by the preprocessor.  The formal file designator for this
       file is:

              SQLMOD

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:

   *   Before running the preprocessor, equate SQLIN to the name of the
       file containing the application you want to preprocess:

              :FILE SQLIN = InFile 

   *   After running the preprocessor, save and rename the output files
       if you do not want them overwritten.  For example:

     :SAVE SQLOUT 
     :RENAME SQLOUT, OutFile 
     :SAVE SQLMOD 
     :RENAME SQLMOD, ModFile 
     :SAVE SQLVAR 
     :RENAME SQLVAR, VarFile 
     :SAVE SQLCONST 
     :RENAME SQLCONST, ConstFile 

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.

[]
Figure 2-2. COBOL Preprocessor Input and Output
[]
Figure 2-3. Compiling Preprocessor Output Source File The source file (SQLIN) must be an ASCII file (numbered or unnumbered) that contains at a minimum the following statements: IDENTIFICATION DIVISION. PROGRAM-ID ProgramName. AnyStatement. 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: * The PROGRAM-ID. 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 ALLBASE/SQL Reference Manual). * Statements found between the prefix EXEC SQL and the suffix END-EXEC. These statements follow the rules given in Chapter 3 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 Chapter 4. Figure 2-5 illustrates an SQLIN file containing a sample program using the following SQL commands highlighted by shading in the figure: INCLUDE SQLCA BEGIN DECLARE SECTION END DECLARE SECTION WHENEVER CONNECT BEGIN WORK COMMIT WORK SELECT SQLEXPLAIN 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 (/). ____________________________________________________________________________ | | | | | :RUN COBEX2P | | 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 | | | | 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> 1823-PT-01 | | SELECT PartNumber, PartName, SalesPrice | | Begin Work | | Commit Work | | | | Part Number: 1823-PT-01 | | Part Name: Graphics Printer | | Sales Price: $450.00 | | | | Enter Part Number within Parts Table or "/" to STOP> / | | | | END OF PROGRAM | | | | | | | | | ____________________________________________________________________________ Figure 2-4. Runtime Dialog of Program COBEX2 _________________________________________________________________________ | | | | | * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *| | * 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 JULY 1987. | | DATE-COMPILED. 17 JULY 1987. | | REMARKS. SQL'S SELECT WITH WHENEVER COMMAND. | | | | ENVIRONMENT DIVISION. | | CONFIGURATION SECTION. | | SOURCE-COMPUTER. HP-3000. | | OBJECT-COMPUTER. HP-3000. | | SPECIAL-NAMES. CONSOLE IS TERMINAL-INPUT. | | | | INPUT-OUTPUT SECTION. | | | | FILE-CONTROL. | | SELECT CRT ASSIGN TO "$STDLIST". | | | | DATA DIVISION. | | | | FILE SECTION. | | FD CRT. | | 01 PROMPT PIC X(34). | | $PAGE | | 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 * * * * * * * | | | _________________________________________________________________________ Figure 2-5. Program COBEX2 __________________________________________________________________ | | | | | 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 FILLER PIC X(15) VALUE SPACES. | | | | 01 DOLLARS PIC $$$,$$$,$$$.99. | | $PAGE | | PROCEDURE DIVISION. | | | | A100-MAIN. | | | | 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 CRT. | | | | 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. | | | | | | | | | __________________________________________________________________ Figure 2-5. Program COBEX2 (page 2 of 6) _______________________________________________ | | | A200-CONNECT-DBENVIRONMENT. | | | | EXEC SQL | | WHENEVER SQLERROR | | GO TO S300-SERIOUS-ERROR | | END-EXEC. | | | | DISPLAY "Connect to PartsDBE". | | EXEC SQL CONNECT TO '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. | | $PAGE | | | _______________________________________________ Figure 2-5. Program COBEX2 (page 3 of 6) ____________________________________________________________ | | | B100-SELECT-DATA. | | | | MOVE SPACES TO RESPONSE. | | MOVE "Enter Part Number or '/' to STOP> " | | TO PROMPT. | | WRITE PROMPT AFTER ADVANCING 1 LINE. | | 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. | ____________________________________________________________ Figure 2-5. Program COBEX2 (page 4 of 6) _______________________________________________________ | | | 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. | | | | $PAGE | | 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. | | | | | _______________________________________________________ Figure 2-5. Program COBEX2 (page 5 of 6) ______________________________________________________________ | | | 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. | | | | | | | | | ______________________________________________________________ Figure 2-5. Program COBEX2 (page 6 of 6) Output File Attributes 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: :listftemp,2 TEMPORARY FILES FOR SOMEUSER.SOMEACCT,SOMEGRP ACCOUNT= SOMEACCT GROUP= SOMEGRP FILENAME CODE ------------LOGICAL RECORD----------- ----SPACE---- SIZE TYP EOF LIMIT R/B SECTORS #X MX SQLCONST 80B FA 39 2048 1 128 8 10 (TEMP) SQLMOD 250W FB 3 1023 1 208 2 10 (TEMP) SQLMSG 80B FA 14 1023 1 96 6 8 (TEMP) SQLOUT 80B FA 417 10000 1 320 11 10 (TEMP) SQLVAR 80B FA 11 2048 1 128 7 10 (TEMP) Modified Source File 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: * 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 SQLIN is in the same column, but on a different line in SQLOUT. In SQLOUT the period is on the line following the last line generated by the preprocessor for the INCLUDE SQLCA command. * Inserts two $INCLUDE COBOL compiler directives after the WORKING-STORAGE SECTION label. During compilation, the directives reference the include files: SQLCONST and SQLVAR. * 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 sentences providing conditional instructions following SQL commands encountered after one of 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 for execution at run time. Parameters used by these external calls are defined in SQLVAR and SQLCONST. * Inserts a "Start Inserted Statements" comment before generated information.
CAUTION Although you can access SQLOUT, SQLVAR, and SQLCONST 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 in SQLOUT, make the changes to SQLIN, re-preprocess SQLIN, and re-compile the output files before putting the application program into production. ____________________________________________________________________________ | | | * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *| | * 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 JULY 1987. | | DATE-COMPILED. 17 JULY 1987. | | REMARKS. SQL'S SELECT WITH WHENEVER COMMAND. | | | | ENVIRONMENT DIVISION. | | CONFIGURATION SECTION. | | SOURCE-COMPUTER. HP-3000. | | OBJECT-COMPUTER. HP-3000. | | SPECIAL-NAMES. CONSOLE IS TERMINAL-INPUT. | | | | INPUT-OUTPUT SECTION. | | | | FILE-CONTROL. | | SELECT CRT ASSIGN TO "$STDLIST". | | | | DATA DIVISION. | | | | FILE SECTION. | | FD CRT. | | 01 PROMPT PIC X(34). | | $PAGE | | WORKING-STORAGE SECTION. | | | | **** Start SQL Preprocessor ****\ | | $INCLUDE SQLCONST\ | | $INCLUDE SQLVAR\ | | **** 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). | ____________________________________________________________________________ Figure 2-6. Modified Source File for Program COBEX2 __________________________________________________________________________ | | | 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 FILLER PIC X(15) VALUE SPACES. | __________________________________________________________________________ Figure 2-6. Modified Sorce File for Program COBEX2 (page 2 of 9) ______________________________________________________________________ | | | 01 DOLLARS PIC $$$,$$$,$$$.99. | | $PAGE | | PROCEDURE DIVISION. | | | | A100-MAIN. | | | | 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 CRT. | | | | 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 PartsDBE". | | | | **** Start SQL Preprocessor ****\ | | * EXEC SQL CONNECT TO 'PartsDBE' END-EXEC\ | | **** Start Inserted Statements **** | ______________________________________________________________________ Figure 2-6. Modified Source File for Program COBEX2 (page 3 of 9) ____________________________________________________________________ | | | MOVE 264 TO SQLCONLEN\ | | CALL "SQLXCONO" USING 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 "SQLXCONO" USING 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 "SQLXCONO" USING SQLCA, SQLCONLEN, SQLCONST3\| | IF SQLCODE IS NEGATIVE\ | | GO TO S300-SERIOUS-ERROR\ | | END-IF\ | | **** End SQL Preprocessor **** | | | ____________________________________________________________________ Figure 2-6. Modified Source File for Program COBEX2 (page 4 of 9) ____________________________________________________________________ | | | | | | | | | A400-EXIT. | | EXIT. | | | | A500-TERMINATE-PROGRAM. | | | | | | | | | | **** Start SQL Preprocessor ****\ | | * EXEC SQL\ | | * RELEASE\ | | * END-EXEC\ | | **** Start Inserted Statements ****\ | | MOVE 56 TO SQLCONLEN\ | | CALL "SQLXCONO" USING SQLCA, SQLCONLEN, SQLCONST4\| | IF SQLCODE IS NEGATIVE\ | | GO TO S300-SERIOUS-ERROR\ | | END-IF\ | | **** End SQL Preprocessor **** | | . | | | | STOP RUN. | | | | A500-EXIT. | | EXIT. | | $PAGE | | B100-SELECT-DATA. | | | | MOVE SPACES TO RESPONSE. | | | | MOVE "Enter Part Number or '/' to STOP> " | | TO PROMPT. | | WRITE PROMPT AFTER ADVANCING 1 LINE. | | ACCEPT RESPONSE. | | | | IF RESPONSE-PREFIX = "/" | | MOVE "Y" TO DONE-FLAG | | GO TO B100-EXIT | | ELSE | | MOVE RESPONSE TO PARTNUMBER. | | | | | | | | | ____________________________________________________________________ Figure 2-6. Modified Source File for Program COBEX2 (page 5 of 9) _______________________________________________________________________ | | | **** 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 | | | | | _______________________________________________________________________ Figure 2-6. Modified Source File for Program COBEX2 (page 6 of 9) ______________________________________________________________________ | | | MOVE 1 TO SQLSECNUM\ | | MOVE 16 TO SQLINLEN\ | | MOVE 54 TO SQLOUTLEN\ | | CALL "SQLXFETO" USING 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. | ______________________________________________________________________ Figure 2-6. Modified Source File for Program (page 7 of 9) ___________________________________________________________________ | | | B200-EXIT. | | EXIT. | | $PAGE | | 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 "SQLXPLNO" USING 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. | ___________________________________________________________________ Figure 2-6. Modified Source File for Program COBEX2 (page 8 of 9) _________________________________________________________________________ | | | 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. | | | | | | | | | | | | | | | _________________________________________________________________________ Figure 2-6. Modified Source File for Program COBEX2 (page 9 of 9)


MPE/iX 5.0 Documentation