MainframeMaster

COBOL Tutorial

Progress0 of 0 lessons

COBOL ACTIVATE Statement

The ACTIVATE statement is used for activating report processing in COBOL.

Overview

The ACTIVATE statement initiates the report processing cycle by activating the report writer. It is the first step in the report generation process and prepares the report writer for processing data and generating formatted output.

This statement is essential for starting any report processing operation and must be used before any report data can be processed or generated.

Syntax

cobol
1
ACTIVATE report-name

Basic syntax for the ACTIVATE statement. The report-name specifies which report to activate for processing.

Parameters

  • report-name: The name of the report to activate for processing

Practical Examples

Example 1: Basic Report Activation

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
IDENTIFICATION DIVISION. PROGRAM-ID. ACTIVATE-EXAMPLE. DATA DIVISION. REPORT SECTION. RD SALES-REPORT PAGE LIMIT IS 60 LINES HEADING 1 FIRST DETAIL 5 LAST DETAIL 55 FOOTING 58. WORKING-STORAGE SECTION. 01 WS-SALES-DATA. 05 WS-PRODUCT-NAME PIC X(30). 05 WS-SALES-AMOUNT PIC 9(8)V99. PROCEDURE DIVISION. MAIN-PROCESS. * Activate the report for processing ACTIVATE SALES-REPORT * Process sales data MOVE "Product A" TO WS-PRODUCT-NAME MOVE 1500.75 TO WS-SALES-AMOUNT * Generate report output GENERATE SALES-REPORT * Terminate report processing TERMINATE SALES-REPORT STOP RUN.

This example demonstrates basic report activation. The ACTIVATE statement starts the report processing for SALES-REPORT, allowing subsequent GENERATE statements to produce report output.

Example 2: Multiple Report Activation

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
IDENTIFICATION DIVISION. PROGRAM-ID. MULTI-REPORT-ACTIVATION. DATA DIVISION. REPORT SECTION. RD SUMMARY-REPORT PAGE LIMIT IS 40 LINES. RD DETAIL-REPORT PAGE LIMIT IS 60 LINES. WORKING-STORAGE SECTION. 01 WS-REPORT-SELECTION PIC X(1). PROCEDURE DIVISION. PROCESS-REPORTS. DISPLAY "Select report (S=Summary, D=Detail): " ACCEPT WS-REPORT-SELECTION EVALUATE WS-REPORT-SELECTION WHEN "S" ACTIVATE SUMMARY-REPORT PERFORM GENERATE-SUMMARY-REPORT TERMINATE SUMMARY-REPORT WHEN "D" ACTIVATE DETAIL-REPORT PERFORM GENERATE-DETAIL-REPORT TERMINATE DETAIL-REPORT WHEN OTHER DISPLAY "Invalid selection" END-EVALUATE STOP RUN. GENERATE-SUMMARY-REPORT. DISPLAY "Generating summary report...". GENERATE-DETAIL-REPORT. DISPLAY "Generating detail report...".

This example shows how to activate different reports based on user selection. Each report type is activated separately, and the appropriate report processing is performed based on the user's choice.

Example 3: Report Processing with Data

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
IDENTIFICATION DIVISION. PROGRAM-ID. DATA-REPORT-PROCESSING. DATA DIVISION. REPORT SECTION. RD INVENTORY-REPORT PAGE LIMIT IS 50 LINES. WORKING-STORAGE SECTION. 01 WS-INVENTORY-RECORD. 05 WS-ITEM-CODE PIC X(10). 05 WS-ITEM-DESCRIPTION PIC X(40). 05 WS-QUANTITY PIC 9(5). 05 WS-UNIT-PRICE PIC 9(6)V99. PROCEDURE DIVISION. PROCESS-INVENTORY. * Activate the inventory report ACTIVATE INVENTORY-REPORT * Process inventory data PERFORM PROCESS-INVENTORY-DATA * Terminate the report TERMINATE INVENTORY-REPORT STOP RUN. PROCESS-INVENTORY-DATA. * Simulate processing inventory records MOVE "ITEM001" TO WS-ITEM-CODE MOVE "Laptop Computer" TO WS-ITEM-DESCRIPTION MOVE 25 TO WS-QUANTITY MOVE 999.99 TO WS-UNIT-PRICE * Generate report line GENERATE INVENTORY-REPORT.

This example demonstrates report activation with data processing. The ACTIVATE statement starts the report processing, followed by data processing and report generation, and finally termination of the report.

Best Practices and Considerations

Best Practices

  • Always activate reports before processing any report data
  • Ensure proper report termination after processing
  • Use meaningful report names for clarity
  • Handle multiple reports carefully to avoid conflicts
  • Test report activation with various data scenarios

Considerations

  • Report definition requirements in the REPORT SECTION
  • Memory usage and performance implications
  • Error handling for report processing
  • Report formatting and layout considerations
  • Integration with other report processing statements

Test Your Knowledge

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

  • To activate program execution
  • To activate report processing
  • To activate file operations
  • To activate memory allocation

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

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

3. What is the relationship between ACTIVATE and report processing?

  • They are unrelated
  • ACTIVATE starts report processing
  • Report processing enables ACTIVATE
  • They are the same thing

4. When should you use the ACTIVATE statement?

  • At the end of report processing
  • At the beginning of report processing
  • Only for error conditions
  • Only when closing files

5. What happens when an ACTIVATE statement is executed?

  • The program stops
  • Report processing is initialized and started
  • All files are closed
  • Memory is freed

Frequently Asked Questions