SQL/MP Programming Manual for COBOL

HP NonStop SQL/MP Programming Manual for COBOL529758-003
3-1
3
SQL/MP Statements and Directives
This section describes NonStop SQL/MP statements and directives you can embed in
a COBOL program. For a detailed description, including the syntax, of all SQL
statements and directives, see the SQL/MP Reference Manual.
Topics include:
Embedding SQL Statements
Finding Information on page 3-3
Embedding SQL Statements
Use this syntax to embed an SQL statement or directive in a COBOL source file:
sql-statement-or-directive
is any SQL statement or directive shown in Table 3-1, NonStop SQL/MP
Statements and Directives, on page 3-3. The statement or directive must begin
with the keywords EXEC SQL and end with END-EXEC. The EXEC SQL keywords
do not require a hyphen or period, but the END-EXEC keywords require both the
hyphen and period. (However, a period after the END-EXEC keywords after the
BEGIN DECLARE SECTION or END DECLARE SECTION directive is ignored.)
Coding SQL Statements and Directives
In general, handle embedded SQL statements and directives as if they were COBOL
statements. Follow the same formatting and line continuation conventions for SQL
statements as you use for COBOL statements. Here are a some specific guidelines to
follow when you embed SQL statements and directives in a COBOL program:
Code an SQL statement or directive on a single source code line or over several
lines:
EXEC SQL WHENEVER SQLERROR PERFORM :HANDLE-ERROR END-EXEC.
EXEC SQL DROP TABLE \NY.$DISK1.INVENT.SUPPLIER END-EXEC.
EXEC SQL
SELECT CUSTOMER.CUSTNAME
INTO :CUSTOMER.CUSTNAME
FROM =CUSTOMER
WHERE CUSTNUM = :FIND_THIS_CUSTOMER
END-EXEC.
Do not nest SQL statements or directives.
EXEC SQL sql-statement-or-directive END-EXEC.