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.
DESTINATION provides control over output routing and destination specification.
The DESTINATION clause follows specific syntax patterns and is used in the SPECIAL-NAMES paragraph of the CONFIGURATION SECTION.
1234567891011121314151617181920* 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 Type | Specification | Use 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 |
12345678910111213141516171819202122232425262728* 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.
DESTINATION is commonly used in specific scenarios where output routing and destination control is needed.
123456789101112131415161718192021222324* 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.
1234567891011121314151617181920212223242526* 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.
1234567891011121314151617181920212223242526* 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.
Following these best practices ensures effective use of the DESTINATION clause for output control and routing.
Pitfall | Problem | Solution |
---|---|---|
Invalid file paths | Output fails to write | Use valid file paths and ensure directories exist |
Unavailable devices | Output routing fails | Verify device availability before specifying |
Poor naming conventions | Confusing destination usage | Use clear, descriptive logical names |
Missing error handling | Program crashes on destination failure | Add proper error handling for destination operations |
Not documenting usage | Difficult to understand output routing | Document all destination purposes and usage |
Use Case | DESTINATION Suitability | Reasoning |
---|---|---|
Report generation | Excellent | Essential for routing reports to appropriate destinations |
Error logging | Good | Helps route errors to appropriate logging destinations |
Multi-device output | Good | Provides control over multiple output destinations |
Simple output | Poor | Unnecessary complexity for simple output |
Input operations | Not applicable | DESTINATION is for output only |
Usage | Syntax | Example |
---|---|---|
File destination | logical-name IS DESTINATION "filename" | REPORT-FILE IS DESTINATION "REPORT.TXT" |
Printer destination | logical-name IS DESTINATION "printer" | PRINTER-OUTPUT IS DESTINATION "PRINTER1" |
Screen destination | logical-name IS DESTINATION "console" | SCREEN-OUTPUT IS DESTINATION "CONSOLE" |
Network destination | logical-name IS DESTINATION "network://address" | NETWORK-OUTPUT IS DESTINATION "NETWORK://192.168.1.100" |
Multiple destinations | Multiple DESTINATION clauses | FILE-OUTPUT IS DESTINATION "FILE.TXT" PRINTER-OUTPUT IS DESTINATION "PRINTER1" |
1. What is the primary purpose of the DESTINATION clause in COBOL?
2. At what level is the DESTINATION clause typically used?
3. What types of destinations can be specified with DESTINATION?
4. When is DESTINATION most useful?
5. How does DESTINATION relate to program output?
Understanding the ASSIGN clause for file and device assignment.
Understanding the SPECIAL-NAMES paragraph in CONFIGURATION SECTION.
Using DESTINATION with file descriptions.
Using DESTINATION with report writer.
Understanding COBOL program structure.