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-16
Inserting Rows From Rowset Arrays
ROWSET [100] unsigned NUMERIC (4) hva_salary;
ROWSET [100] short hva_salary_indicator;
...
EXEC SQL END DECLARE SECTION;
long i;
...
/* Populate the host variable arrays in some way. */
...
/* Store -1 in the indicator array for the first 50 input
values. */
for (i = 0; i < 50; i++) hva_salary_indicator[i] = -1;
/* Store 0 in the indicator array for the next 50 input values.
It is assumed that there are valid values for salary in the
hva_salary rowset array from element no. 50 up to element no. 99
*/
for (i = 50; i < 100; i++) hva_salary_indicator[i] = 0;
EXEC SQL
INSERT INTO persnl.employee
VALUES ( :hva_empnum,:hva_first_name,
:hva_last_name,:hva_deptnum,:hva_jobcode,
:hva_salary INDICATOR :hva_salary_indicator);
...
EXEC SQL BEGIN DECLARE SECTION END-EXEC.
01 sqlstate pic x(5).
01 rs.
02 ROWSET[100] hvaempnum pic 9(4) comp.
02 ROWSET[100] hvafirstname pic x(15).
02 ROWSET[100] hvalastname pic x(20).
02 ROWSET[100] hvadeptnum pic 9(4) comp.
02 ROWSET[100] hvajobcode pic 9(4) comp.
02 ROWSET[100] hvasalary pic 9(4) comp.
02 ROWSET[100] hvasalaryindicator pic s9(4) comp.
EXEC SQL END DECLARE SECTION END-EXEC.
01 i pic s9(4) comp.
...
**** Populate the host variables arrays in some way ****
**** Store -1 in the indicator array for the first 50 ****
**** input values. ****
PERFORM VARYING i FROM 1 BY 1 UNTIL i = 50
Move -1 to hvasalaryindicator(i)
end-perform.
**** Store 0 in the indicator array for the next 50 ****
**** input values. It is assumed that there are valid****
**** values for salary in the hvasalary rowset array ****
**** from element no. 51 upto element no. 100 ****
PERFORM VARYING i FROM 51 BY 1 UNTIL i = 100
Move 0 to hvasalaryindicator(i)
end-perform.
EXEC SQL
COBOL