Page 1 of 2

File Status Error "46"

PostPosted: Wed Jan 04, 2012 4:02 pm
by kumarajv
00000-MAIN.
PERFORM 10000-INITIALIZE-PARA THRU 10000-EXIT
PERFORM 20000-PROCESS-PARA THRU 20000-EXIT
PERFORM 30000-TERMINATE-PARA THRU 30000-EXIT
GOBACK.
00000-EXIT.
GOBACK.

10000-INITIALIZE-PARA.
DISPLAY '10000-INITIALIZATION'
OPEN INPUT INFILE1
INFILE2
OPEN OUTPUT OUT-FILE
INITIALIZE OUT-RECORD.
10000-EXIT.
EXIT.

20000-PROCESS-PARA.
DISPLAY ' 20000-PROCESS-PARA'
PERFORM 21000-READ-INFILE1 THRU 21000-EXIT
UNTIL EOF-FILE1 = 'Y' .
20000-EXIT.
EXIT.

21000-READ-INFILE1.
DISPLAY '21000-READ-FILE1'
MOVE 'N' TO EOF-FILE2
READ INFILE1 AT END
MOVE 'Y' TO EOF-FILE1
END-READ
ADD 1 TO FILE1-READ.
MOVE EMP-NO TO WS-EMPNO
PERFORM 21100-READ-INFILE2 THRU 21100-EXIT
UNTIL EOF-FILE2 = 'Y'.
21000-EXIT.
EXIT.

21100-READ-INFILE2.
DISPLAY '21100-READ-FILE2'
READ INFILE2 AT END
MOVE 'Y' TO EOF-FILE2
END-READ
ADD 1 TO FILE2-READ.
MOVE EMP-ID TO WS-EMPID
PERFORM 22000-MATCH-DATA THRU 22000-EXIT.
21100-EXIT.
EXIT.

22000-MATCH-DATA.
DISPLAY '22000-MATCH-DATA'
DISPLAY 'FILE1 RECS READ = ' FILE1-READ.
DISPLAY 'FILE2 RECS READ = ' FILE2-READ.
IF WS-EMPNO = WS-EMPID
PERFORM 22100-FILES-MATCH THRU 22100-EXIT.
22000-EXIT.
EXIT.

22100-FILES-MATCH.
DISPLAY '22100-FILES-MATCH'
INITIALIZE OUT-RECORD
MOVE EMP-NO TO OUT-EMP-NO
MOVE EMP-NAME TO OUT-EMP-NAME
MOVE EMP-SAL TO OUT-EMP-SAL
MOVE EMP-DEG TO OUT-EMP-DEG
WRITE OUT-RECORD.
22100-EXIT.
EXIT.

30000-TERMINATE-PARA.
DISPLAY '30000-TERMINATE-PARA'
CLOSE OUT-FILE
INFILE1
INFILE2 .
30000-EXIT. EXIT.

Iam getting the file status code as 46:
1) The file 1 first record is reading after that file 2 is redaing until the eof
2) the file 1 second record is reading that time 2 nd file as appeared the file status code 46. Can anyone tell me how to solve this issue

Re: How to solve File status code 46 for the below code

PostPosted: Wed Jan 04, 2012 4:16 pm
by enrico-sorichetti
learn to post using the code tags
it makes things more readable for people willing to help You!

Re: How to solve File status code 46 for the below code

PostPosted: Wed Jan 04, 2012 4:22 pm
by kumarajv
Sure. i will follow that one and this is for matching the files program for unsorted files

Re: How to solve File status code 46 for the below code

PostPosted: Wed Jan 04, 2012 4:24 pm
by enrico-sorichetti
You will get little help for such an illogic requirement...

Re: How to solve File status code 46 for the below code

PostPosted: Wed Jan 04, 2012 4:55 pm
by BillyBoyo
If you have unsorted files, then every key on one of the files must match on the other.

Then you use the file which must only have matches as the "driver". Read a record on that file, read until you find a match on the other file. Process. Read next on driver file, etc. You can have duplicate keys, but if you do you have some other things to consider.

As enrico alludes, usually there is something which you can sequence the files on. When you haven't got anything, you have to have a match for it to work.

Re: How to solve File status code 46 for the below code

PostPosted: Wed Jan 04, 2012 5:06 pm
by kavithathumba
The same thing is done in the above but the issue is coming i think
(i) First File first record has been taken and it is looping for the second file all the records this time it is executing.
(ii) First file second record has been taken and second file looping is not working here and it is abending with file status 46
iam not sure how to solve this one if u know plz let me know also..
:-)

Re: How to solve File status code 46 for the below code

PostPosted: Wed Jan 04, 2012 5:11 pm
by BillyBoyo
You have to stop reading the second file when you find a match on the first file. That is the point of the "match key" having to exist. If you read to end of tile 2, then, yes, you will get the 46 for the first file 2 read for the second file 1 record.

Re: How to solve File status code 46 for the below code

PostPosted: Wed Jan 04, 2012 5:14 pm
by enrico-sorichetti
so if Your first file has 1000 records and Your second file has 1000 records
You plan to open and close the second file 1000 times and issue 1000*500 reads ( statistical average )

OMG :shock:

Re: How to solve File status code 46 for the below code

PostPosted: Wed Jan 04, 2012 6:19 pm
by kumarajv
yes Kavitha ur right that's what happening here.

billy, But the first file record record 1 is not matching with the second file any records.so, it has to take first file second record and have to check with all the records in second file it is taking second record but not reading the second file records. There is no match then how to stop the second file

Re: How to solve File status code 46 for the below code

PostPosted: Wed Jan 04, 2012 6:57 pm
by BillyBoyo
PERFORM 21100-READ-INFILE2 THRU 21100-EXIT
UNTIL EOF-FILE2 = 'Y'


You are not stopping when you get a match.

As I said before, if the driver file has data which does not match the other file, then it is not going to work. The data have to match, everything on at least one of the files.