HP 3000 Manuals

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


ALLBASE/SQL Pascal Application Programming Guide

Preprocessor Input and Output 

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

   *   source file:  a file containing the Pascal ALLBASE/SQL program or
       subprogram with embedded SQL commands for one DBEnvironment.  The
       file must be a fixed length ASCII file, numbered or unnumbered.
       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 for 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 is
       available.

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

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

            SQLOUT

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

   *   include files:  include files containing definitions of constants,
       types, variables, and external procedures used by Pascal
       constructs the preprocessor inserts into SQLOUT. The formal file
       designators for these files are, respectively:

            SQLCONST
            SQLTYPE
            SQLVAR   (or SQLVARn for subprograms)
            SQLEXTN

   *   ALLBASE/SQL message file:  a file containing the preprocessor
       banner, 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 the source file is in a language other than ASCII, the modified source
file, and all generated files will have names in the native language and
extensions in ASCII.

	       Click here to view figure.
          Figure 2-3.  Pascal Preprocessor Input and Output 

	       Click here to view figure.
          Figure 2-4.  Compiling Preprocessor Output 

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 SQLTYPE 
            :RENAME SQLTYPE, TypeFile 
            :SAVE SQLEXTN 
            :RENAME SQLEXTN, ExtnFile 
            :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 section for more information.

Source File 

The source file must be a file that contains at a minimum the following
constructs:

     (* PROGRAM HEADING *)
     Program  ProgramName(input, output);

     begin
     AnyStatement;
     end.

When parsing the source file, the Pascal preprocessor ignores Pascal
statements and most Pascal compiler directives in it.  Only the following
information is parsed by the Pascal preprocessor:

   *   The Pascal compiler directives $Skip_Text ON$, $Skip_Text OFF$,
       $Set, $If, $Else, $Endif, and $Include.

   *   The program name.  Unless you specify a module name in the
       preprocessor invocation line, the preprocessor uses the program
       name as the name for the module it stores.  The name may
       optionally have the suffix .sql to distinguish it from non-SQL
       programs.  A module name can contain as many as 20 bytes and must
       follow the rules governing ALLBASE/SQL basic names (given in the
       ALLBASE/SQL Reference Manual ).

   *   Constructs found after prefix EXEC SQL. These constructs follow
       the rules given in the chapter, "Embedding SQL Commands," for how
       and where to embed these constructs.

   *   Constructs found between the BEGIN DECLARE SECTION and END DECLARE
       SECTION commands.  These commands delimit a declare section which
       contains Pascal data declarations for the host variables used in
       the program.  Both main and subprograms that contain SQL commands,
       regardless of whether or not they contain host variables, must
       include the BEGIN DECLARE SECTION and the END DECLARE SECTION
       commands in order to create the modified source code file, SQLOUT.
       Host variables are described in Chapter 4.

The runtime dialog for a sample program that selects and displays data is
shown in Figure 2-5.  Figure 2-6 illustrates an SQLIN file of the sample
program using the following SQL commands:

     INCLUDE SQLCA
     BEGIN DECLARE SECTION
     END DECLARE SECTION
     WHENEVER
     CONNECT
     BEGIN WORK
     SELECT
     COMMIT WORK
     SQLEXPLAIN

As the following interactive sample dialog 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 the user enters a slash (/) or a serious error is
encountered.
_______________________________________________________________________
|                                                                     |
|      :RUN PASEX2P                                                   |
|      Program to SELECT specified rows from the Parts Table - PASEX2 |
|                                                                     |
|      Event List:                                                    |
|       Connect to PartsDBE                                           |
|       Begin Work                                                    |
|       SELECT specified row 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 |
|                                                                     |
|      Begin Work                                                     |
|      SELECT PartNumber, PartName, SalesPrice                        |
|                                                                     |
|      Row not found!                                                 |
|      Commit Work                                                    |
|                                                                     |
|      Enter Part Number within Parts Table or "/" to STOP> 1323-D-01 |
|                                                                     |
|      Begin Work                                                     |
|      SELECT PartNumber, PartName, SalesPrice                        |
|                                                                     |
|      Part Number:  1323-D-01                                        |
|      Part Name:    Floppy Diskette Drive                            |
|      Sales Price:          200.00                                   |
|      Commit Work                                                    |
|                                                                     |
|      Enter Part Number within Parts Table or "/" to STOP> 1823-PT-01|
|                                                                     |
|      Begin Work                                                     |
|      SELECT PartNumber, PartName, SalesPrice                        |
|                                                                     |
|      Part Number:  1823-PT-01                                       |
|      Part Name:    Graphics Printer                                 |
|      Sales Price:          450.00                                   |
|      Commit Work                                                    |
|                                                                     |
|      Enter Part Number within Parts Table or "/" to STOP> /         |
|                                                                     |
|      Release PartsDBE                                               |
|                                                                     |
|      Terminating Program                                            |
|                                                                     |
_______________________________________________________________________

          Figure 2-5.  Interactive Runtime Dialog of Program PASEX2 
____________________________________________________________________________
|                                                                          |
|     $Heap_Dispose ON$                                                    |
|     $Heap_Compact ON$                                                    |
|     Standard_Level 'HP_Pascal$                                           |
|     (* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *)|
|     (* This program illustrates the use of SQL's SELECT command to     *)|
|     (* retrieve one row or tuple at a time.                            *)|
|     (* BEGIN WORK is executed before the SELECT and a COMMIT WORK      *)|
|     (* after the SELECT.  An indicator variable is also used for       *)|
|     (* SalesPrice.                                                     *)|
|     (* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *)|
|                                                                          |
|     Program pasex2(input, output);                                       |
|                                                                          |
|     label                                                                |
|         1000,                                                            |
|         9999;                                                            |
|                                                                          |
|     const                                                                |
|         OK           =      0;                                           |
|         NotFound     =    100;                                           |
|         DeadLock     = -14024;                                           |
|                                                                          |
|     var                                                                  |
|                                                                          |
|         EXEC SQL INCLUDE SQLCA;   (* SQL Communication Area *)           |
|                                                                          |
|               (* Begin Host Variable Declarations *)                     |
|         EXEC SQL  BEGIN DECLARE SECTION;                                 |
|         PartNumber       : packed array[1..16] of char;                  |
|         PartName         : packed array[1..30] of char;                  |
|         SalesPrice       : longreal;                                     |
|         SalesPriceInd    : SQLIND;                                       |
|         SQLMessage       : packed array[1..132] of char;                 |
|         EXEC SQL  END DECLARE SECTION;                                   |
|               (* End Host Variable Declarations *)                       |
|                                                                          |
|         Abort             : boolean;                                     |
|                                                                          |
|     procedure SQLStatusCheck;  (* Procedure to Display Error Messages *) |
|        Forward;                                                          |
|                                                                          |
|     (* Directive to set SQL Whenever error checking *)                   |
|                                                                          |
|     $PAGE $                                                              |
|                                                                          |
|     EXEC SQL WHENEVER SQLERROR GOTO 1000;                                |
____________________________________________________________________________

          Figure 2-6.  Program PASEX2:  Using Simple Select 
________________________________________________________________________
|                                                                      |
|     procedure ConnectDBE;  (* Procedure to Connect to PartsDBE *)    |
|     begin                                                            |
|                                                                      |
|     writeln('Connect to PartsDBE');                                  |
|     EXEC SQL CONNECT TO 'PartsDBE';                                  |
|                                                                      |
|     end;  (* End of ConnectDBE Procedure *)                          |
|                                                                      |
|                                                                      |
|     procedure BeginTransaction;  (* Procedure to Begin Work *)       |
|     begin                                                            |
|                                                                      |
|     writeln;                                                         |
|     writeln('Begin Work');                                           |
|     EXEC SQL BEGIN WORK;                                             |
|                                                                      |
|     end;  (* End BeginTransaction Procedure *)                       |
|                                                                      |
|                                                                      |
|     procedure EndTransaction;  (* Procedure to Commit Work *)        |
|     begin                                                            |
|                                                                      |
|                                                                      |
|     writeln('Commit Work');                                          |
|     EXEC SQL COMMIT WORK;                                            |
|                                                                      |
|     end;  (* End EndTransaction Procedure *)                         |
|                                                                      |
|                                                                      |
|     (* Directive to reset SQL Whenever error checking *)             |
|     EXEC SQL WHENEVER SQLERROR CONTINUE;                             |
|                                                                      |
|                                                                      |
|     procedure TerminateProgram;   (* Procedure to Release PartsDBE *)|
|     begin                                                            |
|                                                                      |
|     writeln('Release PartsDBE');                                     |
|     EXEC SQL COMMIT WORK RELEASE;                                    |
|                                                                      |
|     writeln;                                                         |
|     writeln('Terminating Program');                                  |
|     Goto 9999;  (* Goto exit point of main program *)                |
|                                                                      |
|     end;  (* End TerminateProgram Procedure *)                       |
|     $PAGE $                                                          |
|                                                                      |
|                                                                      |
________________________________________________________________________

          Figure 2-6.  Program PASEX2:  Using Simple Select (page 2 of 5) 
__________________________________________________________________________
|                                                                        |
|     procedure DisplayRow;   (* Procedure to Display Parts Table Rows *)|
|     begin                                                              |
|     writeln;                                                           |
|     writeln('Part Number: ', PartNumber);                              |
|     writeln('Part Name:   ', PartName);                                |
|     if SalesPriceInd < 0 then                                          |
|        writeln('Sales Price is NULL')                                  |
|     else                                                               |
|        writeln('Sales Price: ', SalesPrice:10:2);                      |
|                                                                        |
|     end;  (* End of DisplayRow *)                                      |
|                                                                        |
|     $PAGE $                                                            |
|                                                                        |
|     procedure SelectData; (* Procedure to Query Parts Table *)         |
|     begin                                                              |
|                                                                        |
|     repeat                                                             |
|                                                                        |
|     writeln;                                                           |
|     prompt('Enter Part Number within Parts Table or "/" to STOP> ');   |
|     readln(PartNumber);                                                |
|     writeln;                                                           |
|                                                                        |
|     if PartNumber[1] <> '/' then                                       |
|       begin                                                            |
|                                                                        |
|       BeginTransaction;                                                |
|                                                                        |
|       writeln('SELECT PartNumber, PartName, SalesPrice');              |
|       EXEC SQL SELECT PartNumber, PartName, SalesPrice                 |
|                 INTO :PartNumber,                                      |
|                      :PartName,                                        |
|                      :SalesPrice  :SalesPriceInd                       |
|                  FROM PurchDB.Parts                                    |
|                 WHERE PartNumber = :PartNumber;                        |
|                                                                        |
|       if SQLCA.SQLWARN[0] in ['W','w'] then                            |
|          begin                                                         |
|          write('SQL WARNING has occurred. The following row');         |
|          writeln('of data may not be valid.');                         |
|          end;                                                          |
|                                                                        |
|                                                                        |
|                                                                        |
|                                                                        |
__________________________________________________________________________

          Figure 2-6.  Program PASEX2:  Using Simple Select (page 3 of 5) 
___________________________________________________________________________
|                                                                         |
|       case SQLCA.SQLCODE of                                             |
|       OK           : DisplayRow;                                        |
|       NotFound     : begin                                              |
|                        writeln;                                         |
|                        writeln('Row not found!');                       |
|                      end;                                               |
|       otherwise      begin                                              |
|                        SQLStatusCheck;                                  |
|                        end;                                             |
|                                                                         |
|       end;  (* case *)                                                  |
|                                                                         |
|       EndTransaction;                                                   |
|                                                                         |
|     end;  (* End if *)                                                  |
|     until PartNumber[1] = '/';                                          |
|                                                                         |
|     end;      (* End of SelectData Procedure *)                         |
|                                                                         |
|     procedure SQLStatusCheck;  (* Procedure to Display Error Messages *)|
|     begin                                                               |
|                                                                         |
|     Abort := FALSE;                                                     |
|     if SQLCA.SQLCODE < DeadLock then Abort := TRUE;                     |
|                                                                         |
|     repeat                                                              |
|     EXEC SQL SQLEXPLAIN :SQLMessage;                                    |
|     writeln(SQLMessage);                                                |
|     until SQLCA.SQLCODE = 0;                                            |
|                                                                         |
|     if Abort then                                                       |
|       begin                                                             |
|                                                                         |
|       TerminateProgram;                                                 |
|                                                                         |
|       end;                                                              |
|                                                                         |
|     end;  (* End SQLStatusCheck Procedure *)                            |
|     $PAGE $                                                             |
|                                                                         |
|                                                                         |
|                                                                         |
|                                                                         |
|                                                                         |
|                                                                         |
|                                                                         |
|                                                                         |
___________________________________________________________________________

          Figure 2-6.  Program PASEX2:  Using Simple Select (page 4 of 5) 
__________________________________________________________
|                                                        |
|     begin  (* Beginning of Program *)                  |
|                                                        |
|     write('Program to SELECT specified rows from ');   |
|     writeln('the Parts Table - PASEX2');               |
|     writeln;                                           |
|     writeln('Event List:');                            |
|     writeln('  Connect to PartsDBE');                  |
|     writeln('  Begin Work');                           |
|     writeln('  SELECT specified row from Parts Table');|
|     writeln('   until user enters "/" ');              |
|     writeln('  Commit Work');                          |
|     writeln('  Disconnect from PartsDBE');             |
|     writeln;                                           |
|                                                        |
|     ConnectDBE;                                        |
|     SelectData;                                        |
|     TerminateProgram;                                  |
|                                                        |
|     (* Whenever Routine - Serious DBE Error *)         |
|     (* SQL Whenever SQLError Entry Point *)            |
|     1000:                                              |
|                                                        |
|       (* Begin *)                                      |
|       SQLStatusCheck;                                  |
|       TerminateProgram;                                |
|       (* End *)                                        |
|                                                        |
|     (* Exit Point for the main program *)              |
|     9999:                                              |
|                                                        |
|     end.   (* End of Program *)                        |
|                                                        |
|                                                        |
|                                                        |
|                                                        |
|                                                        |
|                                                        |
|                                                        |
|                                                        |
|                                                        |
|                                                        |
|                                                        |
|                                                        |
|                                                        |
|                                                        |
|                                                        |
|                                                        |
|                                                        |
__________________________________________________________

          Figure 2-6.  Program PASEX2:  Using Simple Select (page 5 of 5) 

Output File Attributes 

The Pascal preprocessor output files are temporary files.  When the SQLIN
illustrated in Figure 2-6 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           3       2048  16      256  1  8 (TEMP)
     SQLEXTN            80B  FA         135       2048  16      256 26  8 (TEMP)
     SQLMOD            250W  FB           3       1023   1      304 10  8 (TEMP)
     SQLMSG             80B  FA          23       1023  16      128  1  8 (TEMP)
     SQLOUT             80B  FA         308      10000  16      256 32  8 (TEMP)
     SQLTYPE            80B  FA          61       2048  16      256 26  8 (TEMP)
     SQLVAR             80B  FA           7       2048  16      256 26  8 (TEMP)

     :

Preprocessor Modified Source File 

As the Pascal preprocessor parses the source file (SQLIN), it copies
lines from the source file and any file(s) included from it into the
modified source file (SQLOUT), comments out embedded SQL commands, and
inserts information around each embedded SQL command.

In both preprocessing modes, the Pascal preprocessor:

   *   Inserts a $Skip_Text ON$ and a $Skip_Text OFF$ compiler directive
       around the embedded SQL command to comment out the SQL command.

   *   Inserts $INCLUDE Pascal compiler directives within the declaration
       section.  These directives reference the four preprocessor
       generated include files:  SQLCONST, SQLTYPE, SQLVAR, and SQLEXTN.
       SQLCONST and SQLTYPE are included after the program header.
       SQLVAR and SQLEXTN are included at the end of the global
       declaration part of a main program.

   *   Keeps comments that follow an embedded command.  These comments
       appear after the preprocessor generated code associated with the
       command.  Note, for example, that the comment 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 full preprocessing mode, the preprocessor also:

   *   Generates a Pascal declaration for the SQLCA and the SQLDA in the
       SQLTYPE include file.

   *   Generates Pascal statements providing conditional instructions
       following SQL commands encountered after one of the following SQL
       commands:  WHENEVER SQLERROR, WHENEVER SQLWARNING, and WHENEVER
       NOT FOUND.

   *   Generates Pascal statements 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, SQLCONST, and SQLTYPE.


CAUTION Although you can access SQLOUT, SQLVAR, SQLVARn, SQLTYPE, SQLCONST, and SQLEXTN files with an editor, you should never change the information generated by the Pascal preprocessor. Your DBEnvironment could be damaged at run time if preprocessor-generated constructs are altered.
If you change non-preprocessor-generated constructs in SQLOUT, make the changes to SQLIN, re-preprocess SQLIN, and re-compile the output files before putting the application program into production. The following modified source file is the result of preprocessing program pasex2 (shown previously). In the listing, the boundaries of code that has been changed or added by the preprocessor is shaded for easy reference. ____________________________________________________________________________ | | | $set 'XOPEN_SQLCA=false'$ | | $Heap_Dispose ON$ | | $Heap_Compact ON$ | | $Standard_Level 'HP_Pascal'$ | | (* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *)| | (* This program illustrates the use of SQL's SELECT command to *)| | (* retrieve one row or tuple at a time. *)| | (* BEGIN WORK is executed before the SELECT and a COMMIT WORK *)| | (* after the SELECT. An indicator variable is also used for *)| | (* SalesPrice. *)| | (* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *)| | Program pasex2(input, output); | | | | label | | 1000, | | 9999; | | | | $include 'sqlconst'$ | | $include 'sqltype'$ | | const | | OK = 0; | | NotFound = 100; | | DeadLock = -14024; | | | | var | | | | $SKIP_TEXT ON$ | | EXEC SQL INCLUDE SQLCA; | | $SKIP_TEXT OFF$ | | SQLCA : SQLCA_TYPE; | | | | | | (* Begin Host Variable Declarations *) | | | | $SKIP_TEXT ON$ | | EXEC SQL Begin Declare Section; | | $SKIP_TEXT OFF$ | | | | PartNumber : packed array[1..16] of char; | | PartName : packed array[1..30] of char; | | SalesPrice : longreal; | | SalesPriceInd : SQLIND; | | SQLMessage : packed array[1..132] of char; | | | | $SKIP_TEXT ON$ | | EXEC SQL End Declare Section; | | $SKIP_TEXT OFF$ | | | ____________________________________________________________________________ Figure 2-7. Modified Source File for Program PASEX2 ________________________________________________________________________________ | | | (* End Host Variable Declarations *) | | | | Abort : boolean; | | | | $include 'sqlvar'$ | | $include 'sqlextn'$ | | procedure SQLStatusCheck; (* Procedure to Display Error Messages *) | | Forward; | | | | $PAGE $ | | | | (* Directive to set SQL Whenever error checking *) | | | | | | $SKIP_TEXT ON$ | | EXEC SQL Whenever SqlError goto 1000; | | $SKIP_TEXT OFF$ | | | | | | Procedure ConnectDBE; (* Procedure to Connect to PartsDBE *) | | begin | | | | writeln('Connect to PartsDBE'); | | | | $SKIP_TEXT ON$ | | EXEC SQL CONNECT TO 'PartsDBE'; | | $SKIP_TEXT OFF$ | | begin | | SQLVAR1 := '00AE00005061727473444245202020202020202020202020202020202020'| | '202020202020202020202020202020202020202020202020202020202020' | | '202020202020202020202020202020202020202020202020202020202020' | | '202020202020202020202020202020202020202020202020202020202020' | | '202020202020202020202020'; | | SQLXCON(waddress(SQLCA), SQLVAR1); | | if SQLCA.SQLCODE < 0 then | | goto 1000; | | end; | | | | end; (* End of ConnectDBE Procedure *) | | | | | | Procedure BeginTransaction; (* Procedure to Begin Work *) | | begin | | | | writeln; | | writeln('Begin Work'); | ________________________________________________________________________________ Figure 2-7. Modified Source File for Program PASEX2 (page 2 of 7) ________________________________________________________________________ | | | $SKIP_TEXT ON$ | | EXEC SQL BEGIN WORK; | | $SKIP_TEXT OFF$ | | begin | | SQLVAR2 := '00A6007F00110061'; | | SQLXCON(waddress(SQLCA), SQLVAR2); | | if SQLCA.SQLCODE < 0 then | | goto 1000; | | end; | | end; (* End BeginTransaction Procedure *) | | | | procedure EndTransaction; (* Procedure to Commit Work *) | | begin | | | | writeln('Commit Work'); | | | | $SKIP_TEXT ON$ | | EXEC SQL COMMIT WORK; | | $SKIP_TEXT OFF$ | | begin | | SQLVAR3 := '00A10000'; | | SQLXCON(waddress(SQLCA), SQLVAR3); | | if SQLCA.SQLCODE < 0 then | | goto 1000; | | end; | | end; (* End EndTransaction Procedure *) | | | | (* Directive to reset SQL Whenever error checking *) | | | | $SKIP_TEXT ON$ | | EXEC SQL WHENEVER SQLERROR CONTINUE; | | $SKIP_TEXT OFF$ | | | | procedure TerminateProgram; (* Procedure to Release PartsDBE *)| | begin | | | | writeln('Release PartsDBE'); | | | | $SKIP_TEXT ON$ | | EXEC SQL COMMIT WORK RELEASE; | | $SKIP_TEXT OFF$ | | begin | | begin | | SQLVAR4 := '00A10000'; | | SQLXCON(waddress(SQLCA), SQLVAR4); | | end; | ________________________________________________________________________ Figure 2-7. Modified Source File for Program PASEX2 (page 3 of 7) _____________________________________________________________________________ | | | begin | | SQLVAR5 := '00B200002020202020202020202020202020202020202020FFFFFFFF';| | SQLXCON(waddress(SQLCA), SQLVAR5); | | end; | | end; | | | | | | writeln; | | writeln('Terminating Program'); | | Goto 9999; (* Goto exit point of main program *) | | | | end; (* End TerminateProgram Procedure *) | | $PAGE $ | | | | | | procedure DisplayRow; (* Procedure to Display Parts Table Rows *) | | begin | | | | writeln; | | writeln('Part Number: ', PartNumber); | | writeln('Part Name: ', PartName); | | if SalesPriceInd < 0 then | | writeln('Sales Price is NULL') | | else | | writeln('Sales Price: ', SalesPrice:10:2); | | | | end; (* End of DisplayRow *) | | $PAGE $ | | | | procedure SelectData; (* Procedure to Query Parts Table *) | | begin | | | | repeat | | | | writeln; | | prompt('Enter Part Number within Parts Table or "/" to STOP> '); | | readln(PartNumber); | | writeln; | | | | if PartNumber[1] | | '/' then | | begin | | | | BeginTransaction; | | | | writeln('SELECT PartNumber, PartName, SalesPrice'); | | | _____________________________________________________________________________ Figure 2-7. Modified Source File for Program PASEX2 (page 4 of 7) ________________________________________________________________________ | | | $SKIP_TEXT ON$ | | EXEC SQL SELECT PartNumber, PartName, SalesPrice | | INTO :PartNumber, | | :PartName, | | :SalesPrice :SalesPriceInd | | FROM PurchDB.Parts | | WHERE PartNumber = :PartNumber; | | $SKIP_TEXT OFF$ | | begin | | SQLTEMPV.REC1.PartNumber1 := PartNumber; | | SQLXFET(waddress(SQLCA),SQLOWNER,SQLMODNAME,1,waddress(SQLTEMPV),| | 16,64,TRUE); | | if SQLCA.SQLCODE = 0 then | | begin | | PartNumber := SQLTEMPV.REC2.PartNumber1; | | PartName := SQLTEMPV.REC2.PartName2; | | if SQLTEMPV.REC2.SalesPriceInd4 >= 0 then | | SalesPrice := SQLTEMPV.REC2.SalesPrice3; | | SalesPriceInd := SQLTEMPV.REC2.SalesPriceInd4; | | end | | else | | begin | | end; | | end; | | | | if SQLCA.SQLWARN[0] in ['W','w'] then | | begin | | write('SQL WARNING has occurred. The following row'); | | writeln('of data may not be valid.'); | | end; | | | | case SQLCA.SQLCODE of | | OK : DisplayRow; | | NotFound : begin | | writeln; | | writeln('Row not found!'); | | end; | | otherwise begin | | SQLStatusCheck; | | end; | | | | end; (* case *) | | | | EndTransaction; | | | | end; (* End if *) | | until PartNumber[1] = '/'; | | end; (* End of SelectData Procedure *) | ________________________________________________________________________ Figure 2-7. Modified Source File for Program PASEX2 (page 5 of 7) ___________________________________________________________________________ | | | procedure SQLStatusCheck; (* Procedure to Display Error Messages *)| | begin | | | | Abort := FALSE; | | if SQLCA.SQLCODE < DeadLock then Abort := TRUE; | | | | repeat | | | | $SKIP_TEXT ON$ | | EXEC SQL SQLEXPLAIN :SQLMessage; | | $SKIP_TEXT OFF$ | | begin | | SQLXPLN(waddress(SQLCA),waddress(SQLTEMPV.REC4),132,0); | | SQLMessage := ''; | | strmove(132,SQLTEMPV.REC4,1,SQLMessage, 1); | | end; | | | | writeln(SQLMessage); | | until SQLCA.SQLCODE = 0; | | | | if Abort then | | begin | | TerminateProgram; | | end; | | | | end; (* End SQLStatusCheck Procedure *) | | $PAGE $ | | | | begin (* Beginning of Program *) | | | | write('Program to SELECT specified rows from '); | | writeln('the Parts Table - PASEX2'); | | writeln; | | writeln('Event List:'); | | writeln(' Connect to PartsDBE'); | | writeln(' Begin Work'); | | writeln(' SELECT specified row from Parts Table'); | | writeln(' until user enters "/" '); | | writeln(' Commit Work'); | | writeln(' Disconnect from PartsDBE'); | | writeln; | | | | ConnectDBE; | | SelectData; | | TerminateProgram; | | | | (* Whenever Routine - Serious DBE Error *) | | (* SQL Whenever SQLError Entry Point *) | ___________________________________________________________________________ Figure 2-7. Modified Source File for Program PASEX2 (page 6 of 7) ____________________________________________ | | | 1000: | | | | (* Begin *) | | SQLStatusCheck; | | TerminateProgram; | | (* End *) | | | | (* Exit Point for the main program *)| | 9999: | | | | end. (* End of Program *) | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | ____________________________________________ Figure 2-7. Modified Source File for Program PASEX2 (page 7 of 7)


MPE/iX 5.0 Documentation