SQL/MX Programming Manual for C and COBOL (G06.24+, H06.03+)
Static Rowsets
HP NonStop SQL/MX Programming Manual for C and COBOL—523627-004
7-11
Selecting Rows Into Rowset Arrays
Example
This example selects the EMPNUM and SALARY columns of all rows in the 
EMPLOYEE table where the (JOBCODE, DEPTNUM) value is equal to one of the set 
of values in the hva_jobcode and hva_deptnum host variable arrays. An input 
value set is composed of array elements from the hva_jobcode and hva_deptnum 
host variable arrays with identical index numbers. Five input value sets exist, and the 
SELECT statement is executed for each matching input value set: 
EXEC SQL BEGIN DECLARE SECTION; 
 char SQLSTATE[6];
 ROWSET[5] unsigned NUMERIC (4) hva_jobcode; 
 ROWSET[5] unsigned NUMERIC (4) hva_deptnum; 
 ROWSET [100] unsigned NUMERIC (4) hva_empnum; 
 ROWSET [100] unsigned NUMERIC (8,2) hva_salary; 
 ROWSET [100] short hva_salary_indicator; 
 ...
 long numrows;
EXEC SQL END DECLARE SECTION; 
...
/* Populate the jobcode and deptnum rowsets in some way. */
hva_jobcode[0] = 100;
hva_deptnum[0] = 9000;
hva_jobcode[1] = 200;
hva_deptnum[1] = 9000;
hva_jobcode[2] = 300;
hva_deptnum[2] = 1000;
hva_jobcode[3] = 400;
hva_deptnum[3] = 1000;
hva_jobcode[4] = 500;
hva_deptnum[4] = 3000;
...
EXEC SQL 
 SELECT empnum, salary 
 INTO :hva_empnum, 
 :hva_salary INDICATOR :hva_salary_indicator 
 FROM persnl.employee 
 WHERE jobcode = :hva_jobcode AND deptnum = :hva_deptnum;
 ...
EXEC SQL BEGIN DECLARE SECTION END-EXEC.
 01 sqlstate pic x(5).
 01 numrows pic 9(9) comp.
 01 rs.
 02 ROWSET[5] hvajobcode pic 9(4) comp.
 02 ROWSET[5] hvadeptnum pic 9(4) comp.
 02 ROWSET[100] hvaempnum pic 9(4) comp.
 02 ROWSET[100] hvasalary pic 9(8)v9(2) comp.
 02 ROWSET[100] hvasalaryindicator pic s9(4) comp.
EXEC SQL END DECLARE SECTION END-EXEC.
 ...
**** populate the jobcode and deptnum rowsets in some way *****
Move 100 TO hvajobcode(1)
Move 9000 TO hvadeptnum(1)
Move 200 TO hvajobcode(2)
C
COBOL










