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-13
Selecting Rowsets With a Cursor
IF (SQLCODE != 0) {
printf("GET DIAGNOSTICS operation failed."
" SQLCODE = %ld\n", SQLCODE);
return(SQLCODE);
}
for (i = 0; i < numrows; i++) {
printf("Project Code = %s\t
Project Description = %s\t
Start Date = %s\n", hva_projcode[i],
hva_projdesc[i], hva_start_date[i]);
}
}
}
/* Close the cursor */
EXEC SQL
CLOSE rowset_cursor ;
...
EXEC SQL BEGIN DECLARE SECTION END-EXEC.
01 SQLCODE pic s9(9) comp.
01 numrows pic 9(9) comp.
01 rs.
02 ROWSET[200] hvaprojcode pic 9(4) comp.
02 ROWSET[200] hvaprojdesc pic x(18).
02 ROWSET[200] hvastartdate DATE.
EXEC SQL END DECLARE SECTION END-EXEC.
01 i pic s9(4) comp.
...
**** declare cursor for select operation ****
EXEC SQL
DECLARE rowset_cursor CURSOR FOR
SELECT projcode, projdesc, start_date
FROM persnl.project
WHERE start_date <= DATE '1998-12-01'
END-EXEC.
**** open the cursor ****
EXEC SQL
OPEN rowset_cursor
END-EXEC.
**** Fetch all rows from result table ****
Perform until sqlcode not equal 0
EXEC SQL FETCH rowset_cursor
INTO :hvaprojcode, :hvaprojdesc, :hvastartdate
END-EXEC.
if SQLCODE EQUAL 0
EXEC SQL GET DIAGNOSTICS :numrows = ROW_COUNT END-EXEC.
if SQLCODE NOT EQUAL 0
Display "GET DIAGNOSTICS operation failed."
end-if
Perform varying i from 1 by 1 until i > numrows
Display "ProjectCode = " hvaprojcode(i)
"Project Description = " hvaprojdesc(i)
"Start Date = " :hvastartdate(i)
end-perform.
end-if
end-perform.
**** Close the cursor ****
EXEC SQL
CLOSE rowset_cursor
END-EXEC.
...
COBOL