title: COBOL record not writing to text file
body: <p>I'm trying to make a simple COBOL program that takes user inputs and writes them to a .txt file. My program successfully creates a .txt file, however, it fails to record any of the input, and for the life of me I can't figure out why. I want it to repeatedly take user input until specified not to and write that input to a text file.</p>
  
  <p>This is what I have:</p>
  
  <pre><code>   ENVIRONMENT DIVISION.
     INPUT-OUTPUT SECTION.
     FILE-CONTROL.
         SELECT TEST-FILE
             ASSIGN TO "C:\Users\Patrick\Desktop\TESTFILE.TXT"
             ORGANIZATION IS LINE SEQUENTIAL.
  
     DATA DIVISION.
     FILE SECTION.
     FD  TEST-FILE.
     01  TEST-RECORD         PIC X(25).
  
  
     WORKING-STORAGE SECTION.
     01 CONT                 PIC A(1).
     01  TEST-DETAIL.
         05  ITEM-NUMBER      PIC 9(7).
         05  FILLER           PIC X(5) VALUE SPACES.
         05  ITEM-PRICE       PIC 9(4).
  
     PROCEDURE DIVISION.
     PROGRAM-CONTROL.
         PERFORM OPEN-FILE.
         PERFORM GET-RECORD UNTIL CONT = 'N'.
         PERFORM CLOSE-OUT-FILE.
         STOP RUN.
  
     OPEN-FILE.
         OPEN OUTPUT TEST-FILE.
  
     GET-RECORD.
         PERFORM PROMPT-USER.
         PERFORM WRITE-RECORD.
         PERFORM CHECK-NEXT-RECORD.
  
     PROMPT-USER.
         DISPLAY 'ENTER PART-NUMBER'.
             ACCEPT ITEM-NUMBER.
         DISPLAY 'ENTER ITEM-PRICE'.
             ACCEPT ITEM-PRICE.
  
     WRITE-RECORD.
         MOVE TEST-DETAIL TO TEST-RECORD.
         WRITE TEST-RECORD.
  
     CHECK-NEXT-RECORD.
         DISPLAY 'ENTER ANOTHER RECORD? Y/n'.
             ACCEPT CONT.
         IF CONT = 'n' THEN MOVE 'N' TO CONT.
  
     CLOSE-OUT-FILE.
         CLOSE TEST-FILE.
  
     PERFORM PROGRAM-CONTROL.
  </code></pre>
  
  <p>Another thing I notice, is that if I move WRITE-RECORD out of GET-RECORD and into PROGRAM-CONTROL, like so</p>
  
  <pre><code>   PROGRAM-CONTROL.
         PERFORM OPEN-FILE.
         PERFORM GET-RECORD UNTIL CONT = 'N'.
         PERFORM WRITE-RECORD.
         PERFORM CLOSE-OUT-FILE.
         STOP RUN.
  </code></pre>
  
  <p>Then it will write to the .txt file, however, it will only write the last entry inputted (as would be expected). I'm guessing this is an issue with scope, but I don't understand it. Where am I going wrong, and can it work how I have it set up, or does the WRITE call need to be part of the PROGRAM-CONTROL? If so, how do I recursively call only the PROMPT-USER, WRITE-RECORD and CHECK-NEXT-RECORD portions so it works?</p>