MainframeMaster

COBOL Tutorial

COBOL SENTENCE Clause - Quick Reference

Progress0 of 0 lessons

Overview

The SENTENCE clause is a fundamental concept in COBOL that groups related statements together. A sentence consists of one or more statements followed by a period, creating a logical unit of execution in the program.

Purpose and Usage

  • Statement grouping - Group related statements together
  • Flow control - Control program execution flow
  • Logical organization - Organize program logic
  • Structure - Provide program structure
  • Readability - Improve program readability

Syntax

The SENTENCE clause is used in the PROCEDURE DIVISION to group statements.

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
* Basic SENTENCE syntax statement-1 statement-2 statement-3. * Complete example IDENTIFICATION DIVISION. PROGRAM-ID. SENTENCE-EXAMPLE. DATA DIVISION. WORKING-STORAGE SECTION. 01 DATA-ITEM-1 PIC X(20). 01 DATA-ITEM-2 PIC 9(5). PROCEDURE DIVISION. MAIN-LOGIC. MOVE "Hello" TO DATA-ITEM-1 MOVE 12345 TO DATA-ITEM-2 DISPLAY DATA-ITEM-1 DISPLAY DATA-ITEM-2. PROCESSING-LOGIC. IF DATA-ITEM-2 > 1000 DISPLAY "Large number" ADD 1 TO DATA-ITEM-2 DISPLAY "Updated value: " DATA-ITEM-2. STOP RUN.

SENTENCE groups statements for logical execution.

Practical Examples

Examples of using the SENTENCE clause in different scenarios.

Simple Statement Grouping

cobol
1
2
3
4
5
* Group related operations MOVE "Processing started" TO MESSAGE-TEXT DISPLAY MESSAGE-TEXT PERFORM INITIALIZE-DATA DISPLAY "Initialization complete".

SENTENCE groups initialization operations.

Conditional Statement Grouping

cobol
1
2
3
4
5
6
* Group conditional operations IF ACCOUNT-BALANCE < 0 MOVE "Overdraft detected" TO ERROR-MESSAGE DISPLAY ERROR-MESSAGE PERFORM SEND-ALERT SET ACCOUNT-FLAG TO TRUE.

SENTENCE groups conditional operations.

File Processing Grouping

cobol
1
2
3
4
5
6
7
8
9
10
11
* Group file processing operations READ INPUT-FILE AT END MOVE "End of file reached" TO STATUS-MESSAGE DISPLAY STATUS-MESSAGE PERFORM CLOSE-FILES STOP RUN. MOVE INPUT-RECORD TO PROCESSING-RECORD PERFORM PROCESS-RECORD WRITE OUTPUT-RECORD.

SENTENCE groups file processing operations.

Best Practices

Understanding best practices ensures effective use of the SENTENCE clause.

Best Practices

  • Group related statements - Keep related operations together
  • Use meaningful periods - End sentences at logical points
  • Maintain consistency - Use consistent sentence structure
  • Consider readability - Make sentences easy to understand
  • Document complex sentences - Add comments for complex groupings

Test Your Knowledge

1. What is the primary purpose of the SENTENCE clause in COBOL?

  • To define program sentences
  • To group statements and control program flow
  • To define data sentences
  • To create text output

2. In which COBOL division is the SENTENCE clause typically used?

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

3. What is a sentence in COBOL programming?

  • A single statement
  • A group of statements ending with a period
  • A paragraph name
  • A data definition

4. How does the SENTENCE clause affect program execution?

  • It has no effect
  • It groups statements for logical execution
  • It only affects compilation
  • It only affects debugging

5. What is the relationship between SENTENCE and NEXT SENTENCE?

  • They are the same thing
  • SENTENCE groups statements, NEXT SENTENCE skips to the next sentence
  • SENTENCE is for data, NEXT SENTENCE is for procedures
  • They cannot be used together

Frequently Asked Questions