The RUN statement is used to execute another program from within a COBOL program. It provides program chaining capabilities and allows one program to launch another program for execution.
RUN executes another program and may return control.
The RUN statement has a simple syntax but behavior may vary by implementation.
12345678910111213141516171819202122232425262728293031323334* Basic RUN syntax RUN program-name * With conditional execution IF condition RUN program-name END-IF * Complete example IDENTIFICATION DIVISION. PROGRAM-ID. RUN-EXAMPLE. PROCEDURE DIVISION. MAIN-LOGIC. DISPLAY "Starting main program" * Execute data processing PERFORM PROCESS-DATA * Run report generation program RUN "REPORT-GEN" * Continue with main program PERFORM FINAL-PROCESSING STOP RUN. PROCESS-DATA. DISPLAY "Processing data..." * Data processing logic here. FINAL-PROCESSING. DISPLAY "Final processing..." * Final processing logic here.
RUN executes the specified program and may return control.
Statement | Purpose | Control Flow |
---|---|---|
RUN | Execute separate program | May terminate current program |
CALL | Invoke subprogram | Returns to calling program |
EXEC | Execute system command | Returns after execution |
These examples demonstrate how to use the RUN statement effectively in different program execution scenarios.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546IDENTIFICATION DIVISION. PROGRAM-ID. BATCH-PROCESSOR. PROCEDURE DIVISION. MAIN-LOGIC. DISPLAY "Starting batch processing chain" * Step 1: Data validation DISPLAY "Step 1: Running data validation" RUN "DATA-VALIDATE" * Step 2: Data processing DISPLAY "Step 2: Running data processing" RUN "DATA-PROCESS" * Step 3: Report generation DISPLAY "Step 3: Running report generation" RUN "REPORT-GEN" * Step 4: Data cleanup DISPLAY "Step 4: Running data cleanup" RUN "DATA-CLEANUP" DISPLAY "Batch processing chain completed" STOP RUN. * Alternative: Conditional execution PROCEDURE DIVISION. CONDITIONAL-BATCH. DISPLAY "Starting conditional batch processing" * Check if data validation is needed IF VALIDATION-REQUIRED RUN "DATA-VALIDATE" END-IF * Always run data processing RUN "DATA-PROCESS" * Check if reports are needed IF REPORTS-REQUIRED RUN "REPORT-GEN" END-IF DISPLAY "Conditional batch processing completed" STOP RUN.
RUN enables program chaining for batch processing workflows.
1234567891011121314151617181920212223242526272829303132333435* Utility program execution with RUN PROCEDURE DIVISION. UTILITY-EXECUTION. DISPLAY "Starting utility execution" * Run backup utility DISPLAY "Running backup utility" RUN "BACKUP-UTIL" * Run data conversion utility DISPLAY "Running data conversion" RUN "CONVERT-UTIL" * Run system maintenance utility DISPLAY "Running system maintenance" RUN "MAINTENANCE-UTIL" DISPLAY "Utility execution completed" * Error handling with RUN PROCEDURE DIVISION. ERROR-HANDLING-RUN. DISPLAY "Starting error handling process" * Try to run recovery program RUN "RECOVERY-PROG" * Check if recovery was successful IF RECOVERY-SUCCESSFUL DISPLAY "Recovery completed successfully" RUN "CONTINUE-PROCESS" ELSE DISPLAY "Recovery failed" RUN "ERROR-REPORT" END-IF.
RUN executes utility programs for system operations.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253* Report generation workflow with RUN DATA DIVISION. WORKING-STORAGE SECTION. 01 REPORT-TYPE PIC X(10). 01 REPORT-DATE PIC X(8). PROCEDURE DIVISION. REPORT-WORKFLOW. DISPLAY "Starting report generation workflow" * Get report parameters DISPLAY "Enter report type (DAILY/MONTHLY): " ACCEPT REPORT-TYPE DISPLAY "Enter report date (YYYYMMDD): " ACCEPT REPORT-DATE * Run appropriate report program EVALUATE REPORT-TYPE WHEN "DAILY" RUN "DAILY-REPORT" WHEN "MONTHLY" RUN "MONTHLY-REPORT" WHEN OTHER DISPLAY "Invalid report type" RUN "ERROR-HANDLER" END-EVALUATE * Run report distribution RUN "REPORT-DISTRIBUTE" DISPLAY "Report workflow completed" * Multi-step report process PROCEDURE DIVISION. MULTI-STEP-REPORTS. DISPLAY "Starting multi-step report process" * Step 1: Extract data RUN "DATA-EXTRACT" * Step 2: Transform data RUN "DATA-TRANSFORM" * Step 3: Generate report RUN "REPORT-GENERATE" * Step 4: Format report RUN "REPORT-FORMAT" * Step 5: Distribute report RUN "REPORT-DISTRIBUTE" DISPLAY "Multi-step report process completed".
RUN orchestrates complex report generation workflows.
1234567891011121314151617181920212223242526272829303132333435363738394041424344* System maintenance with RUN PROCEDURE DIVISION. SYSTEM-MAINTENANCE. DISPLAY "Starting system maintenance" * Run database maintenance DISPLAY "Running database maintenance" RUN "DB-MAINTENANCE" * Run file cleanup DISPLAY "Running file cleanup" RUN "FILE-CLEANUP" * Run log rotation DISPLAY "Running log rotation" RUN "LOG-ROTATION" * Run performance optimization DISPLAY "Running performance optimization" RUN "PERF-OPTIMIZE" DISPLAY "System maintenance completed" * Scheduled maintenance PROCEDURE DIVISION. SCHEDULED-MAINTENANCE. DISPLAY "Starting scheduled maintenance" * Check current time MOVE FUNCTION CURRENT-DATE TO CURRENT-TIME * Run appropriate maintenance based on time IF CURRENT-HOUR < 6 * Night maintenance RUN "NIGHT-MAINTENANCE" ELSE IF CURRENT-HOUR < 18 * Day maintenance RUN "DAY-MAINTENANCE" ELSE * Evening maintenance RUN "EVENING-MAINTENANCE" END-IF DISPLAY "Scheduled maintenance completed".
RUN executes system maintenance and optimization programs.
Understanding best practices ensures effective use of the RUN statement.
Use Case | Description | Example |
---|---|---|
Program Chaining | Execute programs in sequence | RUN "NEXT-PROGRAM" |
Batch Processing | Run batch jobs | RUN "BATCH-JOB" |
Utility Execution | Execute system utilities | RUN "BACKUP-UTIL" |
Report Generation | Generate reports | RUN "REPORT-GEN" |
System Maintenance | Run maintenance programs | RUN "MAINTENANCE" |
Usage | Syntax | Example |
---|---|---|
Basic RUN | RUN program-name | RUN "REPORT-GEN" |
Conditional RUN | IF condition RUN program-name | IF NEEDED RUN "VALIDATE" |
Program chaining | RUN program1 RUN program2 | RUN "PROCESS" RUN "REPORT" |
Error handling | IF error RUN error-program | IF ERROR RUN "ERROR-HANDLER" |
Workflow control | RUN step1 RUN step2 RUN step3 | RUN "EXTRACT" RUN "TRANSFORM" RUN "LOAD" |
1. What is the primary purpose of the RUN statement in COBOL?
2. In which COBOL division is the RUN statement typically used?
3. What happens after a RUN statement executes?
4. Can you pass parameters with the RUN statement?
5. What is the relationship between RUN and CALL statements?