title: 'WRITE not allowed' error received when file is open
body: <p>When running the code below, which outputs a report of all those who get bonuses based on input files, I get the error, 'WRITE not allowed, file not open for output (status = 48)' on ln 159.</p>
  
  <p>I have tried opening the file in the 500-HEADING module but receive an error saying 'file already open (status = 41)' and receive the original error with moving the OPEN statement around to the 100-MAIN module. Using I-O, INPUT-OUTPUT, and EXTEND return a syntax error.</p>
  
  <pre><code>       IDENTIFICATION DIVISION.
         PROGRAM-ID. ASSIGNMENT9_1_SORT.
         ENVIRONMENT DIVISION.
         INPUT-OUTPUT SECTION.
         FILE-CONTROL.
             SELECT PAYROLL-MASTER ASSIGN TO 'CH0901-UNSORTED.DAT'
             ORGANIZATION IS LINE SEQUENTIAL.
             SELECT WORK-FILE ASSIGN TO 'TEMP.DAT'
             ORGANIZATION IS LINE SEQUENTIAL.
             SELECT BONUS-REPORT ASSIGN TO 'BONUS REPORT SORTED.LST'
             ORGANIZATION IS LINE SEQUENTIAL.
         DATA DIVISION.
         FILE SECTION.
         FD  PAYROLL-MASTER.
         01  PAYROLL-REC.
             05 EMP-NO-IN                 PIC X(5).
             05 NAME-IN                   PIC X(20).
             05 TERRITORY-NO-IN           PIC XX.
             05 OFFICE-NO-IN              PIC XX.
             05 ANNUAL-SALARY-IN          PIC 9(6).
             05                           PIC X(29).
             05 DATE-HIRED-IN.
                  10 MONTH-IN             PIC 99.
                  10 DAY-IN               PIC 99.
                  10 YEAR-IN              PIC 9999.
             05                           PIC X(10).
         FD  BONUS-REPORT.
         01  BONUS-PRINT                  PIC X(80).
         SD  WORK-FILE.
         01  SORT-REC.
             05 EMP-NO                    PIC X(5).
             05 S-NAME                    PIC X(20).
             05 TERR                      PIC XX.
             05 OFFICE                    PIC XX.
             05 ANNUAL-SALARY             PIC 9(6).
             05                           PIC X(29).
             05 DATE-HIRED.
                  10 S-MONTH              PIC 99.
                  10 S-DAY                PIC 99.
                  10 S-YEAR               PIC 9999.
             05                           PIC X(10).
         WORKING-STORAGE SECTION.
         01  BONUS-REC.
             05 EMP-NO-OUT                PIC X(5).
             05 NAME-OUT                  PIC X(20).
             05 TERRITORY-NO-OUT          PIC XX.
             05 OFFICE-NO-OUT             PIC XX.
             05 ANNUAL-SALARY-OUT         PIC 9(6).
             05                           PIC X(29).
             05 DATE-HIRED-OUT.
                 10 MONTH-OUT             PIC 99.
                 10 DAY-OUT               PIC 99.
                 10 YEAR-OUT              PIC 9999.
             05                           PIC X(10).
         01  WS-DATE.
             05 WS-YEAR                   PIC 9999.
             05 WS-MONTH                  PIC 99.
             05 WS-DAY                    PIC 99.
         01  HEADER1.
             05                           PIC X(40) VALUE SPACES.
             05                           PIC X(15) VALUE 'BONUS REPORT'.
             05                           PIC X(5) VALUE SPACES.
             05                           PIC X(5) VALUE 'PAGE '.
             05 PAGE-NO                   PIC 99 VALUE 1.
             05                           PIC XXX.
             05 TODAYS-DATE.
                10 MONTH-FIELD            PIC 99.
                10                        PIC X VALUE '/'.
                10 DAY-FIELD              PIC XX.
                10                        PIC X VALUE '/'.
                10 YEAR-FIELD             PIC 9999.
         01  BLANK-LINE                          PIC X(80).
         01  FIRST-RECORD                 PIC X VALUE 'Y'.
         01  HEADER2.
             05                           PIC X(10) VALUE SPACES.
             05                           PIC X(13) VALUE 'TERRITORY --'.
             05 TERRITORY-NO              PIC 99.
         01  HEADER3.
             05                           PIC X(20) VALUE SPACES.
             05                           PIC X(10) VALUE 'OFFICE --'.
             05 OFFICE-NO                 PIC 99.
         01  HEADER4.
             05                           PIC X(10) VALUE SPACES.
             05                           PIC X(15) VALUE 'EMPLOYEE NAME'.
             05                           PIC X(5) VALUE SPACES.
             05                           PIC X(5) VALUE 'BONUS'.
         01  DATA1.
             05                           PIC X(6) VALUE SPACES.
             05 NAME                      PIC X(20).
             05                           PIC XXXX.
             05 BONUS                     PIC $ZZ,ZZZ.99 VALUE ZEROES.
         01  ARE-THERE-MORE-RECORDS       PIC X VALUE 'Y'.
         01  LINE-COUNT                   PIC 99 VALUE 1.
  
         PROCEDURE DIVISION.
         100-MAIN.
             SORT WORK-FILE
               ON ASCENDING KEY TERR
               ON ASCENDING KEY OFFICE
               USING PAYROLL-MASTER
               GIVING BONUS-REPORT
             PERFORM 200-INPUT
             STOP RUN.
  
         200-INPUT.
             OPEN INPUT BONUS-REPORT
             MOVE FUNCTION CURRENT-DATE TO WS-DATE
             MOVE WS-YEAR TO YEAR-FIELD
             MOVE WS-MONTH TO MONTH-FIELD
             MOVE WS-DAY TO DAY-FIELD
             PERFORM UNTIL ARE-THERE-MORE-RECORDS = 'N'
                  READ BONUS-REPORT NEXT RECORD
                     AT END
                        MOVE 'N' TO ARE-THERE-MORE-RECORDS
                     NOT AT END
                        PERFORM 300-MOVE
                        PERFORM 400-CALC
                  END-READ
             CLOSE BONUS-REPORT
             END-PERFORM.
  
         300-MOVE.
             MOVE EMP-NO-IN TO EMP-NO-OUT
             MOVE NAME-IN TO NAME-OUT
             MOVE TERRITORY-NO-IN TO TERRITORY-NO-OUT
             MOVE OFFICE-NO-IN TO OFFICE-NO-OUT
             MOVE ANNUAL-SALARY-IN TO ANNUAL-SALARY-OUT
             MOVE DATE-HIRED-IN TO DATE-HIRED-OUT.
  
         400-CALC.
             MOVE ZEROES TO BONUS
             IF YEAR-OUT IS LESS THAN 1994
                 COMPUTE BONUS = ANNUAL-SALARY-OUT * 0.10
             END-IF
             EVALUATE TRUE
               WHEN FIRST-RECORD = 'Y'
                  MOVE TERRITORY-NO-OUT TO TERRITORY-NO
                  MOVE OFFICE-NO-OUT TO OFFICE-NO
                  PERFORM 500-HEADING
                  MOVE NAME-OUT TO NAME
                  WRITE BONUS-PRINT FROM DATA1
                  ADD 1 TO LINE-COUNT
                  MOVE 'N' TO FIRST-RECORD
               WHEN FIRST-RECORD = 'N'
                  MOVE TERRITORY-NO-OUT TO TERRITORY-NO
                  MOVE OFFICE-NO-OUT TO OFFICE-NO
                  MOVE NAME-OUT TO NAME
                  IF LINE-COUNT &gt; 10
                     MOVE 1 TO LINE-COUNT
                     ADD 1 TO PAGE-NO
                     PERFORM 500-HEADING
                  END-IF
             WRITE BONUS-PRINT FROM DATA1
             ADD 1 TO LINE-COUNT
             END-EVALUATE.
  
         500-HEADING.
             WRITE BONUS-PRINT FROM BLANK-LINE
             WRITE BONUS-PRINT FROM HEADER1
             WRITE BONUS-PRINT FROM BLANK-LINE
             WRITE BONUS-PRINT FROM HEADER2
             WRITE BONUS-PRINT FROM BLANK-LINE
             WRITE BONUS-PRINT FROM HEADER3
             WRITE BONUS-PRINT FROM BLANK-LINE
             WRITE BONUS-PRINT FROM BLANK-LINE
             WRITE BONUS-PRINT FROM HEADER4.
  `
  </code></pre>