SQL Programming Manual for Pascal

Examples of Static NonStop SQL Programs
HP NonStop SQL Programming Manual for Pascal528614-001
B-6
Date-Time Program
Date-Time Program
The date-time program uses a table named PROJECTS, which is not a part of the
sample database. The program therefore includes comments describing the columns
of the table.
The program can perform three functions:
1. Insert a new project name, start date, end date, and wait time.
2. Add more wait time to a project by updating the WAIT_TIME column of the
PROJECTS table. The original dates in the START_DATE and END_DATE
columns of the PROJECTS table remain unchanged.
3. Print a report showing the original dates and the new dates. The report function
computes the new dates by adding wait time to both the start date and end date.
The program also illustrates the following error handling techniques:
Using a temporary variable to save the value in SQLCODE within an error handling
routine; this allows the program to use the SQLCODE value after handling the
error
Temporarily disabling WHENEVER SQLERROR checking to avoid a possible
infinite loop if an error should occur in the error handling routine
Temporarily disabling WHENEVER NOT FOUND checking for a cursor FETCH
Using the value in SQLCODE to make processing decisions and to make
operations conditional upon the absence of errors
A DEFINE command identifies the PROJECTS table:
SET DEFMODE ON
SET DEFINE CLASS MAP
ADD DEFINE =PROJECTS, FILE \SYS1.$VOL1.SALES.PROJECTS
A sample run of the program in Figure B-1 on page B-7 shows input to the program
and output from the program. Data the user enters is shown in bold. The figure also
includes SQLCI sessions displaying the contents of the PROJECTS table before and
after the program updates the table.
210 0 BEGIN {* Main program *}
211 1 START_OPERATIONS;
212 1 CHECK_SUPPLIER;
213 1 DO_ADD_TO_PARTS (IN_DATA_REC);
214 1 DO_ADD_TO_PARTLOC (IN_DATA_REC);
215 1 CLOSE_CURSOR;
216 1 COMMIT_TRANSACTION;
217 1 SUCCESSFUL_COMPLETION;
218 1 END. {* Main program *}