MainframeMaster

COBOL Tutorial

COBOL SECTION Statement - Quick Reference

Progress0 of 0 lessons

Overview

The SECTION statement is used to organize procedures in the PROCEDURE DIVISION into logical groups. It improves program structure and readability by grouping related paragraphs together.

Purpose and Usage

  • Program organization - Group related procedures together
  • Code readability - Improve program structure
  • Maintainability - Make programs easier to maintain
  • Logical grouping - Organize procedures by function
  • Modular design - Create modular program structure

Syntax

The SECTION statement follows a simple syntax for organizing procedures.

Basic Syntax

cobol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
* Basic SECTION syntax SECTION-NAME SECTION. paragraph-name. statements another-paragraph. statements * Complete example IDENTIFICATION DIVISION. PROGRAM-ID. SECTION-EXAMPLE. PROCEDURE DIVISION. MAIN-LOGIC. PERFORM INITIALIZATION-SECTION PERFORM PROCESSING-SECTION PERFORM CLEANUP-SECTION STOP RUN. INITIALIZATION-SECTION SECTION. INIT-PARAGRAPH. DISPLAY "Initializing program" OPEN INPUT INPUT-FILE OPEN OUTPUT OUTPUT-FILE. PROCESSING-SECTION SECTION. PROCESS-DATA. READ INPUT-FILE AT END GO TO END-PROCESSING END-READ PERFORM PROCESS-RECORD. PROCESS-RECORD. * Process record logic here. CLEANUP-SECTION SECTION. CLEANUP-PROCEDURES. CLOSE INPUT-FILE OUTPUT-FILE DISPLAY "Program completed".

SECTION organizes procedures into logical groups.

Practical Examples

Examples of using the SECTION statement in different program structures.

File Processing Program

cobol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
* File processing with SECTIONs PROCEDURE DIVISION. MAIN-CONTROL. PERFORM INITIALIZATION PERFORM MAIN-PROCESSING PERFORM TERMINATION STOP RUN. INITIALIZATION SECTION. SETUP-PROGRAM. DISPLAY "Starting file processing" OPEN INPUT MASTER-FILE OPEN OUTPUT REPORT-FILE. MAIN-PROCESSING SECTION. PROCESS-FILES. READ MASTER-FILE AT END GO TO END-PROCESSING END-READ PERFORM VALIDATE-RECORD PERFORM WRITE-RECORD. VALIDATE-RECORD. * Validation logic here. WRITE-RECORD. * Write logic here. TERMINATION SECTION. CLEANUP-PROGRAM. CLOSE MASTER-FILE REPORT-FILE DISPLAY "Processing completed".

SECTIONs organize file processing operations.

Best Practices

Understanding best practices ensures effective use of the SECTION statement.

Best Practices

  • Use descriptive names - Choose meaningful section names
  • Group related procedures - Keep related functionality together
  • Maintain consistency - Use consistent naming conventions
  • Limit section size - Keep sections manageable
  • Document purpose - Clearly indicate section purpose

Test Your Knowledge

1. What is the primary purpose of the SECTION statement in COBOL?

  • To define file sections
  • To organize program procedures into logical groups
  • To create data structures
  • To define program parameters

2. In which COBOL division is the SECTION statement typically used?

  • IDENTIFICATION DIVISION
  • ENVIRONMENT DIVISION
  • DATA DIVISION
  • PROCEDURE DIVISION

3. What is the relationship between SECTION and PARAGRAPH?

  • They are the same thing
  • SECTION contains PARAGRAPHs
  • PARAGRAPH contains SECTIONs
  • They cannot be used together

4. Can a SECTION be called directly using PERFORM?

  • Yes, always
  • No, never
  • Only with certain COBOL versions
  • Only if the SECTION is defined as PERFORMABLE

5. What is the main benefit of using SECTIONs in COBOL?

  • Improved performance
  • Better program organization and readability
  • Reduced memory usage
  • Faster compilation

Frequently Asked Questions