SQL/MX Programming Manual for C and COBOL (G06.24+, H06.03+)

Introduction
HP NonStop SQL/MX Programming Manual for C and COBOL523627-004
1-3
Declaring Host Variables
Declaring Host Variables
Declare host variables in a Declare Section in the variable declarations part of your
program. A Declare Section begins with BEGIN DECLARE SECTION and ends with
END DECLARE SECTION.
Example
In this example, hv_this_customer and hv_custname are host variables:
EXEC SQL BEGIN DECLARE SECTION;
unsigned NUMERIC (4) hv_this_customer; /* host variables */
char hv_custname[19];
EXEC SQL END DECLARE SECTION;
In this example, HV_THIS_CUSTOMER and HV_CUSTNAME are host variables:
EXEC SQL BEGIN DECLARE SECTION END-EXEC.
01 HV-THIS-CUSTOMER PIC 9(4) COMP.
01 HV-CUSTNAME PIC X(18).
EXEC SQL END DECLARE SECTION END-EXEC.
Using Host Variables
When you specify a host variable in an SQL statement, you must precede the host
variable name with a colon (:). In a 3GL statement, you do not need the colon.
This example shows a host variable in an embedded SQL statement:
Example
EXEC SQL SELECT custname
INTO :hv_custname
FROM customer
WHERE custnum = :hv_this_customer;
...
strcpy(new_name, hv_custname);
The host variable hv_custname is preceded by a colon (:) in the SQL statement. In
the strcpy function call, hv_custname is not preceded by a colon.
EXEC SQL SELECT custname
INTO :HV-CUSTNAME
FROM customer
WHERE custnum = :HV-THIS-CUSTOMER
END-EXEC.
...
MOVE HV-CUSTNAME TO NEW-NAME.
The host variable HV-CUSTNAME is preceded by a colon (:) in the SQL statement. In
the MOVE statement, HV-CUSTNAME is not preceded by a colon.
See Section 3, Host Variables in C/C++ Programs, and Section 4, Host Variables in
COBOL Programs.
C
COBOL
C
COBOL