MainframeMaster

COBOL Tutorial

COBOL DESTINATION Clause - Quick Reference

Progress0 of 0 lessons

Overview

The DESTINATION clause is used to specify output destinations for program results, reports, or data. This clause is part of the SPECIAL-NAMES paragraph in the CONFIGURATION SECTION and provides control over where program output is directed.

Purpose and Usage

  • Output routing - Control where program output goes
  • Device specification - Specify output devices
  • File destination - Direct output to files
  • Printer control - Route output to printers
  • Display control - Control screen output

Output Destination Concept

Program Output: [Data/Reports/Results]
DESTINATION: [File/Printer/Screen/Device]
Routing: [Program] → [DESTINATION] → [Output Device]
Controls where program output is directed

DESTINATION provides control over output routing and destination specification.

Syntax

The DESTINATION clause follows specific syntax patterns and is used in the SPECIAL-NAMES paragraph of the CONFIGURATION SECTION.

Basic Syntax

cobol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
* Basic DESTINATION clause syntax ENVIRONMENT DIVISION. CONFIGURATION SECTION. SPECIAL-NAMES. logical-name IS DESTINATION destination-specification. * Examples REPORT-OUTPUT IS DESTINATION "REPORT.TXT". PRINTER-OUTPUT IS DESTINATION "PRINTER1". SCREEN-OUTPUT IS DESTINATION "CONSOLE". * Complete example PROGRAM-ID. DESTINATION-EXAMPLE. ENVIRONMENT DIVISION. CONFIGURATION SECTION. SPECIAL-NAMES. REPORT-FILE IS DESTINATION "REPORTS/OUTPUT.TXT". PRINTER-DEVICE IS DESTINATION "LPT1". CONSOLE-OUTPUT IS DESTINATION "CONSOLE". ERROR-LOG IS DESTINATION "ERRORS.LOG".

DESTINATION is used in the SPECIAL-NAMES paragraph to define output destinations.

Destination Types

Destination TypeSpecificationUse Case
File"filename.ext"Output to files
Printer"PRINTER1" or "LPT1"Output to printers
Screen"CONSOLE" or "SCREEN"Output to display
Network"NETWORK://address"Output to network

Usage in Program

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
* Using DESTINATION in program PROGRAM-ID. DESTINATION-EXAMPLE. ENVIRONMENT DIVISION. CONFIGURATION SECTION. SPECIAL-NAMES. REPORT-OUTPUT IS DESTINATION "REPORTS/DAILY.TXT". PRINTER-OUTPUT IS DESTINATION "PRINTER1". ERROR-OUTPUT IS DESTINATION "ERRORS.LOG". DATA DIVISION. WORKING-STORAGE SECTION. 01 REPORT-LINE PIC X(80). PROCEDURE DIVISION. * Output to report file OPEN OUTPUT REPORT-OUTPUT MOVE "Daily Report" TO REPORT-LINE WRITE REPORT-LINE * Output to printer OPEN OUTPUT PRINTER-OUTPUT MOVE "Printed Report" TO REPORT-LINE WRITE REPORT-LINE * Output to error log OPEN OUTPUT ERROR-OUTPUT MOVE "Error occurred" TO REPORT-LINE WRITE REPORT-LINE

DESTINATION allows routing output to different destinations in the program.

Common Use Cases

DESTINATION is commonly used in specific scenarios where output routing and destination control is needed.

Report Generation

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
* Generating reports to different destinations ENVIRONMENT DIVISION. CONFIGURATION SECTION. SPECIAL-NAMES. DAILY-REPORT IS DESTINATION "REPORTS/DAILY.TXT". WEEKLY-REPORT IS DESTINATION "REPORTS/WEEKLY.TXT". MONTHLY-REPORT IS DESTINATION "REPORTS/MONTHLY.TXT". PRINTER-REPORT IS DESTINATION "PRINTER1". PROCEDURE DIVISION. * Generate daily report to file OPEN OUTPUT DAILY-REPORT PERFORM GENERATE-DAILY-REPORT CLOSE DAILY-REPORT * Generate weekly report to file OPEN OUTPUT WEEKLY-REPORT PERFORM GENERATE-WEEKLY-REPORT CLOSE WEEKLY-REPORT * Generate monthly report to printer OPEN OUTPUT PRINTER-REPORT PERFORM GENERATE-MONTHLY-REPORT CLOSE PRINTER-REPORT

Route different types of reports to appropriate destinations.

Error Logging

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
* Logging errors to different destinations ENVIRONMENT DIVISION. CONFIGURATION SECTION. SPECIAL-NAMES. ERROR-LOG IS DESTINATION "ERRORS.LOG". CONSOLE-ERROR IS DESTINATION "CONSOLE". DEBUG-LOG IS DESTINATION "DEBUG.LOG". PROCEDURE DIVISION. * Log critical errors to file OPEN OUTPUT ERROR-LOG MOVE "Critical error occurred" TO ERROR-MESSAGE WRITE ERROR-MESSAGE CLOSE ERROR-LOG * Display errors on console OPEN OUTPUT CONSOLE-ERROR MOVE "Error displayed on console" TO ERROR-MESSAGE WRITE ERROR-MESSAGE CLOSE CONSOLE-ERROR * Log debug information OPEN OUTPUT DEBUG-LOG MOVE "Debug information" TO DEBUG-MESSAGE WRITE DEBUG-MESSAGE CLOSE DEBUG-LOG

Route different types of error messages to appropriate destinations.

Multi-Device Output

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
* Output to multiple devices simultaneously ENVIRONMENT DIVISION. CONFIGURATION SECTION. SPECIAL-NAMES. FILE-OUTPUT IS DESTINATION "OUTPUT.TXT". PRINTER-OUTPUT IS DESTINATION "PRINTER1". SCREEN-OUTPUT IS DESTINATION "CONSOLE". PROCEDURE DIVISION. * Output to file OPEN OUTPUT FILE-OUTPUT MOVE "Data written to file" TO OUTPUT-LINE WRITE OUTPUT-LINE CLOSE FILE-OUTPUT * Output to printer OPEN OUTPUT PRINTER-OUTPUT MOVE "Data sent to printer" TO OUTPUT-LINE WRITE OUTPUT-LINE CLOSE PRINTER-OUTPUT * Output to screen OPEN OUTPUT SCREEN-OUTPUT MOVE "Data displayed on screen" TO OUTPUT-LINE WRITE OUTPUT-LINE CLOSE SCREEN-OUTPUT

Send output to multiple destinations for different purposes.

Best Practices and Tips

Following these best practices ensures effective use of the DESTINATION clause for output control and routing.

DESTINATION Design Principles

  • Use meaningful names - Choose descriptive logical names for destinations
  • Specify appropriate destinations - Match destination type to output purpose
  • Consider file paths - Use proper file paths for file destinations
  • Handle device availability - Ensure specified devices are available
  • Document destination purposes - Clearly document what each destination is for
  • Test destination access - Verify that destinations are accessible

Common Pitfalls to Avoid

PitfallProblemSolution
Invalid file pathsOutput fails to writeUse valid file paths and ensure directories exist
Unavailable devicesOutput routing failsVerify device availability before specifying
Poor naming conventionsConfusing destination usageUse clear, descriptive logical names
Missing error handlingProgram crashes on destination failureAdd proper error handling for destination operations
Not documenting usageDifficult to understand output routingDocument all destination purposes and usage

Performance Considerations

  • Device performance - Different destinations have different performance characteristics
  • I/O overhead - File destinations may have I/O performance considerations
  • Network latency - Network destinations may have latency considerations
  • Printer speed - Printer destinations depend on printer speed
  • Screen refresh - Screen destinations depend on display capabilities
  • Concurrent access - Multiple destinations may affect overall performance

When to Use DESTINATION

Use CaseDESTINATION SuitabilityReasoning
Report generationExcellentEssential for routing reports to appropriate destinations
Error loggingGoodHelps route errors to appropriate logging destinations
Multi-device outputGoodProvides control over multiple output destinations
Simple outputPoorUnnecessary complexity for simple output
Input operationsNot applicableDESTINATION is for output only

DESTINATION Clause Quick Reference

UsageSyntaxExample
File destinationlogical-name IS DESTINATION "filename"REPORT-FILE IS DESTINATION "REPORT.TXT"
Printer destinationlogical-name IS DESTINATION "printer"PRINTER-OUTPUT IS DESTINATION "PRINTER1"
Screen destinationlogical-name IS DESTINATION "console"SCREEN-OUTPUT IS DESTINATION "CONSOLE"
Network destinationlogical-name IS DESTINATION "network://address"NETWORK-OUTPUT IS DESTINATION "NETWORK://192.168.1.100"
Multiple destinationsMultiple DESTINATION clausesFILE-OUTPUT IS DESTINATION "FILE.TXT"
PRINTER-OUTPUT IS DESTINATION "PRINTER1"

Test Your Knowledge

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

  • To define data types
  • To specify the output destination for program results
  • To control file operations
  • To perform calculations

2. At what level is the DESTINATION clause typically used?

  • 01 level only
  • 88 level only
  • 77 level only
  • In SPECIAL-NAMES paragraph

3. What types of destinations can be specified with DESTINATION?

  • Only files
  • Only printers
  • Files, printers, screens, and other output devices
  • Only screens

4. When is DESTINATION most useful?

  • During production runs only
  • When you need to control where program output goes
  • Only during compilation
  • Only during program termination

5. How does DESTINATION relate to program output?

  • They are completely independent
  • DESTINATION controls where program output is directed
  • DESTINATION overrides all output
  • They serve the same purpose

Frequently Asked Questions