rspec/rules/S5032/cobol/rule.adoc

60 lines
1.3 KiB
Plaintext
Raw Normal View History

2021-04-28 16:49:39 +02:00
Using recursion with paragraphs is not a problem in itself but it potentially exposes the software to endless loop. This is the case when there is no condition to end the recursion or when this condition is always false.
This rule raises an issue when a paragraph contains a ``++PERFORM++`` to itself to warn the developer that there is a risk of endless loop. This rule can also be used to fully prevent recursion to be used.
2021-04-28 16:49:39 +02:00
== Noncompliant Code Example
----
PROCEDURE DIVISION.
...
PERFORM READ-RELATED-REC-PARA
...
READ-RELATED-REC-PARA.
...
CALL MY-MODULE
IF MORE-RECS
PERFORM READ-RELATED-REC-PARA
...
----
----
999-ERROR.
"Write to a log file"
If "write fails:
"Display an error message"
PERFORM 999-ERROR.
----
2021-04-28 16:49:39 +02:00
== Compliant Solution
----
PROCEDURE DIVISION.
...
PERFORM READ-RELATED-REC-PARA
UNTIL NO-MORE-RELATED-RECS
OR MAX-NO-OF-RELATED-RECS
...
READ-RELATED-REC-PARA.
...
CALL MY-MODULE
IF MORE-RECS
SET MORE-RELATED-RECS TO TRUE
ADD 1 TO NO-OF-RELATED-RECS
ELSE
SET NO-MORE-RELATED-RECS TO TRUE
END-IF
...
----
ifdef::env-github,rspecator-view[]
'''
== Comments And Links
(visible only on this page)
include::comments-and-links.adoc[]
endif::env-github,rspecator-view[]