Editing
COBOL Std 5 Program Structure
(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!
== 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. <code>CONSOLE IS scherm</code>). # DATA DIVISION β FILE SECTION, WORKING-STORAGE SECTION, LINKAGE SECTION (if a subprogram). # PROCEDURE DIVISION β all executable logic. === 5.2 Mandatory IDENTIFICATION DIVISION Entries === <syntaxhighlight lang="cobol"> IDENTIFICATION DIVISION. PROGRAM-ID. PROG-NAME. AUTHOR. Developer Name. DATE-WRITTEN. YYYY-MM-DD. DATE-COMPILED. YYYY-MM-DD. SECURITY. INTERNAL USE ONLY. </syntaxhighlight> The PROGRAM-ID must match the source file name exactly (without extension). === 5.3 Working-Storage Layout Order === Organise WORKING-STORAGE in this sequence: # Program identification filler (version string, program name). # Database connection parameters (if a DAL program). # Switch / flag fields (<code>SW-</code> prefix). # Counter fields (<code>CTR-</code> prefix). # Error-handling fields (<code>ERR-</code> prefix). # Business data fields. # SQL host variable groups (<code>DB-</code> prefix, via <code>EXEC SQL INCLUDE</code> or <code>COPY</code>). === 5.4 PROCEDURE DIVISION Structure === The procedure division must follow this paragraph-series order: # '''A000''' β entry paragraph; EVALUATE on method verb or input flag; dispatches to lower series. # '''R-series''' β business logic (algorithm, loop bodies, report formatting). # '''S-series''' β database and system routines (connect, cursor, fetch, insert, disconnect). # '''D-series''' β validation sub-routines. # '''E-series''' β error handling. # '''Z000''' β termination / cleanup; always the last paragraph; contains EXIT PROGRAM or STOP RUN. === 5.5 Three-Tier Architecture === For any application accessing a database, adopt the following tier separation. Each tier communicates through a shared copybook control block passed by reference. {| class="wikitable" style="width:100%" ! Tier !! Program Role !! Responsibilities |- | Orchestrator || <code>*main</code> || Accept command-line arguments; initialise UI; dispatch to business logic; manage session lifecycle. |- | Business Logic || <code>*gen / *proc</code> || Implement algorithms, loops, and decision logic. Call DAL and UI. '''Never contain SQL.''' |- | Data Access (DAL) || <code>*dal / *db</code> || All SQL statements. One EXEC SQL per paragraph. Exposes a method-dispatch interface. '''Never contains presentation logic.''' |- | Presentation (UI) || <code>*ui / *rpt</code> || All file I/O and console output. Manages print-file lifecycle. '''Never contains SQL or business rules.''' |} === 5.6 Method-Dispatch Pattern === 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. <syntaxhighlight lang="cobol"> MOVE 'connect' TO DAL-METHODS CALL 'primes' USING PRIMES-DAL IF dal-method-ok CONTINUE ELSE PERFORM E000-HANDLE-ERROR END-IF </syntaxhighlight> 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]]. {{Ambox | type = stop | text = '''Prohibited''' β Direct SQL in business-logic or presentation programs. All database access must go through the DAL tier. }} === 5.7 Paragraph Size === 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. === 5.8 Use of Sections === 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. ---- ---- ''[[Cobol programming standards|β Back to index]]''
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