Introduction to Data Management

Accessing Databases With NonStop SQL
15873 Tandem Computers Incorporated 3-19
Your programs combine statements in a host language (COBOL85, Pascal, or C) with
statements in SQL to manage the database. A portion of a program, with COBOL85 as
the host language and SQL statements highlighted within the listing, appears in
Figure 3-10. In this program, the NonStop SQL statements in the Data Division
declare the host variables NEWPRICE and PARTNAME. In the Procedure Division, a
single NonStop SQL statement increases the value of PRICE by 6% for all HARD DISK
products, using only a single disk access.
In your programs, you precede each embedded SQL statement with the keywords
EXEC SQL. You terminate the SQL statement with a language-dependent terminator.
These delimiters distinguish the SQL statement from the surrounding host-language
code.
By retrieving an entire set of records, rather than by reading and processing one
record at a time, a single NonStop SQL statement can replace many lines of host-
language code.
Figure 3-10. COBOL85 Source Code with SQL Statements Embedded
DATA DIVISION.
WORKING-STORAGE SECTION.
EXEC SQL BEGIN DECLARE SECTION END-EXEC.
01 NEWPRICE PIC S9(6)V9(2) COMP.
01 PARTNAME PIC X(11).
EXEC SQL END DECLARE SECTION END-EXEC.
...
PROCEDURE DIVISION.
550-UPDATE-INV-PRICE.
MOVE 1.06 TO NEWPRICE.
MOVE "%HARD DISK%" TO PARTNAME.
EXEC SQL UPDATE PARTS
SET PRICE = PRICE * :NEWPRICE
WHERE PARTDESC LIKE :PARTNAME
END-EXEC.
Programming for a PATHWAY Environment
If your application processes online transactions, you will probably write your
programs as servers that run in a PATHWAY environment, as shown in Figure 3-11.
The server program receives and replies to messages from the requester and
manipulates the database. You write the code to retrieve the requested data or to
change the database, write the SQL statements to process the request, and write the
reply to the requester. Fault tolerant applications are achieved through the support of
PATHWAY and TMF. More about the PATHWAY environment appears in Sections 5
and 6.