Highlighted
Absent Member.
Absent Member.
2925 views

Opening RM File

Jump to solution

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 (https://technet.microsoft.com/en-us/sysinternals/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.

0 Likes
1 Solution

Accepted Solutions
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: Opening RM File

Jump to solution

Try running outside of Visual Studio in a Visual COBOL command prompt so that the PATH and COBDIR are set to point to the correct system folders and it will find acufh.dll

Navigate to Start menu-->Micro Focus Visual COBOL-->Tools-->Visual COBOL 32-bit Command prompt.

When I test your program like this it runs fine.

View solution in original post

0 Likes
7 Replies
Highlighted
Absent Member.
Absent Member.

RE: Opening RM File

Jump to solution

I did another test to prove there isn't a problem with the input file I'm using, which was created by an RM/COBOL program. First, in Visual Studio, I executed the write-rm-file paragraph to create a new indexed file using Visual COBOL. There were no errors and the out-file showed filestat 00 when the program was done. Then I changed the * to perform read-rm-file. It worked, showing filestat 00 and in-rec "00000000". Then I tried the same test using the exe, outside Visual Studio. The first part of the test, write-rm-file, shows that the program couldn't even successfully open a new output indexed file. The filestat was 30 again.

      PROCEDURE DIVISION.

      start-program.

          perform read-rm-file.

     *    perform write-rm-file.

          goback.

      read-rm-file.

          open output out-file.

          OPEN INPUT IN-FILE.

          move filestat to out-rec.  

          write out-rec.

          read in-file next

          move IN-RECORD to out-rec.

          write out-rec.

          close in-file out-file.

      write-rm-file.

          open output out-file.

          open output in-file.

          move filestat to out-rec.

          write out-rec.

          move zeros to in-record.

          write in-record.

          move 1 to in-record.

          write in-record.

          close in-file out-file.

0 Likes
Highlighted
Absent Member.
Absent Member.

RE: Opening RM File

Jump to solution

This webpage (documentation.microfocus.com/.../index.jsp) suggested there could something wrong with the FD, so I cleaned up the indexed file FD and received the same results as above.

      FD  IN-FILE

          LABEL RECORD IS STANDARD

          DATA RECORD IS IN-RECORD

          record contains 8 characters.

      01  IN-RECORD.

          02  IN-KEY.

              03  FILLER          PIC X(3).

              03  FILLER          PIC 9(3).

          02  FILLER              PIC 9(2).

0 Likes
Highlighted
New Member.

RE: Opening RM File

Jump to solution

In my experience, the default configuration for RM/Cobol does not return a non-zero value for the FILE STATUS item EXCEPT if an applicable USE statement is specified and invoked.  I would presume that behavior carries over into VC.

Code what you mean, and mean what you code!

0 Likes
Highlighted
Absent Member.
Absent Member.

RE: Opening RM File

Jump to solution

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?

0 Likes
Highlighted
Absent Member.
Absent Member.

RE: Opening RM File

Jump to solution

The difference may be in locating the acufh.dll.  A value of binary zeroes is returned for the file status when a filetype(21) file cannot be opened because acufh.dll is not found.  As it currently works, this is not a fatal error and the program continues, returning the invalid status of binary zeroes.  A status of two ascii zeroes would indicate success, but two binary zeroes indicate nothing.  There is RPI 608828 for this issue, that is, when acufh.dll is not found the program continues as if there were no error other than returning the invalid status of binary zeroes. (Note: filetype(21), that is RM files, are accessed through acufh.dll, which must be loadable for I/O on RM files with Visual COBOL.)

0 Likes
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: Opening RM File

Jump to solution

Try running outside of Visual Studio in a Visual COBOL command prompt so that the PATH and COBDIR are set to point to the correct system folders and it will find acufh.dll

Navigate to Start menu-->Micro Focus Visual COBOL-->Tools-->Visual COBOL 32-bit Command prompt.

When I test your program like this it runs fine.

View solution in original post

0 Likes
Highlighted
Absent Member.
Absent Member.

RE: Opening RM File

Jump to solution

Thanks, Chris! That worked for me too.

Your suggestion led me to search for acufh.dll. And that led to several other helpful posts that will provide more flexibility than to have to run this program in the Visual COBOL command prompt:

community.microfocus.com/.../11137.aspx

community.microfocus.com/.../7441.aspx

community.microfocus.com/.../456.accessing-rm-data-files-from-managed-visual-cobol.aspx

In the end, I just needed to add one more compiler directive: $SET CALLFH"ACUFH". Now I can even use this program in a dll called from a web app.

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.