SQL Programming Manual for Pascal
HP NonStop SQL Programming Manual for Pascal—528614-001
B-1
B
Examples of Static NonStop SQL 
Programs
This appendix provides these static NonStop SQL programming examples:
•
Insertion program
•
Date-time program
For the NonStop SQL sample database used with these examples, see Appendix A.
Insertion Program
The insertion program on the following pages uses static SQL statements. The 
program inserts a part name, part number, and quantity into the PARTS table and then 
inserts a new part into the PARTLOC table. For database consistency, the program 
reads the SUPPLIER table to determine whether the supplier of the part is a record in 
the table. The program reads the SUPPLIER table with a cursor, locking the row in the 
table. Then the program inserts a row in the PARTLOC and PARTS tables before 
committing the transaction.
The program uses values supplied by initializing variables. It performs error processing 
by displaying the SQLCODE value (without the SQLCA structure).
The program uses DEFINEs for the table names and the =_DEFAULTS DEFINE for 
the default catalog in which the SQL compiler registers the program file. The DEFINE 
commands in effect for this program are:
SET DEFMODE ON
ALTER DEFINE =_DEFAULTS, CATALOG \SYS1.$VOL1.INVENT
SET DEFINE CLASS MAP
ADD DEFINE =PARTS, FILE \SYS1.$VOL1.SALES.PARTS
ADD DEFINE =SUPPLIER, FILE \SYS1.$VOL1.INVENT.SUPPLIER
ADD DEFINE =PARTLOC, FILE \SYS1.$VOL1.INVENT.PARTLOC
The run command and output for this program are as follows:
RUN command:
RUN POBJ
OUTPUT:
START PROGRAM NEWPART ******
SUPPLIER IS MAGNETICS CORP
BEGIN INSERT ON PARTLOC **********
BEGIN INSERT ON PARTS ************
COMMIT TRANSACTION
PART ADDED. PROGRAM ENDS










