Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I/O Operation Failure

Status
Not open for further replies.

acallist

Programmer
Feb 4, 2003
8
CA
I wrote a simple COBOL program to read an input file, do some conversions, and to generate an output file from within the Code. However, I recieve an I/O operation failure error and the file is not created. If I manually create a blank physical file before hand with the same name, it becomes populated with the correct data, so the program logic appears to be ok. If I change the ASSIGN TO statement to point to a printer, the spool file also has the correct data. The file status in the job log on the input file is 00, and the output file status is ***? Any ideas? below is the code...any help would be greatly appreciated.

IDENTIFICATION DIVISION.
*===============================================================
PROGRAM-ID. BAC344ASS1.
****************************************************************
* *
* Purpose: This program will read the Old Vendor file, convert*
* Country Codes to names, ignore certain records, *
* and reorganize fields to produce a modified *
* Vendor File. *
* Input: OLDFILE (Vendor File) *
* *
* Output: NEWFILE (Modified Vendor File) *
* *
*--------------------------------------------------------------*
* * *
****************************************************************
*===============================================================
ENVIRONMENT DIVISION.
*===============================================================
INPUT-OUTPUT SECTION.
*---------------------------------------------------------------
FILE-CONTROL.
*---------------------------------------------------------------
SELECT ORIGINAL
ASSIGN TO DISK-OLDFILE
ORGANIZATION IS SEQUENTIAL
ACCESS MODE IS SEQUENTIAL.

SELECT NEWONE
ASSIGN TO DISK-WAZUP
ORGANIZATION IS SEQUENTIAL.
*===============================================================
DATA DIVISION.
*===============================================================
FILE SECTION.
*---------------------------------------------------------------

FD ORIGINAL
RECORD CONTAINS 56 CHARACTERS
DATA RECORD IS OLDFILER.

01 OLDFILER.

05 VENDORCODE PIC X(5).
05 VENDORNAME PIC X(20).
05 CFIRSTNAME PIC X(10).
05 CLASTNAME PIC X(10).
05 CNTRYCODE PIC X(1).
05 PHONENO PIC S9(10).

FD NEWONE
RECORD CONTAINS 72 CHARACTERS
DATA RECORD IS NEWONER.

01 NEWONER.
05 N-VENDORCODE PIC X(5).
05 N-VENDORNAME PIC X(20).
05 N-CLASTNAME PIC X(10).
05 N-CFIRSTNAME PIC X(10).
05 N-CNTRYNAME PIC X(10).
05 N-PHONENO PIC S9(10).
05 FILLER PIC X(7).
*---------------------------------------------------------------
WORKING-STORAGE SECTION.
*---------------------------------------------------------------

01 WORKING-STORAGE-REC.
05 WS-FLAGS-VARIABLES.
10 WS-DEL-REC PIC X(01).

05 WS-FILE-FLAG PIC X(01).

05 WS-COUNTERS-VARIABLES.
10 WS-ERROR PIC S9(2) VALUE ZERO.

05 WS-TEMP-RECORD.
10 NEW-VENDORC PIC X(5).
10 NEW-VENDORN PIC X(20).
10 NEW-LASTN PIC X(10).
10 NEW-FIRSTN PIC X(10).
10 NEW-COUNTRYN PIC X(10).
10 NEW-PHONENO PIC S9(10).
10 FILLER PIC X(7).

*=====================================================
PROCEDURE DIVISION.
*=====================================================
A000-MAIN-LINE.
PERFORM B100-OPEN-FILES.
MOVE "Y" TO WS-FILE-FLAG.
PERFORM C100-READ-FILES.
IF WS-FILE-FLAG = "Y"
PERFORM UNTIL WS-FILE-FLAG = "N"
PERFORM D100-COUNTRY
PERFORM E100-WRITE-FILES
PERFORM C100-READ-FILES
END-PERFORM
END-IF.
PERFORM Z100-END-PROCESS.

*------------------------------------------------------------*
B100-OPEN-FILES.
*------------------------------------------------------------*
OPEN INPUT ORIGINAL
EXTEND NEWONE.

*------------------------------------------------------------*
C100-READ-FILES.
*------------------------------------------------------------*
READ ORIGINAL
AT END
MOVE "N" TO WS-FILE-FLAG
END-READ.

*------------------------------------------------------------*
D100-COUNTRY.
*------------------------------------------------------------*
EVALUATE CNTRYCODE
WHEN 1
MOVE "Canada" TO NEW-COUNTRYN
WHEN 2
MOVE "USA" TO NEW-COUNTRYN
WHEN 3
MOVE "Brazil" TO NEW-COUNTRYN
WHEN 4
MOVE "Mexico" TO NEW-COUNTRYN
WHEN 5
MOVE "Bermuda" TO NEW-COUNTRYN
WHEN 6
MOVE "Spain" TO NEW-COUNTRYN
WHEN 7
MOVE "China" TO NEW-COUNTRYN
WHEN 8
MOVE "Japan" TO NEW-COUNTRYN
WHEN 9
MOVE "Italy" TO NEW-COUNTRYN
WHEN OTHER
MOVE "Not Defined" TO NEW-COUNTRYN
END-EVALUATE.

*------------------------------------------------------------*
E100-WRITE-FILES.
*------------------------------------------------------------*
MOVE VENDORCODE TO N-VENDORCODE.
MOVE VENDORNAME TO N-VENDORNAME.
MOVE CLASTNAME TO N-CLASTNAME.
MOVE CFIRSTNAME TO N-CFIRSTNAME.
MOVE NEW-COUNTRYN TO N-CNTRYNAME.
MOVE PHONENO TO N-PHONENO.

WRITE NEWONER.

*------------------------------------------------------------*
Z100-END-PROCESS.
*------------------------------------------------------------*
CLOSE ORIGINAL
NEWONE.
STOP RUN.
 
Thanks for the tip mrregan...but just out of curiosity, will this SELECT OPTIONAL statement still create the newfile?
 
Hello,

The use of SELECT OPTIONAL with EXTEND tells COBOL that the file may not exist when the program starts. If you leave it out it will not create it. But, with it in, it will.
 
Thank you very much TCSBIZ..just going over to the 400 to try it...hopefully willl work..will find out later on....I appreciate the tip...
 
Or try changing

Code:
OPEN ... EXTEND NEWONE.

to

Code:
OPEN ... [bold]OUTPUT[/bold] NEWONE.

You might also get some useful information by including a FILE STATUS clause in the SELECT statements and then display that information when you encounter an error in the program.

Good luck, "Code what you mean,
and mean what you code"

Razalas
 
Hi,

What environment/compiler are you using?
Also, to recreate the exact alignment you use in your code for your Tek-Tip post, you can use the following:

(code)
put your code here
(/code)

But, instead of parens () use square brackets []. If you submit code snippets, you can repeat the process as many times as you like and intersperse regular text bettween the code snippets.

Regards, Jack.
 
I tried using a simple OPEN OUTPUT NEWONE, that didn't work, same error (I/O). Then I tried the SELECT OPTIONAL, and recieved an error MCH3601 "Pointer not set for location referenced. " Any help would be great.

Thanks,

Angelo
 
The Issue is now fixed. Thanks to everyone for their help. Turns out, because the output file had to be dynamically created, a COBOL bound program compilation was required. By compiling with the command CRTBNDCBLPGM and adding a compiler option for *CRTF, it allowed the file to be generated from within the code.
 
"because the output file had to be dynamically created"

For future reference, what platform was this compiled/run on, that programs that create files must be compiled differently from those that do not?

Or did I miss something? [upsidedown] "Code what you mean,
and mean what you code"

Razalas
 
Sorry my bad...its on AS/400..its my first time posting here so I may miss some details..
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top