View previous topic :: View next topic
|
Author |
Message |
bittu Warnings : 1 New User
Joined: 07 Jan 2007 Posts: 19 Location: Bangalore
|
|
|
|
Hi,
I am comparing two sequential files on the basis of program-name and their size. if program-names and sizes are same then just display a message else i need to write the contents from both the input file to the output file. i m getting return code 00. but my program is not writing the records in the output file. my coe is like this-----
Code: |
OPEN INPUT TB170-FILE, TI21-FILE.
OPEN OUTPUT REPORT-FILE.
PERFORM READ-TB170-FILE THRU READ-TB170-FILE-EXIT
UNTIL EOF = "Y".
CLOSE TB170-FILE, TI21-FILE, REPORT-FILE.
STOP RUN.
READ-TB170-FILE.
READ TB170-FILE AT END MOVE "Y" TO EOF.
IF DEV-STATUS NOT = "00"
DISPLAY "TB170 FILE IS NOT OPENED" DEV-STATUS
END-IF.
MOVE "N" TO EOF.
PERFORM READ-TI21-FILE THRU READ-TI21-FILE-EXIT
UNTIL EOF = "Y".
READ-TB170-FILE-EXIT.
EXIT.
READ-TI21-FILE.
READ TB170-FILE AT END MOVE "Y" TO EOF.
IF TEST-STATUS NOT = "00"
DISPLAY "TI21 FILE IS NOT OPENED" TEST-STATUS
END-IF.
IF (TB-NAME = TI-NAME) AND (TB-SIZE = TI-SIZE)
DISPLAY "THE PROGRAM NAME AND SIZE IS SAME"
ELSE
IF (TB-NAME = TI-NAME) AND (TB-SIZE < TI-SIZE)
PERFORM REPORT-WRITE-FROM-BOTH1
ELSE
IF (TB-NAME = TI-NAME) AND (TB-SIZE > TI-SIZE)
PERFORM REPORT-WRITE-FROM-BOTH1
END-IF
END-IF
END-IF.
READ-TI21-FILE-EXIT.
EXIT.
REPORT-WRITE-FROM-BOTH1.
MOVE TB-SIZE TO R-TB-SIZE.
MOVE TB-NAME TO R-TB-NAME.
MOVE TB-MONTH TO R-TB-MONTH.
MOVE TB-DATE TO R-TB-DATE.
MOVE TI-SIZE TO R-TI-SIZE.
MOVE TI-MONTH TO R-TI-MONTH.
MOVE TI-DATE TO R-TI-DATE.
WRITE REPORT-REC. |
any help in this program would be appreciated that why this program is not writing the output.
thanx |
|
Back to top |
|
|
ksk
Active User
Joined: 08 Jun 2006 Posts: 355 Location: New York
|
|
|
|
Hi,
What do u want to do if program names are differnet but sizes are same and both are different? This might be happening with ur input files.
Just display the program names and sizes and see what is happening. |
|
Back to top |
|
|
logeswarank Warnings : 1 New User
Joined: 15 Oct 2006 Posts: 22 Location: Chennai
|
|
|
|
Hi,
In your case you are checking both input files program name are same and the sizes are different,may be your input files contains different program names better post your sample input datas for two input files.Then only we are able to give solution to your problem. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
Hello,
If you have 2 files and need to "match" them against each other, you need to
1. sort both files into the same sequence.
2. download the 2-file match/merge sample code from the "sticky" in this forum.
3. change the sample code for your specifics.
4. post back here if your version of the match/merge code does not work or if you have questions.
The code you posted will not "match" the 2 files as i believe you need. |
|
Back to top |
|
|
bittu Warnings : 1 New User
Joined: 07 Jan 2007 Posts: 19 Location: Bangalore
|
|
|
|
hi logeswarank,
sorry for replying late. but as of now i have two sequential files as input and one output sequential file. data in both the input files is as followed:
file-1
Code: |
111111 jul 22 12:30 program1
222222 jul 22 10:40 program2
333333 aug 25 11:20 program3
444444 sep 30 09:15 program4
555555 jan 25 08:20 program5
666666 dec 22 08:20 program6 |
file-2
Code: |
111111 jul 22 12:30 program1
444444 jul 22 10:40 program2
555555 aug 25 11:20 program3
666666 sep 11 08:20 program4
777777 jan 25 08:20 program5
888888 nov 28 08:20 program6 |
now i m getting the output but problem is that in the output it is repeating the last written record. the output for these two input file is:
Code: |
program2 222222 jul22 444444 jul22
program3 333333 aug25 555555 aug25
program4 444444 sep30 666666 sep11
program5 555555 jan25 777777 jan25
program6 666666 dec22 888888 nov28
program6 666666 dec22 888888 nov28 |
and my code is:
Code: |
PROCEDURE DIVISION.
0000-MAINLINE.
OPEN INPUT TB170-FILE, TI21-FILE.
IF DEV-STATUS NOT = "00"
DISPLAY "TB170 FILE IS NOT OPENED" DEV-STATUS
STOP RUN
END-IF.
IF TEST-STATUS NOT = "00"
DISPLAY "TI21 FILE IS NOT OPENED" TEST-STATUS
STOP RUN
END-IF.
OPEN OUTPUT REPORT-FILE.
IF TEST-STATUS NOT = "00"
DISPLAY "REPORT FILE IS NOT OPENED" REPORT-STATUS
STOP RUN
END-IF.
PERFORM READ-TB170-FILE THRU READ-TB170-FILE-EXIT
UNTIL EOF = "Y".
CLOSE TB170-FILE, TI21-FILE, REPORT-FILE.
STOP RUN.
READ-TB170-FILE.
READ TB170-FILE AT END MOVE "Y" TO EOF.
READ TI21-FILE AT END MOVE "Y" TO EOF.
PERFORM COMPARE-TB170-TI021 THRU COMPARE-EXIT.
READ-TB170-FILE-EXIT.
EXIT.
IF (TB-NAME = TI-NAME) AND (TB-SIZE = TI-SIZE)
DISPLAY "PROGRAM : " TI-NAME " SIZE : " TI-SIZE
ELSE
IF (TB-NAME = TI-NAME) AND (TB-SIZE NOT = TI-SIZE)
PERFORM REPORT-WRITE-FROM-BOTH-FILE
END-IF
END-IF.
COMPARE-EXIT.
EXIT.
REPORT-WRITE-FROM-BOTH-FILE.
MOVE TB-SIZE TO R-TB-SIZE.
MOVE TB-NAME TO R-TB-NAME.
MOVE TB-MONTH TO R-TB-MONTH.
MOVE TB-DATE TO R-TB-DATE.
MOVE TI-SIZE TO R-TI-SIZE.
MOVE TI-MONTH TO R-TI-MONTH.
MOVE TI-MONTH TO R-TI-MONTH.
MOVE TI-DATE TO R-TI-DATE.
WRITE REPORT-REC.
IF REPORT-STATUS NOT = "00"
DISPLAY "REPORT FILE IS NOT OPENED" REPORT-STATUS
END-IF. |
but it is repeating the last written record as i have shown u in my output file. plz let me know what changes or additions are required for this so that it will not repeat the last written record.
thanx |
|
Back to top |
|
|
guptae
Moderator
Joined: 14 Oct 2005 Posts: 1208 Location: Bangalore,India
|
|
|
|
Hi there,
Use the folloeing code
Code: |
PROCEDURE DIVISION.
0000-MAINLINE.
OPEN INPUT TB170-FILE, TI21-FILE.
IF DEV-STATUS NOT = "00"
DISPLAY "TB170 FILE IS NOT OPENED" DEV-STATUS
STOP RUN
END-IF.
IF TEST-STATUS NOT = "00"
DISPLAY "TI21 FILE IS NOT OPENED" TEST-STATUS
STOP RUN
END-IF.
OPEN OUTPUT REPORT-FILE.
IF TEST-STATUS NOT = "00"
DISPLAY "REPORT FILE IS NOT OPENED" REPORT-STATUS
STOP RUN
END-IF.
READ TB170-FILE AT END MOVE "Y" TO EOF.
READ TI21-FILE AT END MOVE "Y" TO EOF.
PERFORM READ-TB170-FILE THRU READ-TB170-FILE-EXIT
UNTIL EOF = "Y".
CLOSE TB170-FILE, TI21-FILE, REPORT-FILE.
STOP RUN.
READ-TB170-FILE.
PERFORM COMPARE-TB170-TI021 THRU COMPARE-EXIT.
READ TB170-FILE AT END MOVE "Y" TO EOF.
READ TI21-FILE AT END MOVE "Y" TO EOF.
READ-TB170-FILE-EXIT.
EXIT.
COMPARE-TB170-TI021
IF (TB-NAME = TI-NAME) AND (TB-SIZE = TI-SIZE)
DISPLAY "PROGRAM : " TI-NAME " SIZE : " TI-SIZE
ELSE
IF (TB-NAME = TI-NAME) AND (TB-SIZE NOT = TI-SIZE)
PERFORM REPORT-WRITE-FROM-BOTH-FILE
END-IF
END-IF.
COMPARE-EXIT.
EXIT.
REPORT-WRITE-FROM-BOTH-FILE.
MOVE TB-SIZE TO R-TB-SIZE.
MOVE TB-NAME TO R-TB-NAME.
MOVE TB-MONTH TO R-TB-MONTH.
MOVE TB-DATE TO R-TB-DATE.
MOVE TI-SIZE TO R-TI-SIZE.
MOVE TI-MONTH TO R-TI-MONTH.
MOVE TI-MONTH TO R-TI-MONTH.
MOVE TI-DATE TO R-TI-DATE.
WRITE REPORT-REC.
IF REPORT-STATUS NOT = "00"
DISPLAY "REPORT FILE IS NOT OPENED" REPORT-STATUS
END-IF. |
I have not done much changes in the code just i am reading the files befor checking end of file. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
Hello,
I don't have the time to go into this at depth just now, but i believe the code will not work in all cases. It may work for the posted sample data, but the "real" data may have conditions not present in the sample.
For starters, both files should NOT be read each iteration. One, the other, or both need to be read depending on the positioning in each file. When one file reaches AT END, it should no longer be read, but the other file must be read until AT END.
There is a "sticky" near the top of this COBOL forum that does a 2-file match/merge and is currently in production on multiple systems.
I'd suggest you download it and compare how it processes and either use it or modify this code to use the same concept. |
|
Back to top |
|
|
Devzee
Active Member
Joined: 20 Jan 2007 Posts: 684 Location: Hollywood
|
|
|
|
I would suggest if possible it's better to do the file comparison logic in SORT which will be efficient and easy. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
Hello,
Sorry, but no, i must disagree.
Somewhere between many and most of the "programs" being written in SORT are because the "programmer" has not learned programming basics (i.e. a 2-file match/merge). Rare is the business requirement that can be completely met by the sort product. Many, many processes need to read some kind of random data (vsam, database) or use some predefined array (copybook) or whatever and/or produce a "real" report that is beyond the capability of the sort products.
If 100% of a requirement can be met by the sort product alone, fine, but most of the ones i've seen use the sort to "match/merge" because the coder does not know how and there is other code on the front or on the back or both thereby using more people time for development and documentation as well as usually much more machine resources. |
|
Back to top |
|
|
Devzee
Active Member
Joined: 20 Jan 2007 Posts: 684 Location: Hollywood
|
|
|
|
I agree with you dick Scherrer.
I mentioned if possible otherwise code logic in COBOL program |
|
Back to top |
|
|
bittu Warnings : 1 New User
Joined: 07 Jan 2007 Posts: 19 Location: Bangalore
|
|
|
|
Hi guptae,
the code that u have added in my code is doing the same thing. it is repeating the last written record again.
the code added by u is:
READ TB170-FILE AT END MOVE "Y" TO EOF.
READ TI21-FILE AT END MOVE "Y" TO EOF.
before perform loop.
but it does not make any difference.
thanks |
|
Back to top |
|
|
saptagiri kintali
New User
Joined: 21 Sep 2007 Posts: 20 Location: chennai
|
|
|
|
PROCEDURE DIVISION.
0000-MAINLINE.
OPEN INPUT TB170-FILE, TI21-FILE.
IF DEV-STATUS NOT = "00"
DISPLAY "TB170 FILE IS NOT OPENED" DEV-STATUS
STOP RUN
END-IF.
IF TEST-STATUS NOT = "00"
DISPLAY "TI21 FILE IS NOT OPENED" TEST-STATUS
STOP RUN
END-IF.
OPEN OUTPUT REPORT-FILE.
IF TEST-STATUS NOT = "00"
DISPLAY "REPORT FILE IS NOT OPENED" REPORT-STATUS
STOP RUN
END-IF.
READ TB170-FILE AT END MOVE "Y" TO EOF.
READ TI21-FILE AT END MOVE "Y" TO EOF.
PERFORM READ-TB170-FILE THRU READ-TB170-FILE-EXIT
UNTIL EOF = "Y".
CLOSE TB170-FILE, TI21-FILE, REPORT-FILE.
STOP RUN.
READ-TB170-FILE.
PERFORM COMPARE-TB170-TI021 THRU COMPARE-EXIT.
READ TB170-FILE AT END MOVE "Y" TO EOF.
READ TI21-FILE AT END MOVE "Y" TO EOF.
READ-TB170-FILE-EXIT.
EXIT.
COMPARE-TB170-TI021
IF (TB-NAME = TI-NAME) AND (TB-SIZE = TI-SIZE)
DISPLAY "PROGRAM : " TI-NAME " SIZE : " TI-SIZE
ELSE
/* HERE CHECK FOR FILE STATUS LIKE (IF TEST-STAT=0 AND DEV-STAT =0)
IF (TB-NAME = TI-NAME) AND (TB-SIZE NOT = TI-SIZE)
PERFORM REPORT-WRITE-FROM-BOTH-FILE
END-IF
END-IF.
COMPARE-EXIT.
EXIT.
REPORT-WRITE-FROM-BOTH-FILE.
MOVE TB-SIZE TO R-TB-SIZE.
MOVE TB-NAME TO R-TB-NAME.
MOVE TB-MONTH TO R-TB-MONTH.
MOVE TB-DATE TO R-TB-DATE.
MOVE TI-SIZE TO R-TI-SIZE.
MOVE TI-MONTH TO R-TI-MONTH.
MOVE TI-MONTH TO R-TI-MONTH.
MOVE TI-DATE TO R-TI-DATE.
WRITE REPORT-REC.
IF REPORT-STATUS NOT = "00"
DISPLAY "REPORT FILE IS NOT OPENED" REPORT-STATUS
END-IF.
Ithink now u will get correct answer try it once...waiting for ur reply..[/b] |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
Hello,
Did you test the code you posted? I believe it will fail on some input coniditions.
Make some complete test data, run the code, and post the results. |
|
Back to top |
|
|
kvenkat_b4u
New User
Joined: 19 Feb 2007 Posts: 1 Location: hyderabad
|
|
|
|
Here the problem is End-of-file Condition........
For example your input is having 10 record.....u compared 10th record & written to output file...at that time E-O-F is not reached......
So your read must perform again ...now only E-O-F condition will occur....
Obviously your output structure contain last record...so you must check E-O-F (End of file condition) before writting to output...r else last record will be always occured Twice in output...............
Hope this will help you........... |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
Hello,
It is not merely an EOF issue.
Please compare the code in question with the sample code in the sticky and notice the differences.
Think of what will happen in one of the input files has 3 un-matched records in the middle of the file. There are many other conditions to consider as well. These do not all require "special" code to deal with. One simple set of code will "do it all".
It is not difficult, but many people do try to make it difficult. . . . |
|
Back to top |
|
|
Craq Giegerich
Senior Member
Joined: 19 May 2007 Posts: 1512 Location: Virginia, USA
|
|
|
|
dick scherrer wrote: |
It is not difficult, but many people do try to make it difficult. . . . |
And some of them make it very difficult. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
Hi Craig,
Possibly the worst one i had to "play" with was one that started badly and then got worse over the years. It was one of the "main" update programs for part of a payroll/personnel system.
By the time i was asked to look at it (it abended one night and the people responsible for the application could not figure what to do), the little beauty had 7 READs for the "master" file and 9 for the other. Every time a new combination of input data was discovered, they did a strange little dance and added more switches or reads to get around the discovery.
The version that was in production at the time was just under 2200 statements (IIRC). After puzzling over it for about 10 minutes, i sat down with the team lead and said that i'd re-write it if they could wait a day or so to run it. He agreed and with his help understanding the very little bit of "business code" in the program, the re-write took less than 400 statements (most of which was field definitions and data movement).
There were a few comments from people in that group concerned the new little module could not do everything that the original did. As it was a monthly job, we went back and reran the prior 6 months and compared the output files - exactly the same. |
|
Back to top |
|
|
bittu Warnings : 1 New User
Joined: 07 Jan 2007 Posts: 19 Location: Bangalore
|
|
|
|
THE REQUIREMENT IS:
THERE R TWO INPUT SORTED FILES(SEQUENTIAL). ONE OUT PUT FILE(SEQUENTIAL).
WE HAVE TO MATCH KEY FILED OF BOTH THE FILE.
IF KEY OF FILE1 IS < KEY OF FILE2 THEN WRITE THE RECORD FROM FILE1 ONLy TO
THE OUTPUT FILE(FILE3)
IF KEY OF FILE1 IS > KEY OF FILE2 THEN WRITE THE RECORD FROM FILE2 ONLy TO
THE OUTPUT FILE(FILE3)
IF KEY OF FILE1 IS = KEY OF FILE2 THEN WRITE THE RECORD FROM FILE1 AND
FILE2 BOTH OR SIMPLY DISPLAY A MESSAGE.
PERFORM MAIN-PROCESS UNTIL (EOF OF FILE1 AND EOF OF FILE2)
EVALUATE TRUE
WHEN KEY OF FILE1 < KEY OF FILE2
PERFORM READ-FILE1
IF EOF OF FILE1
PERFORM EOF-FILE1 UNTIL EOF OF FILE2
END-IF
WHEN KEY OF FILE1 > KEY OF FILE2
PERFORM READ-FILE2
IF EOF OF FILE2
PERFORM EOF-FILE2 UNTIL EOF OF FILE1
END-IF
WHEN KEY OF FILE1 = KEY OF FILE2
DISPLAY "MATCH"
PERFORM READ-FILE1
PERFORM READ-FILE2
END-EVALUATE.
READ-FILE1.
READ FILE1.
EOF-FILE1.
PERFORM WRITE-FROM-FILE1.
PERFORM READ-FILE2.
WRITE-FROM-FILE1.
MOVE FILE1-REC TO FILE3-REC
WRITE FILE3-REC.
READ-FILE2.
READ FILE2.
READ-FILE2.
READ FILE2.
EOF-FILE2.
PERFORM WRITE-FROM-FILE2.
PERFORM READ-FILE1.
WRITE-FROM-FILE2.
MOVE FILE2-REC TO FILE3-REC.
WRITE FILE3-REC.
READ-FILE1.
READ FILE1.
But it is showing only last record from file2.
and in spool it is showing file1 has reached to end of file.
plz reply.. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
Hello,
Well, you're persistant. . .
Look at the sample code and compare it to your code. Yours will not work. The way it has been laid out, it will probably never work. You cannot just add more reads to fit the current set of input data. The file contents will change from run to run and you cannot redo the code every time the data changes.
You need an understanding of this very basic process. From the code posted, it is quite obvious that you do not have this understanding yet.
If you compare the sample code from the sticky to your posted code, you will see significant differences. You need to understand why the sample code works and what you have does not.
After you compare the 2, post a reply with anything you don't understand. |
|
Back to top |
|
|
|