MainframeMaster

COBOL Tutorial

Progress0 of 0 lessons

COBOL SUPPRESS Statement - Quick Reference

The SUPPRESS statement in COBOL is used to suppress printing or output during program execution. It provides a way to control output and reduce system overhead by preventing certain types of messages or output from being displayed or printed.

Primary Use

Suppress printing or output during execution

Division

PROCEDURE DIVISION

Type

Output control statement

Status

Implementation-dependent

Overview

The SUPPRESS statement is an implementation-dependent COBOL feature used to control output during program execution. It can be used to suppress various types of output including debug messages, verbose logging, or other program output. This is particularly useful in production environments where you want to reduce output or in batch processing scenarios where excessive output can impact performance. The exact behavior and availability of SUPPRESS varies between COBOL implementations.

Syntax

cobol
1
2
3
4
5
6
7
8
SUPPRESS [output-type]. * Examples (implementation-dependent): SUPPRESS. SUPPRESS PRINTING. SUPPRESS DISPLAY. SUPPRESS DEBUG. SUPPRESS ALL OUTPUT.

Practical Examples

Basic Output Control with Flags

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
* Basic output control using flags (alternative to SUPPRESS) IDENTIFICATION DIVISION. PROGRAM-ID. OUTPUT-CONTROL-EXAMPLE. DATA DIVISION. WORKING-STORAGE SECTION. 01 WS-DEBUG-FLAG PIC X VALUE 'N'. 88 DEBUG-ENABLED VALUE 'Y'. 88 DEBUG-DISABLED VALUE 'N'. 01 WS-VERBOSE-FLAG PIC X VALUE 'N'. 88 VERBOSE-ENABLED VALUE 'Y'. 88 VERBOSE-DISABLED VALUE 'N'. 01 WS-COUNTER PIC 9(3) VALUE 0. 01 WS-TOTAL PIC 9(5) VALUE 0. PROCEDURE DIVISION. MAIN-LOGIC. * Set debug mode based on environment or parameter MOVE 'Y' TO WS-DEBUG-FLAG * Enable debug output DISPLAY "Program started" * Process data with conditional output PERFORM PROCESS-DATA DISPLAY "Program completed" STOP RUN. PROCESS-DATA. PERFORM VARYING WS-COUNTER FROM 1 BY 1 UNTIL WS-COUNTER > 10 ADD WS-COUNTER TO WS-TOTAL * Conditional debug output IF DEBUG-ENABLED DISPLAY "Processing iteration: " WS-COUNTER DISPLAY "Running total: " WS-TOTAL END-IF * Conditional verbose output IF VERBOSE-ENABLED DISPLAY "Detailed processing information for iteration " WS-COUNTER END-IF END-PERFORM * Always display final result DISPLAY "Final total: " WS-TOTAL.

Explanation: This example demonstrates a common alternative to the SUPPRESS statement using conditional logic with flags. The program uses debug and verbose flags to control output. When debug mode is enabled, detailed processing information is displayed. When verbose mode is enabled, additional detailed information is shown. This approach provides flexible output control without relying on implementation-specific SUPPRESS statements.

Environment-Based Output Control

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
56
57
58
59
60
61
62
63
64
65
66
* Environment-based output control example IDENTIFICATION DIVISION. PROGRAM-ID. ENVIRONMENT-OUTPUT-EXAMPLE. DATA DIVISION. WORKING-STORAGE SECTION. 01 WS-ENVIRONMENT PIC X(10). 01 WS-OUTPUT-LEVEL PIC X(1) VALUE '1'. 01 WS-DEBUG-MODE PIC X VALUE 'N'. 88 DEBUG-ON VALUE 'Y'. 88 DEBUG-OFF VALUE 'N'. 01 WS-RECORD-COUNT PIC 9(5) VALUE 0. 01 WS-ERROR-COUNT PIC 9(3) VALUE 0. PROCEDURE DIVISION. MAIN-LOGIC. * Determine environment and set output level ACCEPT WS-ENVIRONMENT FROM ENVIRONMENT-VALUE IF WS-ENVIRONMENT = 'PRODUCTION' MOVE '0' TO WS-OUTPUT-LEVEL * Minimal output SET DEBUG-OFF TO TRUE ELSE IF WS-ENVIRONMENT = 'TESTING' MOVE '2' TO WS-OUTPUT-LEVEL * Detailed output SET DEBUG-ON TO TRUE ELSE MOVE '1' TO WS-OUTPUT-LEVEL * Standard output SET DEBUG-OFF TO TRUE END-IF DISPLAY "Environment: " WS-ENVIRONMENT DISPLAY "Output level: " WS-OUTPUT-LEVEL * Process with environment-appropriate output PERFORM PROCESS-RECORDS * Display summary based on output level IF WS-OUTPUT-LEVEL >= '1' DISPLAY "Processing completed" DISPLAY "Records processed: " WS-RECORD-COUNT END-IF IF WS-OUTPUT-LEVEL >= '2' OR DEBUG-ON DISPLAY "Error count: " WS-ERROR-COUNT DISPLAY "Detailed processing statistics available" END-IF STOP RUN. PROCESS-RECORDS. * Simulate record processing PERFORM VARYING WS-RECORD-COUNT FROM 1 BY 1 UNTIL WS-RECORD-COUNT > 100 * Simulate occasional errors IF WS-RECORD-COUNT MOD 20 = 0 ADD 1 TO WS-ERROR-COUNT IF DEBUG-ON DISPLAY "Error processing record: " WS-RECORD-COUNT END-IF END-IF * Progress indicator for verbose output IF WS-OUTPUT-LEVEL >= '2' IF WS-RECORD-COUNT MOD 10 = 0 DISPLAY "Processed " WS-RECORD-COUNT " records" END-IF END-IF END-PERFORM.

Explanation: This example shows how to implement environment-based output control. The program determines the environment (production, testing, or development) and sets appropriate output levels. In production, minimal output is displayed. In testing, detailed output including debug information is shown. This approach provides better control than SUPPRESS and works across different COBOL implementations.

Batch Processing Output Control

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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
* Batch processing with output control example IDENTIFICATION DIVISION. PROGRAM-ID. BATCH-OUTPUT-EXAMPLE. DATA DIVISION. WORKING-STORAGE SECTION. 01 WS-BATCH-MODE PIC X VALUE 'Y'. 88 BATCH-PROCESSING VALUE 'Y'. 88 INTERACTIVE-MODE VALUE 'N'. 01 WS-SUMMARY-ONLY PIC X VALUE 'N'. 88 SUMMARY-ONLY VALUE 'Y'. 88 DETAILED-OUTPUT VALUE 'N'. 01 WS-RECORD-COUNT PIC 9(6) VALUE 0. 01 WS-PROCESSED-COUNT PIC 9(6) VALUE 0. 01 WS-ERROR-COUNT PIC 9(4) VALUE 0. 01 WS-START-TIME PIC 9(8). 01 WS-END-TIME PIC 9(8). PROCEDURE DIVISION. MAIN-LOGIC. * Get current time for performance tracking ACCEPT WS-START-TIME FROM TIME * Check if running in batch mode IF BATCH-PROCESSING SET SUMMARY-ONLY TO TRUE DISPLAY "Batch processing started" ELSE SET DETAILED-OUTPUT TO TRUE DISPLAY "Interactive processing started" END-IF * Process records with appropriate output level PERFORM PROCESS-BATCH-RECORDS * Get end time and calculate duration ACCEPT WS-END-TIME FROM TIME * Display summary information PERFORM DISPLAY-SUMMARY STOP RUN. PROCESS-BATCH-RECORDS. * Simulate processing large number of records PERFORM VARYING WS-RECORD-COUNT FROM 1 BY 1 UNTIL WS-RECORD-COUNT > 10000 * Process record logic here ADD 1 TO WS-PROCESSED-COUNT * Simulate occasional errors IF WS-RECORD-COUNT MOD 1000 = 0 ADD 1 TO WS-ERROR-COUNT END-IF * Progress indicator for detailed output IF DETAILED-OUTPUT IF WS-RECORD-COUNT MOD 100 = 0 DISPLAY "Processed " WS-RECORD-COUNT " records" END-IF END-IF * Minimal progress for batch mode IF SUMMARY-ONLY IF WS-RECORD-COUNT MOD 5000 = 0 DISPLAY "Progress: " WS-RECORD-COUNT " records processed" END-IF END-IF END-PERFORM. DISPLAY-SUMMARY. DISPLAY "=== Processing Summary ===" DISPLAY "Total records: " WS-RECORD-COUNT DISPLAY "Successfully processed: " WS-PROCESSED-COUNT DISPLAY "Errors encountered: " WS-ERROR-COUNT * Calculate and display processing time SUBTRACT WS-START-TIME FROM WS-END-TIME DISPLAY "Processing time: " WS-END-TIME " seconds" IF SUMMARY-ONLY DISPLAY "Batch processing completed" ELSE DISPLAY "Detailed processing completed" END-IF.

Explanation: This example demonstrates output control for batch processing scenarios. The program detects whether it's running in batch mode and adjusts output accordingly. In batch mode, only summary information and occasional progress indicators are displayed to reduce system overhead. In interactive mode, detailed progress information is shown. This approach optimizes performance for batch processing while maintaining useful output for interactive use.

Log Level Control

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
56
57
58
* Log level control example IDENTIFICATION DIVISION. PROGRAM-ID. LOG-LEVEL-EXAMPLE. DATA DIVISION. WORKING-STORAGE SECTION. 01 WS-LOG-LEVEL PIC 9(1) VALUE 1. 88 LOG-ERROR VALUE 1. 88 LOG-WARNING VALUE 2. 88 LOG-INFO VALUE 3. 88 LOG-DEBUG VALUE 4. 01 WS-CURRENT-LEVEL PIC 9(1). 01 WS-MESSAGE PIC X(100). 01 WS-TIMESTAMP PIC X(20). PROCEDURE DIVISION. MAIN-LOGIC. * Set log level based on parameter or environment ACCEPT WS-CURRENT-LEVEL FROM ARGUMENT-VALUE IF WS-CURRENT-LEVEL = 0 MOVE 1 TO WS-CURRENT-LEVEL * Default to error level END-IF DISPLAY "Log level set to: " WS-CURRENT-LEVEL * Demonstrate different log levels PERFORM LOG-MESSAGE USING 1 "Critical error occurred" PERFORM LOG-MESSAGE USING 2 "Warning: Resource usage high" PERFORM LOG-MESSAGE USING 3 "Information: Processing started" PERFORM LOG-MESSAGE USING 4 "Debug: Variable value = 123" STOP RUN. LOG-MESSAGE. USING LOG-LEVEL PIC 9(1) MESSAGE-TEXT PIC X(100). * Check if message should be displayed based on current log level IF LOG-LEVEL <= WS-CURRENT-LEVEL * Get current timestamp ACCEPT WS-TIMESTAMP FROM DATE YYYYMMDD STRING WS-TIMESTAMP DELIMITED BY SIZE " " DELIMITED BY SIZE INTO WS-MESSAGE END-STRING * Format log message based on level EVALUATE LOG-LEVEL WHEN 1 DISPLAY "ERROR: " MESSAGE-TEXT WHEN 2 DISPLAY "WARNING: " MESSAGE-TEXT WHEN 3 DISPLAY "INFO: " MESSAGE-TEXT WHEN 4 DISPLAY "DEBUG: " MESSAGE-TEXT END-EVALUATE END-IF.

Explanation: This example shows how to implement log level control as an alternative to SUPPRESS. The program uses a numeric log level system where higher numbers include more detailed output. Error messages (level 1) are always displayed, while debug messages (level 4) are only shown when the log level is set to 4. This provides granular control over output verbosity and is more flexible than simple suppression.

Best Practices and Considerations

Important Considerations

  • SUPPRESS is implementation-dependent
  • Consider using conditional logic as alternative
  • Use environment variables for output control
  • Implement log levels for better control
  • Test output control in different environments

Advantages

  • Can reduce system overhead
  • Provides output control flexibility
  • Useful for batch processing
  • Can improve performance
  • Helps manage log verbosity

Limitations

  • Not available in all COBOL implementations
  • Behavior may vary between systems
  • May not provide granular control
  • Can make debugging more difficult
  • Requires careful testing

Best Practices

  • • Use conditional logic as a portable alternative
  • • Implement log levels for better control
  • • Use environment variables for configuration
  • • Test output control in all target environments
  • • Document output control behavior

Test Your Knowledge

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

  • To stop program execution
  • To suppress printing or output during program execution
  • To hide variables from other programs
  • To disable error messages

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

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

3. What types of output can the SUPPRESS statement control?

  • Only error messages
  • Only debug output
  • Various types of output including printing, display, and debug messages
  • Only file output

4. Is the SUPPRESS statement supported in all COBOL implementations?

  • Yes, it is a standard COBOL feature
  • No, it is implementation-dependent
  • Only in mainframe environments
  • Only in modern COBOL versions

5. What is a common alternative to using SUPPRESS for controlling output?

  • Using STOP RUN
  • Using conditional DISPLAY statements with flags
  • Using EXIT PROGRAM
  • Using PERFORM statements