<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.webhuis.nl:443/index.php?action=history&amp;feed=atom&amp;title=COBOL_Std_5_Program_Structure</id>
	<title>COBOL Std 5 Program Structure - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.webhuis.nl:443/index.php?action=history&amp;feed=atom&amp;title=COBOL_Std_5_Program_Structure"/>
	<link rel="alternate" type="text/html" href="https://wiki.webhuis.nl:443/index.php?title=COBOL_Std_5_Program_Structure&amp;action=history"/>
	<updated>2026-09-11T08:01:11Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.39.17</generator>
	<entry>
		<id>https://wiki.webhuis.nl:443/index.php?title=COBOL_Std_5_Program_Structure&amp;diff=4722&amp;oldid=prev</id>
		<title>Martin: Created page with &quot;== 5. Program Structure ==  === 5.1 Division Order ===  Every program must contain all four divisions in this sequence:  # IDENTIFICATION DIVISION — program identity and metadata. # ENVIRONMENT DIVISION — platform bindings, file assignments, special names (e.g. &lt;code&gt;CONSOLE IS scherm&lt;/code&gt;). # DATA DIVISION — FILE SECTION, WORKING-STORAGE SECTION, LINKAGE SECTION (if a subprogram). # PROCEDURE DIVISION — all executable logic.  === 5.2 Mandatory IDENTIFICATION D...&quot;</title>
		<link rel="alternate" type="text/html" href="https://wiki.webhuis.nl:443/index.php?title=COBOL_Std_5_Program_Structure&amp;diff=4722&amp;oldid=prev"/>
		<updated>2026-03-25T11:13:51Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;== 5. Program Structure ==  === 5.1 Division Order ===  Every program must contain all four divisions in this sequence:  # IDENTIFICATION DIVISION — program identity and metadata. # ENVIRONMENT DIVISION — platform bindings, file assignments, special names (e.g. &amp;lt;code&amp;gt;CONSOLE IS scherm&amp;lt;/code&amp;gt;). # DATA DIVISION — FILE SECTION, WORKING-STORAGE SECTION, LINKAGE SECTION (if a subprogram). # PROCEDURE DIVISION — all executable logic.  === 5.2 Mandatory IDENTIFICATION D...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;== 5. Program Structure ==&lt;br /&gt;
&lt;br /&gt;
=== 5.1 Division Order ===&lt;br /&gt;
&lt;br /&gt;
Every program must contain all four divisions in this sequence:&lt;br /&gt;
&lt;br /&gt;
# IDENTIFICATION DIVISION — program identity and metadata.&lt;br /&gt;
# ENVIRONMENT DIVISION — platform bindings, file assignments, special names (e.g. &amp;lt;code&amp;gt;CONSOLE IS scherm&amp;lt;/code&amp;gt;).&lt;br /&gt;
# DATA DIVISION — FILE SECTION, WORKING-STORAGE SECTION, LINKAGE SECTION (if a subprogram).&lt;br /&gt;
# PROCEDURE DIVISION — all executable logic.&lt;br /&gt;
&lt;br /&gt;
=== 5.2 Mandatory IDENTIFICATION DIVISION Entries ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;cobol&amp;quot;&amp;gt;&lt;br /&gt;
       IDENTIFICATION DIVISION.&lt;br /&gt;
       PROGRAM-ID.      PROG-NAME.&lt;br /&gt;
       AUTHOR.          Developer Name.&lt;br /&gt;
       DATE-WRITTEN.    YYYY-MM-DD.&lt;br /&gt;
       DATE-COMPILED.   YYYY-MM-DD.&lt;br /&gt;
       SECURITY.        INTERNAL USE ONLY.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The PROGRAM-ID must match the source file name exactly (without extension).&lt;br /&gt;
&lt;br /&gt;
=== 5.3 Working-Storage Layout Order ===&lt;br /&gt;
&lt;br /&gt;
Organise WORKING-STORAGE in this sequence:&lt;br /&gt;
&lt;br /&gt;
# Program identification filler (version string, program name).&lt;br /&gt;
# Database connection parameters (if a DAL program).&lt;br /&gt;
# Switch / flag fields (&amp;lt;code&amp;gt;SW-&amp;lt;/code&amp;gt; prefix).&lt;br /&gt;
# Counter fields (&amp;lt;code&amp;gt;CTR-&amp;lt;/code&amp;gt; prefix).&lt;br /&gt;
# Error-handling fields (&amp;lt;code&amp;gt;ERR-&amp;lt;/code&amp;gt; prefix).&lt;br /&gt;
# Business data fields.&lt;br /&gt;
# SQL host variable groups (&amp;lt;code&amp;gt;DB-&amp;lt;/code&amp;gt; prefix, via &amp;lt;code&amp;gt;EXEC SQL INCLUDE&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;COPY&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
=== 5.4 PROCEDURE DIVISION Structure ===&lt;br /&gt;
&lt;br /&gt;
The procedure division must follow this paragraph-series order:&lt;br /&gt;
&lt;br /&gt;
# &amp;#039;&amp;#039;&amp;#039;A000&amp;#039;&amp;#039;&amp;#039; — entry paragraph; EVALUATE on method verb or input flag; dispatches to lower series.&lt;br /&gt;
# &amp;#039;&amp;#039;&amp;#039;R-series&amp;#039;&amp;#039;&amp;#039; — business logic (algorithm, loop bodies, report formatting).&lt;br /&gt;
# &amp;#039;&amp;#039;&amp;#039;S-series&amp;#039;&amp;#039;&amp;#039; — database and system routines (connect, cursor, fetch, insert, disconnect).&lt;br /&gt;
# &amp;#039;&amp;#039;&amp;#039;D-series&amp;#039;&amp;#039;&amp;#039; — validation sub-routines.&lt;br /&gt;
# &amp;#039;&amp;#039;&amp;#039;E-series&amp;#039;&amp;#039;&amp;#039; — error handling.&lt;br /&gt;
# &amp;#039;&amp;#039;&amp;#039;Z000&amp;#039;&amp;#039;&amp;#039; — termination / cleanup; always the last paragraph; contains EXIT PROGRAM or STOP RUN.&lt;br /&gt;
&lt;br /&gt;
=== 5.5 Three-Tier Architecture ===&lt;br /&gt;
&lt;br /&gt;
For any application accessing a database, adopt the following tier separation. Each tier communicates through a shared copybook control block passed by reference.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;width:100%&amp;quot;&lt;br /&gt;
! Tier !! Program Role !! Responsibilities&lt;br /&gt;
|-&lt;br /&gt;
| Orchestrator || &amp;lt;code&amp;gt;*main&amp;lt;/code&amp;gt; || Accept command-line arguments; initialise UI; dispatch to business logic; manage session lifecycle.&lt;br /&gt;
|-&lt;br /&gt;
| Business Logic || &amp;lt;code&amp;gt;*gen / *proc&amp;lt;/code&amp;gt; || Implement algorithms, loops, and decision logic. Call DAL and UI. &amp;#039;&amp;#039;&amp;#039;Never contain SQL.&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
|-&lt;br /&gt;
| Data Access (DAL) || &amp;lt;code&amp;gt;*dal / *db&amp;lt;/code&amp;gt; || All SQL statements. One EXEC SQL per paragraph. Exposes a method-dispatch interface. &amp;#039;&amp;#039;&amp;#039;Never contains presentation logic.&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
|-&lt;br /&gt;
| Presentation (UI) || &amp;lt;code&amp;gt;*ui / *rpt&amp;lt;/code&amp;gt; || All file I/O and console output. Manages print-file lifecycle. &amp;#039;&amp;#039;&amp;#039;Never contains SQL or business rules.&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== 5.6 Method-Dispatch Pattern ===&lt;br /&gt;
&lt;br /&gt;
Inter-tier calls use a method-dispatch pattern: the caller places a verb string into a control-block method field, invokes the subprogram, and inspects the result code on return.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;cobol&amp;quot;&amp;gt;&lt;br /&gt;
           MOVE &amp;#039;connect&amp;#039;   TO DAL-METHODS&lt;br /&gt;
           CALL &amp;#039;primes&amp;#039;    USING PRIMES-DAL&lt;br /&gt;
           IF dal-method-ok&lt;br /&gt;
               CONTINUE&lt;br /&gt;
           ELSE&lt;br /&gt;
               PERFORM E000-HANDLE-ERROR&lt;br /&gt;
           END-IF&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The called program must implement an A000 EVALUATE block on its method field and set the result code before EXIT PROGRAM. Valid result codes are defined in [[#7.1 Return-Code Standard|§7.1]].&lt;br /&gt;
&lt;br /&gt;
{{Ambox&lt;br /&gt;
| type  = stop&lt;br /&gt;
| text  = &amp;#039;&amp;#039;&amp;#039;Prohibited&amp;#039;&amp;#039;&amp;#039; — Direct SQL in business-logic or presentation programs. All database access must go through the DAL tier.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
=== 5.7 Paragraph Size ===&lt;br /&gt;
&lt;br /&gt;
Each paragraph should perform a single, named function. Aim for 20–80 lines. Paragraphs exceeding 100 lines must be subdivided. Paragraphs under 5 lines are acceptable for dispatch stubs and result-setting.&lt;br /&gt;
&lt;br /&gt;
=== 5.8 Use of Sections ===&lt;br /&gt;
&lt;br /&gt;
Avoid PROCEDURE DIVISION sections, except where required by the compiler: DECLARATIVES, SORT/MERGE INPUT/OUTPUT PROCEDURE. Use paragraph-level PERFORM for all other control flow. Section fall-through is a common source of subtle bugs.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&amp;#039;&amp;#039;[[Cobol programming standards|← Back to index]]&amp;#039;&amp;#039;&lt;/div&gt;</summary>
		<author><name>Martin</name></author>
	</entry>
</feed>