MainframeMaster

COBOL Tutorial

COBOL RUN Statement - Quick Reference

Progress0 of 0 lessons

Overview

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.

Purpose and Usage

  • Program execution - Execute other programs
  • Program chaining - Chain programs together
  • Batch processing - Run programs in sequence
  • Utility execution - Execute system utilities
  • Workflow control - Control program flow

Program Execution Concept

Program A
├── Process data
├── RUN Program B
└── Continue processing
Program B executes and returns control

RUN executes another program and may return control.

Syntax

The RUN statement has a simple syntax but behavior may vary by implementation.

Basic Syntax

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
* 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.

RUN vs CALL Comparison

StatementPurposeControl Flow
RUNExecute separate programMay terminate current program
CALLInvoke subprogramReturns to calling program
EXECExecute system commandReturns after execution

Practical Examples

These examples demonstrate how to use the RUN statement effectively in different program execution scenarios.

Batch Processing Chain

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
IDENTIFICATION 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.

Utility Program Execution

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
* 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.

Report Generation Workflow

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
* 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.

System Maintenance

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
* 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.

Best Practices and Considerations

Understanding best practices ensures effective use of the RUN statement.

Best Practices

  • Verify program existence - Ensure programs exist before RUN
  • Handle errors gracefully - Provide error handling for RUN failures
  • Use meaningful names - Use descriptive program names
  • Document dependencies - Clearly document program dependencies
  • Test thoroughly - Verify RUN behavior with various scenarios
  • Consider alternatives - Evaluate CALL vs RUN for your needs

Common Use Cases

Use CaseDescriptionExample
Program ChainingExecute programs in sequenceRUN "NEXT-PROGRAM"
Batch ProcessingRun batch jobsRUN "BATCH-JOB"
Utility ExecutionExecute system utilitiesRUN "BACKUP-UTIL"
Report GenerationGenerate reportsRUN "REPORT-GEN"
System MaintenanceRun maintenance programsRUN "MAINTENANCE"

Performance Considerations

  • Program loading - RUN may involve loading programs into memory
  • Resource usage - Each RUN may consume system resources
  • Execution time - Consider total execution time of chained programs
  • Memory management - RUN may affect memory allocation
  • System overhead - Program switching has overhead

RUN Statement Quick Reference

UsageSyntaxExample
Basic RUNRUN program-nameRUN "REPORT-GEN"
Conditional RUNIF condition RUN program-nameIF NEEDED RUN "VALIDATE"
Program chainingRUN program1 RUN program2RUN "PROCESS" RUN "REPORT"
Error handlingIF error RUN error-programIF ERROR RUN "ERROR-HANDLER"
Workflow controlRUN step1 RUN step2 RUN step3RUN "EXTRACT" RUN "TRANSFORM" RUN "LOAD"

Test Your Knowledge

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

  • To compile a program
  • To execute a program or subprogram
  • To debug a program
  • To terminate a program

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

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

3. What happens after a RUN statement executes?

  • The current program terminates
  • Control returns to the calling program
  • The system waits for user input
  • It depends on the program being executed

4. Can you pass parameters with the RUN statement?

  • No, never
  • Yes, always
  • It depends on the COBOL implementation
  • Only with certain program types

5. What is the relationship between RUN and CALL statements?

  • They are the same thing
  • RUN executes programs, CALL invokes subprograms
  • RUN is faster than CALL
  • They cannot be used together

Frequently Asked Questions