
Inline adoc files when they are included exactly once. Also fix language tags because this inlining gives us better information on what language the code is written in.
103 lines
2.3 KiB
Plaintext
103 lines
2.3 KiB
Plaintext
== Why is this an issue?
|
|
|
|
The number of columns in a ``++FETCH++`` statement should match the number actually selected in the relevant cursor. Use more columns in the ``++FETCH++`` than the cursor, and you've got a data problem, because the variables you expect to be updated by the cursor are never actually touched, and neither are their null indicators. Instead, they retain whatever value they had before the fetch. Meaning you're operating with bad data.
|
|
|
|
|
|
=== Noncompliant code example
|
|
|
|
[source,cobol]
|
|
----
|
|
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-COLUMN1-IND -- Noncompliant
|
|
,:H-COLUMN2 :H-COLUMN2-IND
|
|
,:H-COLUMN3 :H-COLUMN3-IND
|
|
,:H-COLUMN4 :H-COLUMN4-IND -- Not selected
|
|
,:H-COLUMN5 :H-COLUMN5-IND -- Not selected
|
|
----
|
|
|
|
|
|
=== Compliant solution
|
|
|
|
[source,cobol]
|
|
----
|
|
EXEC SQL
|
|
DECLARE C-SQL-CURSOR CURSOR
|
|
SELECT COLUMN1
|
|
,COLUMN2
|
|
,COLUMN3
|
|
,COLUMN4
|
|
,COLUMN5
|
|
FROM TBLWTABLE
|
|
WITH UR
|
|
END-EXEC.
|
|
|
|
…
|
|
|
|
EXEC SQL
|
|
FETCH C-SQL-CURSOR
|
|
INTO :H-COLUMN1 :H-COLUMN1-IND
|
|
,:H-COLUMN2 :H-COLUMN2-IND
|
|
,:H-COLUMN3 :H-COLUMN3-IND
|
|
,:H-COLUMN4 :H-COLUMN4-IND
|
|
,:H-COLUMN5 :H-COLUMN5-IND
|
|
----
|
|
or
|
|
|
|
[source,cobol]
|
|
----
|
|
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-COLUMN1-IND
|
|
,:H-COLUMN2 :H-COLUMN2-IND
|
|
,:H-COLUMN3 :H-COLUMN3-IND
|
|
----
|
|
|
|
|
|
ifdef::env-github,rspecator-view[]
|
|
|
|
'''
|
|
== Implementation Specification
|
|
(visible only on this page)
|
|
|
|
=== Message
|
|
|
|
Refactor this ``++FETCH++`` to select the same number of columns selected in "xxx".
|
|
|
|
|
|
=== Highlighting
|
|
|
|
* primary: ``++INTO++`` + column list in ``++FETCH++`` statement
|
|
* secondary: ``++SELECT++`` + column list in cursor
|
|
|
|
|
|
'''
|
|
== Comments And Links
|
|
(visible only on this page)
|
|
|
|
=== relates to: S4103
|
|
|
|
endif::env-github,rspecator-view[]
|