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.
The SENTENCE clause is used in the PROCEDURE DIVISION to group statements.
12345678910111213141516171819202122232425262728* 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.
Examples of using the SENTENCE clause in different scenarios.
12345* Group related operations MOVE "Processing started" TO MESSAGE-TEXT DISPLAY MESSAGE-TEXT PERFORM INITIALIZE-DATA DISPLAY "Initialization complete".
SENTENCE groups initialization operations.
123456* 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.
1234567891011* 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.
Understanding best practices ensures effective use of the SENTENCE clause.
1. What is the primary purpose of the SENTENCE clause in COBOL?
2. In which COBOL division is the SENTENCE clause typically used?
3. What is a sentence in COBOL programming?
4. How does the SENTENCE clause affect program execution?
5. What is the relationship between SENTENCE and NEXT SENTENCE?