Avoid Programs having cursors that doesn't contain the "FOR UPDATE" clause and not containing the "FOR READ ONLY" or "FOR FETCH ONLY" clause (PL1) | CAST Appmarq

Avoid Programs having cursors that doesn't contain the "FOR UPDATE" clause and not containing the "FOR READ ONLY" or "FOR FETCH ONLY" clause (PL1)


Rule Definition
While FOR UPDATE forces a certain access path, FOR FETCH ONLY provides more opportunities to the optimizer to choose the most efficient access path.

Remediation
Add one of the three clause : "FOR UPDATE" or "FOR READ ONLY" or FORFETCH ONLY". If you specify FOR FETCH ONLY, then DB2 does not need to know the current position of your cursor on the base table, because you are not going to update qualifying rows. Therefore, a more efficient access path for read-only cursors may be available to the optimizer. In order to get the benefit of lock avoidance, it is important to code cursors unambiguously. This is especially true for dynamic SQL. Coding a cursor unambiguously means explicitly specifying either FOR FETCH ONLY for read-only cursors or FOR UPDATE for cursors whose data will be used to perform subsequent updates.

Violation Code Sample
DCL     SYSPRINT FILE  STREAM OUTPUT PRINT;
DCL     FTEST1   FILE  RECORD INPUT;       
DCL     FTEST2   FILE  RECORD INPUT;       
DCL     FTEST3  FILE  RECORD OUTPUT;      
ON ENDF (FTEST1) EOF_FTEST1 = ON;
Fixed Code Sample
DCL     SYSPRINT FILE  STREAM OUTPUT PRINT;
DCL     FTEST1   FILE  RECORD INPUT;       
DCL     FTEST2   FILE  RECORD INPUT;       
DCL     FTEST3  FILE  RECORD OUTPUT;      
ON ENDF (FTEST1) EOF_FTEST1 = ON;  
ON ENDF (FTEST2) EOF_FTEST2 = ON;

Related Technologies

Health Factor

  Efficiency


Technical Criterion
Efficiency - SQL and Data Handling Performance

About CAST Appmarq

CAST Appmarq is by far the biggest repository of data about real IT systems. It's built on thousands of analyzed applications, made of 35 different technologies, by over 300 business organizations across major verticals. It provides IT Leaders with factual key analytics to let them know if their applications are on track.

Benchmark Statistics

Global Compliance

99.59%

Total Violations
9
Total Opportunities
2,179
Average Violations / App.
1.50
The compliance score represents 1 minus the ratio between the number of times a rule has been violated compared to the number of opportunities in a set of applications that the rule could have been violated.

Industry Insights

Financial Services

99.15%

Manufacturing

99.97%

IT & Business Consulting

100.00%