MainframeMaster

COBOL Tutorial

COBOL COMMUNICATION SECTION - Quick Reference

Progress0 of 0 lessons

Overview

The COMMUNICATION SECTION is a specialized section within the DATA DIVISION used to define data structures for communication operations. It provides a standardized way to organize communication-related data and message structures.

Purpose and Usage

  • Communication data - Define structures for communication operations
  • Message handling - Organize message-related data structures
  • Protocol support - Support communication protocols and standards
  • Status information - Define communication status and control data
  • Queue management - Handle message queue structures

Communication Section Concept

DATA DIVISION
├── FILE SECTION
├── WORKING-STORAGE SECTION
├── COMMUNICATION SECTION ←
└── LINKAGE SECTION
Specialized section for communication data

COMMUNICATION SECTION is one of the four main sections in DATA DIVISION.

Syntax

The COMMUNICATION SECTION follows specific syntax patterns and can contain various types of data definitions for communication operations.

Basic Syntax

cobol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
* Basic COMMUNICATION SECTION syntax DATA DIVISION. COMMUNICATION SECTION. CD communication-name [SYMBOLIC QUEUE IS queue-name] [SYMBOLIC SUB-QUEUE IS sub-queue-name] [MESSAGE COUNT IS count-field] [MESSAGE DATE IS date-field] [MESSAGE TIME IS time-field] [SYMBOLIC SOURCE IS source-name] [TEXT LENGTH IS length-field] [END KEY IS key-field] [STATUS KEY IS status-field] [MESSAGE TYPE IS type-field]. 01 communication-data-item PIC X(n).

COMMUNICATION SECTION can contain CD statements and 01 level data items.

CD Statement Clauses

ClausePurposeExample
SYMBOLIC QUEUEDefine queue nameSYMBOLIC QUEUE IS MSG-QUEUE
MESSAGE COUNTTrack message countMESSAGE COUNT IS WS-MSG-COUNT
MESSAGE DATEMessage date fieldMESSAGE DATE IS WS-MSG-DATE
MESSAGE TIMEMessage time fieldMESSAGE TIME IS WS-MSG-TIME
STATUS KEYCommunication statusSTATUS KEY IS WS-STATUS

Communication Data Structures

cobol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
* Message header structure 01 MESSAGE-HEADER. 05 MSG-TYPE PIC X(10). 05 MSG-LENGTH PIC 9(5). 05 MSG-PRIORITY PIC 9(1). 05 MSG-SENDER PIC X(20). 05 MSG-RECEIVER PIC X(20). 05 MSG-TIMESTAMP PIC X(26). * Communication status structure 01 COMM-STATUS. 05 STATUS-CODE PIC X(2). 05 STATUS-MESSAGE PIC X(50). 05 QUEUE-STATUS PIC X(1). 05 MESSAGE-COUNT PIC 9(4). * Protocol-specific data 01 PROTOCOL-DATA. 05 PROTOCOL-VERSION PIC X(5). 05 PROTOCOL-TYPE PIC X(10). 05 PROTOCOL-FLAGS PIC X(8).

Common data structures for communication operations.

Practical Examples

These examples demonstrate how to use the COMMUNICATION SECTION effectively in different communication scenarios.

Basic Message Communication

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
40
41
42
43
44
IDENTIFICATION DIVISION. PROGRAM-ID. MESSAGE-COMMUNICATION. DATA DIVISION. COMMUNICATION SECTION. CD MESSAGE-QUEUE SYMBOLIC QUEUE IS "MSG-QUEUE" MESSAGE COUNT IS WS-MESSAGE-COUNT MESSAGE DATE IS WS-MESSAGE-DATE MESSAGE TIME IS WS-MESSAGE-TIME STATUS KEY IS WS-STATUS-KEY. 01 MESSAGE-STRUCTURE. 05 MSG-HEADER. 10 MSG-TYPE PIC X(10). 10 MSG-LENGTH PIC 9(5). 10 MSG-PRIORITY PIC 9(1). 05 MSG-BODY PIC X(100). 05 MSG-TRAILER. 10 MSG-CHECKSUM PIC X(8). WORKING-STORAGE SECTION. 01 WS-MESSAGE-COUNT PIC 9(4). 01 WS-MESSAGE-DATE PIC 9(8). 01 WS-MESSAGE-TIME PIC 9(6). 01 WS-STATUS-KEY PIC X(2). PROCEDURE DIVISION. MAIN-PROCESS. * Initialize message structure MOVE "DATA" TO MSG-TYPE MOVE 100 TO MSG-LENGTH MOVE 1 TO MSG-PRIORITY MOVE "This is a test message" TO MSG-BODY * Process communication PERFORM PROCESS-MESSAGE STOP RUN. PROCESS-MESSAGE. DISPLAY "Message Type: " MSG-TYPE DISPLAY "Message Length: " MSG-LENGTH DISPLAY "Message Body: " MSG-BODY.

Basic message communication using CD statement and message structure.

Queue-Based Communication

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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
IDENTIFICATION DIVISION. PROGRAM-ID. QUEUE-COMMUNICATION. DATA DIVISION. COMMUNICATION SECTION. CD INPUT-QUEUE SYMBOLIC QUEUE IS "INPUT-QUEUE" SYMBOLIC SUB-QUEUE IS "HIGH-PRIORITY" MESSAGE COUNT IS WS-INPUT-COUNT STATUS KEY IS WS-INPUT-STATUS. CD OUTPUT-QUEUE SYMBOLIC QUEUE IS "OUTPUT-QUEUE" MESSAGE COUNT IS WS-OUTPUT-COUNT STATUS KEY IS WS-OUTPUT-STATUS. 01 QUEUE-MESSAGE. 05 QMSG-HEADER. 10 QMSG-ID PIC X(20). 10 QMSG-TYPE PIC X(10). 10 QMSG-PRIORITY PIC 9(1). 05 QMSG-DATA PIC X(200). 05 QMSG-METADATA. 10 QMSG-TIMESTAMP PIC X(26). 10 QMSG-SOURCE PIC X(20). WORKING-STORAGE SECTION. 01 WS-INPUT-COUNT PIC 9(4). 01 WS-INPUT-STATUS PIC X(2). 01 WS-OUTPUT-COUNT PIC 9(4). 01 WS-OUTPUT-STATUS PIC X(2). PROCEDURE DIVISION. MAIN-PROCESS. * Check input queue status IF WS-INPUT-COUNT > 0 PERFORM PROCESS-INPUT-MESSAGE END-IF * Send output message PERFORM SEND-OUTPUT-MESSAGE STOP RUN. PROCESS-INPUT-MESSAGE. DISPLAY "Processing input message from queue" DISPLAY "Queue count: " WS-INPUT-COUNT. SEND-OUTPUT-MESSAGE. MOVE "MSG001" TO QMSG-ID MOVE "RESPONSE" TO QMSG-TYPE MOVE 2 TO QMSG-PRIORITY MOVE "Response data" TO QMSG-DATA DISPLAY "Sending output message".

Queue-based communication with input and output queues.

Protocol-Specific Communication

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
40
41
42
43
44
45
46
47
48
49
IDENTIFICATION DIVISION. PROGRAM-ID. PROTOCOL-COMMUNICATION. DATA DIVISION. COMMUNICATION SECTION. CD PROTOCOL-QUEUE SYMBOLIC QUEUE IS "PROTOCOL-QUEUE" MESSAGE TYPE IS WS-MESSAGE-TYPE TEXT LENGTH IS WS-TEXT-LENGTH STATUS KEY IS WS-PROTOCOL-STATUS. 01 PROTOCOL-MESSAGE. 05 PROTOCOL-HEADER. 10 PROTOCOL-VERSION PIC X(5). 10 PROTOCOL-TYPE PIC X(10). 10 PROTOCOL-FLAGS PIC X(8). 10 PROTOCOL-SEQUENCE PIC 9(6). 05 PROTOCOL-BODY. 10 PROTOCOL-COMMAND PIC X(20). 10 PROTOCOL-PARAMETERS PIC X(100). 05 PROTOCOL-TRAILER. 10 PROTOCOL-CHECKSUM PIC X(8). 10 PROTOCOL-END-MARKER PIC X(2). WORKING-STORAGE SECTION. 01 WS-MESSAGE-TYPE PIC X(10). 01 WS-TEXT-LENGTH PIC 9(5). 01 WS-PROTOCOL-STATUS PIC X(2). PROCEDURE DIVISION. MAIN-PROCESS. * Initialize protocol message MOVE "1.0" TO PROTOCOL-VERSION MOVE "REQUEST" TO PROTOCOL-TYPE MOVE "00000001" TO PROTOCOL-FLAGS MOVE 1 TO PROTOCOL-SEQUENCE MOVE "GET_DATA" TO PROTOCOL-COMMAND MOVE "PARAM1=value1" TO PROTOCOL-PARAMETERS * Process protocol communication PERFORM PROCESS-PROTOCOL-MESSAGE STOP RUN. PROCESS-PROTOCOL-MESSAGE. DISPLAY "Protocol Version: " PROTOCOL-VERSION DISPLAY "Protocol Type: " PROTOCOL-TYPE DISPLAY "Protocol Command: " PROTOCOL-COMMAND DISPLAY "Protocol Parameters: " PROTOCOL-PARAMETERS.

Protocol-specific communication with structured message format.

Status Monitoring Communication

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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
IDENTIFICATION DIVISION. PROGRAM-ID. STATUS-COMMUNICATION. DATA DIVISION. COMMUNICATION SECTION. CD STATUS-QUEUE SYMBOLIC QUEUE IS "STATUS-QUEUE" MESSAGE COUNT IS WS-STATUS-COUNT MESSAGE DATE IS WS-STATUS-DATE MESSAGE TIME IS WS-STATUS-TIME STATUS KEY IS WS-STATUS-KEY. 01 STATUS-MESSAGE. 05 STATUS-HEADER. 10 STATUS-SOURCE PIC X(20). 10 STATUS-TIMESTAMP PIC X(26). 10 STATUS-SEQUENCE PIC 9(6). 05 STATUS-DATA. 10 STATUS-CODE PIC X(2). 10 STATUS-LEVEL PIC X(1). 10 STATUS-DESCRIPTION PIC X(100). 05 STATUS-METRICS. 10 STATUS-CPU-USAGE PIC 9(3). 10 STATUS-MEMORY-USAGE PIC 9(3). 10 STATUS-DISK-USAGE PIC 9(3). WORKING-STORAGE SECTION. 01 WS-STATUS-COUNT PIC 9(4). 01 WS-STATUS-DATE PIC 9(8). 01 WS-STATUS-TIME PIC 9(6). 01 WS-STATUS-KEY PIC X(2). PROCEDURE DIVISION. MAIN-PROCESS. * Initialize status message MOVE "SYSTEM-MONITOR" TO STATUS-SOURCE MOVE "00" TO STATUS-CODE MOVE "I" TO STATUS-LEVEL MOVE "System operating normally" TO STATUS-DESCRIPTION MOVE 25 TO STATUS-CPU-USAGE MOVE 60 TO STATUS-MEMORY-USAGE MOVE 45 TO STATUS-DISK-USAGE * Send status update PERFORM SEND-STATUS-UPDATE STOP RUN. SEND-STATUS-UPDATE. DISPLAY "Status Source: " STATUS-SOURCE DISPLAY "Status Code: " STATUS-CODE DISPLAY "Status Description: " STATUS-DESCRIPTION DISPLAY "CPU Usage: " STATUS-CPU-USAGE "%" DISPLAY "Memory Usage: " STATUS-MEMORY-USAGE "%" DISPLAY "Disk Usage: " STATUS-DISK-USAGE "%".

Status monitoring communication with system metrics.

Best Practices and Considerations

Understanding best practices ensures proper communication data organization and system integration.

Communication Section Best Practices

  • Use descriptive names - Choose meaningful names for CD statements and data items
  • Organize logically - Group related communication data together
  • Document structures - Clearly document message formats and protocols
  • Handle errors - Include error handling in communication operations
  • Validate data - Validate communication data before processing

Common Pitfalls to Avoid

PitfallProblemSolution
Inconsistent namingConfusion and errorsUse consistent naming conventions
Missing status handlingCommunication failuresAlways check status codes
Inadequate documentationMaintenance difficultiesDocument all structures and protocols
Poor error handlingSystem failuresImplement comprehensive error handling
Protocol mismatchesCommunication errorsEnsure protocol compatibility

Modern Communication Considerations

cobol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
* Traditional mainframe communication CD MAINFRAME-QUEUE SYMBOLIC QUEUE IS "CICS-QUEUE" MESSAGE COUNT IS WS-QUEUE-COUNT. * Modern web service communication 01 WEB-SERVICE-REQUEST. 05 WS-HEADER. 10 WS-CONTENT-TYPE PIC X(50). 10 WS-AUTHORIZATION PIC X(100). 05 WS-BODY PIC X(1000). * Database communication 01 DB-COMMUNICATION. 05 DB-COMMAND PIC X(200). 05 DB-PARAMETERS PIC X(500). 05 DB-RESULT-STATUS PIC X(2).

Consider modern communication needs when designing structures.

COMMUNICATION SECTION Quick Reference

ComponentSyntaxPurpose
Section DeclarationCOMMUNICATION SECTION.Declare communication section
CD StatementCD name [clauses]Define communication description
SYMBOLIC QUEUESYMBOLIC QUEUE IS nameDefine queue name
MESSAGE COUNTMESSAGE COUNT IS fieldTrack message count
STATUS KEYSTATUS KEY IS fieldCommunication status

Test Your Knowledge

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

  • To define file structures
  • To define communication-related data structures
  • To define working storage
  • To define linkage data

2. In which division is the COMMUNICATION SECTION typically used?

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

3. What type of data is typically defined in the COMMUNICATION SECTION?

  • File records
  • Communication messages and status information
  • Working variables
  • Program parameters

4. Which of the following is commonly used in the COMMUNICATION SECTION?

  • FD statements
  • CD statements
  • 01 level data items
  • All of the above

5. When is the COMMUNICATION SECTION most useful?

  • When working with files
  • When working with communication protocols or message passing
  • When defining variables
  • When opening files

Frequently Asked Questions