MainframeMaster

COBOL Tutorial

COBOL REPOSITORY Clause - Quick Reference

Progress0 of 0 lessons

Overview

The REPOSITORY clause is used in COBOL's ENVIRONMENT DIVISION to define external data items and functions that can be shared across multiple programs. This enables code reuse and consistent data structures across large applications.

Purpose and Usage

  • External data definition - Define data items shared across programs
  • Function interfaces - Define function prototypes and interfaces
  • Code reuse - Enable sharing of common data structures
  • Modular programming - Support large application development
  • Consistency - Ensure uniform data definitions across programs

REPOSITORY vs WORKING-STORAGE Concept

REPOSITORY: [External Definition] → [Shared Across Programs]
WORKING-STORAGE: [Internal Definition] → [Single Program Only]
REPOSITORY enables sharing, WORKING-STORAGE is program-specific

REPOSITORY clause enables external data sharing across programs.

Syntax

The REPOSITORY clause follows specific syntax patterns within the ENVIRONMENT DIVISION and establishes external data definitions.

Basic Syntax

cobol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
* Basic REPOSITORY clause syntax ENVIRONMENT DIVISION. REPOSITORY SECTION. CLASS external-class-name AS "class-name" INTERFACE external-interface-name AS "interface-name" FUNCTION external-function-name AS "function-name" PROGRAM external-program-name AS "program-name". * Example with data items REPOSITORY SECTION. CLASS CUSTOMER-CLASS AS "CustomerClass" FUNCTION VALIDATE-CUSTOMER AS "validateCustomer" PROGRAM CUSTOMER-PROGRAM AS "CUSTPGM". * With multiple definitions REPOSITORY SECTION. CLASS EMPLOYEE-CLASS AS "EmployeeClass" CLASS DEPARTMENT-CLASS AS "DepartmentClass" FUNCTION CALCULATE-SALARY AS "calcSalary" FUNCTION VALIDATE-EMPLOYEE AS "validateEmployee" PROGRAM EMPLOYEE-PROGRAM AS "EMPPGM".

REPOSITORY clause establishes external definitions for sharing across programs.

REPOSITORY vs WORKING-STORAGE Comparison

AspectREPOSITORYWORKING-STORAGE
DivisionENVIRONMENT DIVISIONDATA DIVISION
ScopeExternal (shared)Internal (program-specific)
PurposeExternal definitionsInternal variables
AccessMultiple programsSingle program
LinkingRequiredNot required

ENVIRONMENT DIVISION Structure

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
* Complete ENVIRONMENT DIVISION with REPOSITORY ENVIRONMENT DIVISION. CONFIGURATION SECTION. SOURCE-COMPUTER. IBM-3090. OBJECT-COMPUTER. IBM-3090. SPECIAL-NAMES. ALPHABET ASCII-ALPHABET IS STANDARD-1 ALPHABET EBCDIC-ALPHABET IS STANDARD-2. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT CUSTOMER-FILE ASSIGN TO CUSTFILE ORGANIZATION IS INDEXED ACCESS MODE IS DYNAMIC RECORD KEY IS CUSTOMER-ID FILE STATUS IS CUSTOMER-FILE-STATUS. * REPOSITORY SECTION - External definitions REPOSITORY SECTION. CLASS CUSTOMER-CLASS AS "CustomerClass" FUNCTION VALIDATE-CUSTOMER AS "validateCustomer" FUNCTION CALCULATE-CREDIT AS "calculateCredit" PROGRAM CUSTOMER-PROGRAM AS "CUSTPGM". I-O-CONTROL. SAME RECORD AREA FOR CUSTOMER-FILE, CUSTOMER-BACKUP.

REPOSITORY SECTION is part of the ENVIRONMENT DIVISION structure.

Practical Examples

These examples demonstrate how to use the REPOSITORY clause effectively in different external data sharing scenarios.

Shared Data Structures

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
* Program 1: Define external data structures IDENTIFICATION DIVISION. PROGRAM-ID. SHARED-DATA-DEFINER. ENVIRONMENT DIVISION. REPOSITORY SECTION. CLASS CUSTOMER-RECORD AS "CustomerRecord" CLASS EMPLOYEE-RECORD AS "EmployeeRecord" FUNCTION VALIDATE-CUSTOMER AS "validateCustomer" FUNCTION VALIDATE-EMPLOYEE AS "validateEmployee". DATA DIVISION. WORKING-STORAGE SECTION. * Define shared record structures 01 CUSTOMER-RECORD. 05 CUSTOMER-ID PIC 9(6). 05 CUSTOMER-NAME PIC X(30). 05 CUSTOMER-ADDRESS PIC X(50). 05 CUSTOMER-PHONE PIC X(15). 01 EMPLOYEE-RECORD. 05 EMPLOYEE-ID PIC 9(6). 05 EMPLOYEE-NAME PIC X(30). 05 EMPLOYEE-DEPT PIC X(10). 05 EMPLOYEE-SALARY PIC 9(7)V99. PROCEDURE DIVISION. MAIN-LOGIC. * Export the record structures for other programs CALL "EXPORT-RECORDS" USING CUSTOMER-RECORD, EMPLOYEE-RECORD STOP RUN.

REPOSITORY clause enables sharing of data structures across programs.

Function Interfaces

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
* Program 2: Using shared functions IDENTIFICATION DIVISION. PROGRAM-ID. CUSTOMER-PROCESSOR. ENVIRONMENT DIVISION. REPOSITORY SECTION. FUNCTION VALIDATE-CUSTOMER AS "validateCustomer" FUNCTION CALCULATE-CREDIT AS "calculateCredit" PROGRAM CUSTOMER-PROGRAM AS "CUSTPGM". DATA DIVISION. WORKING-STORAGE SECTION. 01 CUSTOMER-DATA. 05 CUSTOMER-ID PIC 9(6). 05 CUSTOMER-NAME PIC X(30). 05 CUSTOMER-CREDIT PIC 9(7)V99. 01 VALIDATION-RESULT PIC X. 88 VALID-CUSTOMER VALUE "Y". 88 INVALID-CUSTOMER VALUE "N". PROCEDURE DIVISION. PROCESS-CUSTOMER. * Use shared validation function CALL VALIDATE-CUSTOMER USING CUSTOMER-DATA RETURNING VALIDATION-RESULT IF VALID-CUSTOMER * Use shared credit calculation function CALL CALCULATE-CREDIT USING CUSTOMER-DATA RETURNING CUSTOMER-CREDIT DISPLAY "Customer processed successfully" ELSE DISPLAY "Invalid customer data" END-IF STOP RUN.

REPOSITORY clause enables sharing of function interfaces across programs.

Class Definitions

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
* Program 3: Object-oriented approach with REPOSITORY IDENTIFICATION DIVISION. PROGRAM-ID. OBJECT-PROCESSOR. ENVIRONMENT DIVISION. REPOSITORY SECTION. CLASS CUSTOMER-CLASS AS "CustomerClass" CLASS EMPLOYEE-CLASS AS "EmployeeClass" CLASS ACCOUNT-CLASS AS "AccountClass". DATA DIVISION. WORKING-STORAGE SECTION. 01 CUSTOMER-OBJECT OBJECT REFERENCE CUSTOMER-CLASS. 01 EMPLOYEE-OBJECT OBJECT REFERENCE EMPLOYEE-CLASS. 01 ACCOUNT-OBJECT OBJECT REFERENCE ACCOUNT-CLASS. 01 CUSTOMER-DATA. 05 CUSTOMER-ID PIC 9(6). 05 CUSTOMER-NAME PIC X(30). 01 EMPLOYEE-DATA. 05 EMPLOYEE-ID PIC 9(6). 05 EMPLOYEE-NAME PIC X(30). PROCEDURE DIVISION. PROCESS-OBJECTS. * Create customer object using shared class INVOKE CUSTOMER-CLASS "NEW" USING CUSTOMER-DATA RETURNING CUSTOMER-OBJECT * Create employee object using shared class INVOKE EMPLOYEE-CLASS "NEW" USING EMPLOYEE-DATA RETURNING EMPLOYEE-OBJECT * Process objects INVOKE CUSTOMER-OBJECT "PROCESS" INVOKE EMPLOYEE-OBJECT "PROCESS" STOP RUN.

REPOSITORY clause enables sharing of class definitions across programs.

Multi-Program Application

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
* Main application program IDENTIFICATION DIVISION. PROGRAM-ID. MAIN-APPLICATION. ENVIRONMENT DIVISION. REPOSITORY SECTION. PROGRAM CUSTOMER-PROGRAM AS "CUSTPGM" PROGRAM EMPLOYEE-PROGRAM AS "EMPPGM" PROGRAM ACCOUNT-PROGRAM AS "ACCTPGM" FUNCTION SHARED-VALIDATION AS "sharedValidation". DATA DIVISION. WORKING-STORAGE SECTION. 01 SHARED-DATA. 05 USER-ID PIC 9(6). 05 USER-NAME PIC X(30). 05 VALIDATION-RESULT PIC X. PROCEDURE DIVISION. MAIN-LOGIC. * Use shared validation function CALL SHARED-VALIDATION USING SHARED-DATA RETURNING VALIDATION-RESULT * Call shared programs CALL CUSTOMER-PROGRAM USING SHARED-DATA CALL EMPLOYEE-PROGRAM USING SHARED-DATA CALL ACCOUNT-PROGRAM USING SHARED-DATA DISPLAY "Application processing complete" STOP RUN. * Subprogram 1: Customer processing IDENTIFICATION DIVISION. PROGRAM-ID. CUSTPGM. ENVIRONMENT DIVISION. REPOSITORY SECTION. FUNCTION VALIDATE-CUSTOMER AS "validateCustomer". DATA DIVISION. LINKAGE SECTION. 01 CUSTOMER-DATA. 05 CUSTOMER-ID PIC 9(6). 05 CUSTOMER-NAME PIC X(30). PROCEDURE DIVISION USING CUSTOMER-DATA. * Process customer data using shared function CALL VALIDATE-CUSTOMER USING CUSTOMER-DATA DISPLAY "Customer processing complete" EXIT PROGRAM.

REPOSITORY clause enables complex multi-program applications with shared resources.

Best Practices and Tips

Following these best practices ensures effective use of the REPOSITORY clause in COBOL applications.

REPOSITORY Best Practices

  • Use meaningful names - Choose descriptive external item names
  • Document external interfaces - Clearly document shared data structures
  • Maintain consistency - Use consistent naming conventions
  • Test external references - Verify all external items are accessible
  • Plan linking strategy - Ensure proper linking of external references
  • Version control - Manage changes to shared definitions carefully

Common Pitfalls to Avoid

PitfallProblemSolution
Undefined external referencesLinking errorsEnsure all external items are defined
Type mismatchesRuntime errorsVerify data type consistency
Missing linkingCompilation failuresInclude proper linking steps
Poor naming conventionsMaintenance difficultiesUse consistent naming standards
Inconsistent definitionsData corruptionMaintain single source of truth

Performance Considerations

  • Linking overhead - External references require linking time
  • Memory sharing - Shared data can reduce memory usage
  • Function call overhead - External function calls may be slower
  • Load time - Programs with external references may load slower
  • Cache efficiency - Shared data can improve cache utilization

When to Use REPOSITORY vs Other Methods

ScenarioUse REPOSITORYUse Other Methods
Shared data structuresYesNo
Function interfacesYesNo
Multi-program applicationsYesNo
Single program variablesNoYes (WORKING-STORAGE)
File definitionsNoYes (FILE SECTION)

REPOSITORY Clause Quick Reference

UsageSyntaxPurpose
Define external classCLASS name AS "class-name"Share class definitions
Define external functionFUNCTION name AS "function-name"Share function interfaces
Define external programPROGRAM name AS "program-name"Share program references
Define external interfaceINTERFACE name AS "interface-name"Share interface definitions
Multiple definitionsMultiple entries in REPOSITORYShare multiple external items

Test Your Knowledge

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

  • To create data files
  • To define external data items and functions
  • To generate reports
  • To create program documentation

2. In which division is the REPOSITORY clause used?

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

3. What happens when a REPOSITORY clause is executed?

  • External data items are created
  • External data items and functions are defined
  • A repository file is created
  • Repository data is processed

4. What is the relationship between REPOSITORY and external data items?

  • They are the same thing
  • REPOSITORY defines external items, items are used in programs
  • REPOSITORY is faster than external items
  • They cannot be used together

5. Which of the following is a valid REPOSITORY clause usage?

  • REPOSITORY SECTION.
  • REPOSITORY DIVISION.
  • REPOSITORY PARAGRAPH.
  • REPOSITORY SENTENCE.

Frequently Asked Questions