MainframeMaster

COBOL Tutorial

COBOL RESET Clause - Quick Reference

Progress0 of 0 lessons

Overview

The RESET clause is used in COBOL file handling to reset file status and position indicators to their initial state. This is useful for error recovery and file reuse scenarios.

Purpose and Usage

  • Error recovery - Clear file status errors
  • File reuse - Reset file for multiple operations
  • Status clearing - Clear file status indicators
  • Position reset - Reset file position indicators
  • Debugging - Clear status for testing

RESET vs CLOSE Concept

RESET: [Status Clearing] → [File Reuse]
CLOSE: [Resource Release] → [File Termination]
RESET clears status, CLOSE releases resources

RESET clause enables file reuse by clearing status indicators.

Syntax

The RESET clause follows specific syntax patterns within file handling operations and can be used with different file types.

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
* Basic RESET clause syntax RESET file-name ... RESET file-status-variable ... * Complete example RESET CUSTOMER-FILE ON EXCEPTION DISPLAY "Reset failed for customer file" NOT ON EXCEPTION DISPLAY "Customer file reset successfully". * With error handling RESET TRANSACTION-FILE ON EXCEPTION PERFORM HANDLE-RESET-ERROR NOT ON EXCEPTION PERFORM CONTINUE-PROCESSING. * Multiple file reset RESET INPUT-FILE, OUTPUT-FILE ON EXCEPTION DISPLAY "Reset failed for one or more files".

RESET clause clears file status and position indicators.

RESET vs CLOSE Comparison

AspectRESETCLOSE
PurposeStatus clearingResource release
File stateRemains openClosed
ReuseImmediateRequires reopen
Error recoveryClears errorsTerminates access
PerformanceFastModerate

PROCEDURE 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
29
30
31
32
* Complete PROCEDURE DIVISION with RESET PROCEDURE DIVISION. MAIN-LOGIC. PERFORM INITIALIZATION PERFORM PROCESS-FILES PERFORM FINALIZATION STOP RUN. INITIALIZATION. OPEN INPUT CUSTOMER-FILE OPEN OUTPUT REPORT-FILE. PROCESS-FILES. PERFORM UNTIL END-OF-FILE READ CUSTOMER-FILE AT END MOVE "Y" TO EOF-FLAG NOT AT END PERFORM PROCESS-RECORD ON EXCEPTION PERFORM HANDLE-READ-ERROR END-READ END-PERFORM. HANDLE-READ-ERROR. * Reset file status and retry RESET CUSTOMER-FILE DISPLAY "File reset, retrying read operation". FINALIZATION. CLOSE CUSTOMER-FILE CLOSE REPORT-FILE.

RESET clause is used within PROCEDURE DIVISION for error recovery.

Practical Examples

These examples demonstrate how to use the RESET clause effectively in different file handling scenarios.

Error Recovery with RESET

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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
IDENTIFICATION DIVISION. PROGRAM-ID. ERROR-RECOVERY. ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT CUSTOMER-FILE ASSIGN TO "CUSTFILE.DAT" ORGANIZATION IS SEQUENTIAL ACCESS MODE IS SEQUENTIAL FILE STATUS IS CUSTOMER-STATUS. DATA DIVISION. FILE SECTION. FD CUSTOMER-FILE LABEL RECORDS ARE STANDARD RECORD CONTAINS 80 CHARACTERS. 01 CUSTOMER-RECORD. 05 CUSTOMER-ID PIC 9(6). 05 CUSTOMER-NAME PIC X(30). 05 CUSTOMER-ADDRESS PIC X(40). 05 FILLER PIC X(4). WORKING-STORAGE SECTION. 01 CUSTOMER-STATUS PIC XX. 01 EOF-FLAG PIC X VALUE 'N'. 88 END-OF-FILE VALUE 'Y'. 01 ERROR-COUNT PIC 9(3) VALUE 0. 01 MAX-ERRORS PIC 9(3) VALUE 5. PROCEDURE DIVISION. MAIN-LOGIC. PERFORM INITIALIZATION PERFORM PROCESS-FILE UNTIL END-OF-FILE OR ERROR-COUNT >= MAX-ERRORS PERFORM FINALIZATION STOP RUN. INITIALIZATION. OPEN INPUT CUSTOMER-FILE IF CUSTOMER-STATUS NOT = "00" DISPLAY "Error opening file: " CUSTOMER-STATUS STOP RUN. PROCESS-FILE. READ CUSTOMER-FILE AT END MOVE "Y" TO EOF-FLAG NOT AT END PERFORM PROCESS-RECORD ON EXCEPTION PERFORM HANDLE-READ-ERROR END-READ. HANDLE-READ-ERROR. ADD 1 TO ERROR-COUNT DISPLAY "Read error: " CUSTOMER-STATUS " - Attempt " ERROR-COUNT * Reset file status and retry RESET CUSTOMER-FILE IF CUSTOMER-STATUS = "00" DISPLAY "File reset successfully, continuing..." ELSE DISPLAY "Reset failed: " CUSTOMER-STATUS MOVE "Y" TO EOF-FLAG END-IF. PROCESS-RECORD. * Process the customer record DISPLAY "Processing customer: " CUSTOMER-NAME. FINALIZATION. CLOSE CUSTOMER-FILE DISPLAY "Processing complete. Errors: " ERROR-COUNT.

RESET clause enables error recovery in file processing.

File Reuse with RESET

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
54
55
56
57
58
59
60
61
* File reuse scenario with RESET PROCEDURE DIVISION. BATCH-PROCESSING. PERFORM INITIALIZATION PERFORM PROCESS-BATCH-1 PERFORM RESET-FOR-BATCH-2 PERFORM PROCESS-BATCH-2 PERFORM FINALIZATION STOP RUN. INITIALIZATION. OPEN INPUT DATA-FILE OPEN OUTPUT REPORT-FILE. PROCESS-BATCH-1. DISPLAY "Processing batch 1..." PERFORM UNTIL BATCH-1-COMPLETE READ DATA-FILE AT END MOVE "Y" TO BATCH-1-COMPLETE NOT AT END PERFORM PROCESS-BATCH-1-RECORD END-READ END-PERFORM. RESET-FOR-BATCH-2. DISPLAY "Resetting file for batch 2..." RESET DATA-FILE IF FILE-STATUS = "00" DISPLAY "File reset successfully for batch 2" ELSE DISPLAY "Reset failed: " FILE-STATUS STOP RUN END-IF. PROCESS-BATCH-2. DISPLAY "Processing batch 2..." PERFORM UNTIL BATCH-2-COMPLETE READ DATA-FILE AT END MOVE "Y" TO BATCH-2-COMPLETE NOT AT END PERFORM PROCESS-BATCH-2-RECORD END-READ END-PERFORM. PROCESS-BATCH-1-RECORD. * Process record for batch 1 WRITE REPORT-RECORD FROM DATA-RECORD. PROCESS-BATCH-2-RECORD. * Process record for batch 2 with different logic MOVE DATA-RECORD TO BATCH-2-RECORD PERFORM VALIDATE-BATCH-2 IF VALID-RECORD WRITE REPORT-RECORD FROM BATCH-2-RECORD END-IF. FINALIZATION. CLOSE DATA-FILE CLOSE REPORT-FILE.

RESET clause enables file reuse for multiple batch operations.

Multiple File Reset

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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
* Multiple file reset scenario PROCEDURE DIVISION. MULTI-FILE-PROCESSING. PERFORM INITIALIZATION PERFORM PROCESS-MULTIPLE-FILES PERFORM RESET-ALL-FILES PERFORM REPROCESS-FILES PERFORM FINALIZATION STOP RUN. INITIALIZATION. OPEN INPUT FILE-1, FILE-2, FILE-3 OPEN OUTPUT OUTPUT-FILE. PROCESS-MULTIPLE-FILES. DISPLAY "Processing multiple files..." PERFORM UNTIL ALL-FILES-PROCESSED PERFORM READ-AND-PROCESS-FILES END-PERFORM. READ-AND-PROCESS-FILES. READ FILE-1 AT END MOVE "Y" TO FILE-1-EOF NOT AT END PERFORM PROCESS-FILE-1-RECORD ON EXCEPTION PERFORM HANDLE-FILE-1-ERROR END-READ READ FILE-2 AT END MOVE "Y" TO FILE-2-EOF NOT AT END PERFORM PROCESS-FILE-2-RECORD ON EXCEPTION PERFORM HANDLE-FILE-2-ERROR END-READ READ FILE-3 AT END MOVE "Y" TO FILE-3-EOF NOT AT END PERFORM PROCESS-FILE-3-RECORD ON EXCEPTION PERFORM HANDLE-FILE-3-ERROR END-READ. RESET-ALL-FILES. DISPLAY "Resetting all files..." RESET FILE-1, FILE-2, FILE-3 IF FILE-1-STATUS = "00" AND FILE-2-STATUS = "00" AND FILE-3-STATUS = "00" DISPLAY "All files reset successfully" ELSE DISPLAY "One or more files failed to reset" STOP RUN END-IF. REPROCESS-FILES. DISPLAY "Reprocessing files..." PERFORM UNTIL ALL-FILES-REPROCESSED PERFORM READ-AND-REPROCESS-FILES END-PERFORM. FINALIZATION. CLOSE FILE-1, FILE-2, FILE-3 CLOSE OUTPUT-FILE.

RESET clause enables multiple file reset for batch processing.

Debugging with RESET

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
54
55
56
57
58
59
60
61
62
* Debugging scenario with RESET PROCEDURE DIVISION. DEBUG-PROCESSING. PERFORM INITIALIZATION PERFORM DEBUG-FILE-OPERATIONS PERFORM FINALIZATION STOP RUN. INITIALIZATION. OPEN INPUT DEBUG-FILE OPEN OUTPUT DEBUG-LOG. DEBUG-FILE-OPERATIONS. DISPLAY "Starting debug file operations..." * First read operation READ DEBUG-FILE NOT AT END DISPLAY "First read successful" PERFORM LOG-SUCCESS ON EXCEPTION DISPLAY "First read failed: " FILE-STATUS PERFORM LOG-ERROR END-READ * Reset file status for clean testing RESET DEBUG-FILE DISPLAY "File reset for second test" * Second read operation READ DEBUG-FILE NOT AT END DISPLAY "Second read successful" PERFORM LOG-SUCCESS ON EXCEPTION DISPLAY "Second read failed: " FILE-STATUS PERFORM LOG-ERROR END-READ * Reset again for third test RESET DEBUG-FILE DISPLAY "File reset for third test" * Third read operation READ DEBUG-FILE NOT AT END DISPLAY "Third read successful" PERFORM LOG-SUCCESS ON EXCEPTION DISPLAY "Third read failed: " FILE-STATUS PERFORM LOG-ERROR END-READ. LOG-SUCCESS. WRITE DEBUG-LOG-RECORD FROM "SUCCESS: File operation completed". LOG-ERROR. WRITE DEBUG-LOG-RECORD FROM "ERROR: File operation failed". FINALIZATION. CLOSE DEBUG-FILE CLOSE DEBUG-LOG.

RESET clause enables clean debugging by clearing file status.

Best Practices and Tips

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

RESET Best Practices

  • Check file status after RESET - Verify reset was successful
  • Use for error recovery - Clear errors before retrying
  • Implement proper error handling - Address root causes
  • Test with different file types - Verify behavior
  • Document reset operations - Record when and why RESET is used
  • Monitor performance impact - Ensure RESET doesn't cause issues

Common Pitfalls to Avoid

PitfallProblemSolution
Not checking status after RESETUnreliable error recoveryAlways verify RESET success
Using RESET instead of fixing errorsMasking real problemsAddress root causes
Excessive RESET usagePerformance degradationUse RESET judiciously
Not testing with all file typesUnexpected behaviorTest thoroughly
Ignoring RESET failuresContinued errorsHandle RESET failures

Performance Considerations

  • Fast operation - RESET is typically very fast
  • Minimal overhead - Little impact on performance
  • Memory efficient - Doesn't allocate new resources
  • Error recovery - Enables continued processing
  • File reuse - Avoids reopen overhead

When to Use RESET vs Other Methods

ScenarioUse RESETUse Other Methods
Error recoveryYesNo
File reuseYesNo
Status clearingYesNo
File terminationNoYes (CLOSE)
Resource releaseNoYes (CLOSE)

RESET Clause Quick Reference

UsageSyntaxPurpose
Single file resetRESET file-nameReset one file
Multiple file resetRESET file1, file2Reset multiple files
With error handlingRESET file ON EXCEPTIONHandle reset errors
Status variable resetRESET status-varReset status indicators
Position resetRESET position-indicatorReset position indicators

Test Your Knowledge

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

  • To create new files
  • To reset file status and position indicators
  • To generate reset reports
  • To create program documentation

2. In which context is the RESET clause most commonly used?

  • FILE SECTION
  • PROCEDURE DIVISION
  • WORKING-STORAGE SECTION
  • ENVIRONMENT DIVISION

3. What happens when a RESET clause is executed?

  • File status is reset to initial state
  • File status and position indicators are reset
  • A reset file is created
  • Reset data is processed

4. What is the relationship between RESET and file status?

  • They are unrelated
  • RESET clears file status indicators
  • RESET is faster than other methods
  • They cannot be used together

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

  • RESET file-name
  • RESET file-status
  • RESET position-indicator
  • All of the above

Frequently Asked Questions