Editing
Naming and Coding Standards
(section)
Jump to navigation
Jump to search
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== 6. Procedure Division Coding Rules == <span id="structured-programming"></span> === 6.1 Structured programming === All control flow must use structured constructs: {| !width="50%"| Construct !width="50%"| Use for |- | <code>PERFORM <paragraph></code> | Single call to a named paragraph |- | <code>PERFORM <paragraph> UNTIL <condition></code> | Loops with pre-test condition |- | <code>EVALUATE TRUE … WHEN … END-EVALUATE</code> | Multi-way branch (preferred over nested IF) |- | <code>IF … ELSE … END-IF</code> | Two-way branch |- | <code>NEXT SENTENCE</code> | Skip remainder of sentence (used sparingly; prefer END-IF) |} '''Never use:''' - <code>GO TO</code> (except structured skip idiom in legacy contexts) - <code>ALTER</code> - <code>PERFORM … THRU</code> (couples paragraphs; prefer explicit PERFORM chains) <span id="evaluate-true-convention"></span> === 6.2 EVALUATE TRUE convention === The method-dispatch EVALUATE always takes this form: <syntaxhighlight lang="cobol">EVALUATE TRUE WHEN <condition-name-1> PERFORM <paragraph> WHEN <condition-name-2> PERFORM <paragraph> WHEN OTHER MOVE 1 TO <result-field> END-EVALUATE.</syntaxhighlight> * Every EVALUATE must have a <code>WHEN OTHER</code> clause. * The <code>WHEN OTHER</code> must set a meaningful error indicator; it must never be a no-op. <span id="perform-until"></span> === 6.3 PERFORM … UNTIL === * The loop condition is checked '''before''' the first iteration (test-before / DO-WHILE reversed). * Infinite loops are not permitted. Every PERFORM UNTIL must have a reachable exit condition. * Loop termination must be tested and documented in the program logic guide. <span id="call-conventions"></span> === 6.4 CALL conventions === * All inter-program calls use <code>CALL "literal" USING <data-block></code>. * The called program name must be a string literal, not a data name (for static linkage and security). * Always check the result field of the called program’s control block immediately after the CALL. <span id="arithmetic"></span> === 6.5 Arithmetic === * Use <code>COMPUTE</code> for complex expressions: <code>COMPUTE x = a ** 0.5</code>. * Use <code>ADD … TO</code>, <code>SUBTRACT … FROM</code>, <code>MULTIPLY … BY</code>, <code>DIVIDE … BY … GIVING … REMAINDER</code> for simple operations. * Always use <code>GIVING</code> and <code>REMAINDER</code> clauses to avoid in-place modification of source operands. * Always check for zero divisor before DIVIDE. * Declare intermediate results with sufficient precision to avoid truncation: <code>PIC 9(9)V9(9)</code> for square-root results. ----- <span id="sql-embedding-conventions"></span>
Summary:
Please note that all contributions to Webhuis wiki are considered to be released under the GNU Free Documentation License 1.3 or later (see
Project:Copyrights
for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource.
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Navigation menu
Personal tools
Not logged in
Talk
Contributions
Create account
Log in
Namespaces
Page
Discussion
English
Views
Read
Edit
View history
More
Search
Navigation
Voorpagina
Cobol and PostgreSQL
PostgreSQL
CFEngine
Proxmox
Webhuis Kennisbank
Basale infra
Webhuis bouwstenen
Webhuis configuratie
Webhuis Infra
Webhuis Support
Webhuis Raspberry
Opzet Applicaties
Business Applicaties
Community portal
Current events
Recent changes
Random page
Help
sitesupport
Tools
What links here
Related changes
Special pages
Page information