There’s no point in selecting columns in a cursor that aren’t actually referenced in the relevant FETCH
statement. Instead, either
pare down the cursor to select only what you actually need, or FETCH
the other columns.
Noncompliant code example
EXEC SQL
DECLARE C-SQL-CURSOR CURSOR
SELECT COLUMN1
,COLUMN2 -- Not fetched
,COLUMN3 -- Not fetched
FROM TBLWTABLE
WITH UR
END-EXEC.
…
EXEC SQL
FETCH C-SQL-CURSOR -- Noncompliant
INTO :H-COLUMN1
END-EXEC
Compliant solution
EXEC SQL
DECLARE C-SQL-CURSOR CURSOR
SELECT COLUMN1
,COLUMN2
,COLUMN3
FROM TBLWTABLE
WITH UR
END-EXEC.
…
EXEC SQL
FETCH C-SQL-CURSOR
INTO :H-COLUMN1, :H-COLUMN2, :H-COLUMN3
END-EXEC
or
EXEC SQL
DECLARE C-SQL-CURSOR CURSOR
SELECT COLUMN1
FROM TBLWTABLE
WITH UR
END-EXEC.
…
EXEC SQL
FETCH C-SQL-CURSOR
INTO :H-COLUMN1
END-EXEC