Highlighted
Absent Member.
Absent Member.
9628 views

Read file in COBOL

Jump to solution

Hello,

I got this: 

ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT F1 ASSIGN TO "test.dat".

I get this error at the last line: "Invalid ASSIGN name" which is "test.dat". I've also tried the whole file path but it still doesn't work. The file is in the same directory as the program file. Anything on this?

- Thomas

Tags (3)
0 Likes
1 Solution

Accepted Solutions
Highlighted
Absent Member.
Absent Member.

RE: Read file in COBOL

Jump to solution

thomasbn94

This will work for a flat file for INPUT, for OUTPUT and also for EXTEND

          SELECT FILEA

              ASSIGN TO 'C:\MyFolder\FILEA.txt'

              ORGANIZATION IS LINE SEQUENTIAL

              ACCESS IS SEQUENTIAL.

BTW, the use of quotes or apostrophes don't make any difference so long as you use them in pairs

You can have both in the one program no problem

VALUE 'ONE' and VALUE "ONE" means the same thing to the compiler

For an indexed file (some call it ISAM - Indexed Sequential Access Method) look in the documentation and vary the above sample code a little (lines 3 & 4)

View solution in original post

0 Likes
15 Replies
Highlighted
Contributor.
Contributor.

RE: Read file in COBOL

Jump to solution

You need to tell it what medium your file is on:

SELECT F1 ASSIGN TO DISK "TEST.DAT".

0 Likes
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: Read file in COBOL

Jump to solution

Hello Thomas,

I don't see anything wrong with the whole SELECT clause. Do you get the error when you compile or run the application? Can you attach a screenprint showing the error please.

Regards,

–Ғɑɳօ
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: Read file in COBOL

Jump to solution

I see two thing you may want to change, first remove the word DISK and change the double quits to single ones.

0 Likes
Highlighted
Absent Member.
Absent Member.

RE: Read file in COBOL

Jump to solution

One more thing, you may want to add       organization is line sequential.      following the file name.

0 Likes
Highlighted
Absent Member.
Absent Member.

RE: Read file in COBOL

Jump to solution

The whole program: puu.sh/.../07672df381.png

Compile-time error: puu.sh/.../493416ff0c.png

Whenever I get the file reading correct I can start to refine the program...

I did change from " to ' but I got the same error

- Thomas

0 Likes
Highlighted
Absent Member.
Absent Member.

RE: Read file in COBOL

Jump to solution

Hello,

I didn't read all the replies... here's with the DISK clause included:

puu.sh/.../ef499ac98f.png

I tried with the whole file path but i got the same error

- Thomas

0 Likes
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: Read file in COBOL

Jump to solution

Hello Thomas,

Thanks for providing the screenprints, but I still don't see anything that would cause this compiler error. I don't even see COBCH1588 in the documentation.

Attached is a very similar to your sample program. Can you please see if you can recreate the problem or not?

0181.ASSIGNissue.zip

Regards,

–Ғɑɳօ
0 Likes
Highlighted
Contributor.
Contributor.

RE: Read file in COBOL

Jump to solution

It looks like you're getting a file status of 35, which is a file not found.  If the file does not exist or if the ID that the program is running under doesn't have access to that file, when you open the file for INPUT you'll get this error.

Make sure the file exists.

0 Likes
Highlighted
Absent Member.
Absent Member.

RE: Read file in COBOL

Jump to solution

I copied the contents of NewData.cbl into a new source file in a new project and it compiled without errors. However, will "hello" be written into that file? I opened it after the program had executed and there was nothing there. The code in the screenshots above was written in COBOL for OS/390, which means that there's probably a syntax error. I stick to Visual COBOL for now... I compiled your program using Visual COBOL, but i still got unexpected resultat. Thanks in advance.

- Thomas

0 Likes
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: Read file in COBOL

Jump to solution

From the error message you are getting (as shown in your latest screen shot), it appears you may not have the environment set up correctly. Are you trying to execute the program at the command prompt?

Blair McDonald

0 Likes
Highlighted
Absent Member.
Absent Member.

RE: Read file in COBOL

Jump to solution

I did this: New project > empty project. Then new > file > program in Visual Studios.

I build it and run it from the IDE. Have I missed something very fundamental?

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.