Opening RM File

I'm having trouble opening an RM/COBOL indexed file. This program is a very simple example of the issue. It opens an indexed file and then writes the file status from that open step to an output flat file. When this program is run in Visual Studio the file status is 00 but when the exe is run (either by double clicking the exe file or by running it in command prompt) it is 30.


I tried running Process Monitor (technet.microsoft.com/.../processmonitor.aspx) with a filter for any path containing "c:\temp\in-file". Leaving that while running the test program in Visual Studio, I see many processes show up. But then if I keep the monitoring going while running the exe, it shows no processes trying to access the input file, almost as if it never even tries to open the file.


What could be different about running this program in Visual Studio vs running the compiled exe?

      $SET CHECKNUM
      $SET DIALECT"RM"
      $SET IDXFORMAT"21"
       IDENTIFICATION DIVISION.
       PROGRAM-ID. Program1.
       ENVIRONMENT DIVISION.
       INPUT-OUTPUT SECTION.
       FILE-CONTROL.
       SELECT IN-FILE ASSIGN TO "c:\temp\in-file"
                  ORGANIZATION IS INDEXED
                  ACCESS MODE IS DYNAMIC
                  RECORD KEY IS IN-KEY
                  FILE STATUS IS FILESTAT.
       select out-file assign to "C:\temp\out-file"
           organization is line sequential.
       DATA DIVISION.
       FD  IN-FILE
           LABEL RECORD IS STANDARD
           DATA RECORD IS PL-POINTER-RECORD.
       01  IN-RECORD.
           02  IN-KEY.
               03  FILLER          PIC X(3).
               03  FILLER          PIC 9(3).
           02  FILLER              PIC 9(2).
      
       fd out-file.
       01 out-rec pic x(8).
          
       WORKING-STORAGE SECTION.

       01  FILESTAT                   PIC X(2).
       01  FILESTAT-EXTENDED REDEFINES FILESTAT.
           02  FILESTAT-EXT-1         PIC X.
           02  FILESTAT-EXT-2         PIC X.
           02  FILESTAT-EXT-2-BINARY REDEFINES FILESTAT-EXT-2 PIC 99 COMP-X.
       01  FILESTAT-EXT-2-BINARY-DISP PIC 9(03). 
      

       PROCEDURE DIVISION.
           open output out-file.
           OPEN INPUT IN-FILE.
           move filestat to out-rec. 
           write out-rec.
           close in-file out-file.
           EXIT PROGRAM.

Parents
  • When this program runs in Visual Studio, it opens the RM/COBOL file with FILE STATUS zero. Maybe I’m overlooking an error status and should try a USE statement. But, it appears there isn't an error opening the file, because the program is able to read the file.

     

    When this program runs outside Visual Studio, a non-zero FILE STATUS is returned when the RM/COBOL file is opened. And the program can't read any records. In that case, it appears not to need the USE statement to return a non-zero FILE STATUS.

     

    Perhaps this program simplifies the test:

              open output out-file.

              open output in-file.

              move FILESTAT to out-rec.

              write out-rec.

              move "AA" to in-record.

              write in-record.

              close in-file.

              open input in-file.

              move FILESTAT to out-rec.

              write out-rec.

              initialize in-record.

              read in-file next.

              move FILESTAT to out-rec.

              write out-rec.

              move IN-RECORD to out-rec.

              write out-rec.

              close in-file out-file.

     

    The contents of out-file after running in Visual Studio:

    00

    00

    00

    AA

     

    The contents of out-file after running the exe (the fourth record is spaces):

    30

    30

    47

     

     

    I appreciate the suggestion to try a USE statement. I haven’t written RM/COBOL programs and I wasn’t familiar with that syntax. I added this to the top of the procedure division:

           DECLARATIVES.

           OUT-FILE-IO-ERROR-HANDLING SECTION.

              USE AFTER STANDARD ERROR PROCEDURE ON IN-FILE.

              display "error " filestat.

              accept filestat from console.

           END DECLARATIVES.

           MAIN-PROGRAM SECTION.

     

    Running in Visual Studio, it never hits the USE error section. Running the exe outside Visual Studio results in the following displays on the screen:

    error 30

    error 48

    error 42

    error 30

    error 47

    error 42

     

    The question remains: Why is this program working differently in Visual Studio from outside Visual Studio?

Reply
  • When this program runs in Visual Studio, it opens the RM/COBOL file with FILE STATUS zero. Maybe I’m overlooking an error status and should try a USE statement. But, it appears there isn't an error opening the file, because the program is able to read the file.

     

    When this program runs outside Visual Studio, a non-zero FILE STATUS is returned when the RM/COBOL file is opened. And the program can't read any records. In that case, it appears not to need the USE statement to return a non-zero FILE STATUS.

     

    Perhaps this program simplifies the test:

              open output out-file.

              open output in-file.

              move FILESTAT to out-rec.

              write out-rec.

              move "AA" to in-record.

              write in-record.

              close in-file.

              open input in-file.

              move FILESTAT to out-rec.

              write out-rec.

              initialize in-record.

              read in-file next.

              move FILESTAT to out-rec.

              write out-rec.

              move IN-RECORD to out-rec.

              write out-rec.

              close in-file out-file.

     

    The contents of out-file after running in Visual Studio:

    00

    00

    00

    AA

     

    The contents of out-file after running the exe (the fourth record is spaces):

    30

    30

    47

     

     

    I appreciate the suggestion to try a USE statement. I haven’t written RM/COBOL programs and I wasn’t familiar with that syntax. I added this to the top of the procedure division:

           DECLARATIVES.

           OUT-FILE-IO-ERROR-HANDLING SECTION.

              USE AFTER STANDARD ERROR PROCEDURE ON IN-FILE.

              display "error " filestat.

              accept filestat from console.

           END DECLARATIVES.

           MAIN-PROGRAM SECTION.

     

    Running in Visual Studio, it never hits the USE error section. Running the exe outside Visual Studio results in the following displays on the screen:

    error 30

    error 48

    error 42

    error 30

    error 47

    error 42

     

    The question remains: Why is this program working differently in Visual Studio from outside Visual Studio?

Children
No Data