View previous topic :: View next topic
|
Author |
Message |
Jeya Raj
New User
Joined: 14 Jan 2007 Posts: 33 Location: USA
|
|
|
|
Hi all,
I need to write a cobol program to read two VSAM files and compare those two files at 05 level. If there is a difference at 05 level for these files write it into one flat file with field name and two file values. If not continue to read input files.
I?m reading these two files into two copybooks. How can I compare two files at 05 levels?. Please let me know.
Thanks, |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
Please post your copybooks (or at least the part you want to compare) and some sample data from both files as well as what you want for output when your code executes.
It need not be much, just enought to show what you are working with and what you need for the result. |
|
Back to top |
|
|
William Thompson
Global Moderator
Joined: 18 Nov 2006 Posts: 3156 Location: Tucson AZ
|
|
|
|
The level means nothing, you are comparing the two files "by key", some field in one needs to match to a field in the other.
The first thing, are both files in the same sequence of the field (or fields) that you need to compare? Determine this, and all else becomes a simple schoolbook exercise. |
|
Back to top |
|
|
Jeya Raj
New User
Joined: 14 Jan 2007 Posts: 33 Location: USA
|
|
|
|
I'm reading the first file and sending the key to read the second file. Both of the files are having the same record length and structure. One file is populated from VSAM data and another is populated from DB2. I need to compare both files. Write the output file with the field name and values from two files for that field if there is a mismatch. |
|
Back to top |
|
|
DavidatK
Active Member
Joined: 22 Nov 2005 Posts: 700 Location: Troy, Michigan USA
|
|
|
|
New2cobol,
I have written, and maintain several programs that do a virtually identical process, only with DB2 rows instead of VSAM records (the logic between them is pretty much the same). When you write the sequential file, you will want to include the Key of the VSAM file so you know what records is being processed. Also you will need to decide what you are going to do if a record exists on one file and not the other. What is going to happen to the file once built? You?re going to have to decide on a format for the seq file. Probable something like this:
Code: |
01 CHANGE-RECORD.
05 RECORD-KEY PIC X(30). >or the max key length<
05 RECORD-FIELD_NAME PIC X(30).
05 OLD-VALUE PIC X(??). >max len of values<
05 NEW-VALUE PIC X(??). >same as OLD-VALUE<
|
Your seq file must be generic enough to be used with all fields. That the reason for the fields in the CHANGE-RECORD being PIC X()
You will have to interrogate each field individually.
Code: |
01 NEW-FILE.
05 RECORD-KEY PIC X(25).
:
05 OUTSTANDING-BALANCE PIC S9(11)V9(2) COMP-3.
:
01 WS-11-2 PIC -9(11).9(2).
:
:
IF OUTSTANDING-BALANCE
OF OLD-FILE NOT = OUTSTANDING-BALANCE
OF NEW-FILE
THEN
MOVE RECORD-KEY
OF NEW-FILE TO RECORD-KEY
OF CHANGE-FILE
MOVE ?OUTSTANDING-BALANCE?
TO RECORD-FIELD-NAME
OF CHANGE-RECORD
MOVE OUTSTANDING-BALANCE
OF OLD-FILE
TO WS-11-2
MOVE WS-11-2 TO OLD-VALUE
OF CHANGE-RECORD
MOVE OUTSTANDING-BALANCE
OF NEW-FILE
TO WS-11-2
MOVE WS-11-2 TO NEW-VALUE
OF CHANGE-RECORD
WRITE CHANGE-RECORD
END-IF.
IF INTEREST-RATE
OF OLD-FILE NOT = INTEREST-RATE
OF NEW-FILE
THEN
:
:
|
|
|
Back to top |
|
|
|