Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

How to eliminate duplicate files through a cobol program.

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
sangee27

New User


Joined: 16 Mar 2007
Posts: 19
Location: Pune

PostPosted: Mon May 21, 2007 10:32 am    Post subject: How to eliminate duplicate files through a cobol program.
Reply with quote

Hi,

I have a requirement like this to eliminate duplicates:

I have an input file which contains headers and trailers repeated, kind of concatenated file...

TT01ABC
TD01456
RT01GHT
TT01BGV
TD01689
TT01MHB
TD01997
RT01NHG

where TT01 is the header record and RT01 is the trailer record(TD01 - detail record).

1) I have to eliminate duplicates by comparing the 3 fields in the header record with that of a control file(in the above case position 5,6,7). This control file should contain the 3 fields specified above for the last 20 headers. I have to write the control file through this program.

2) Also i have to check whether the header record is having the corresponding trailer record. If you check the second header it does not have a trailer record, so it is not a good one and have to write the entire set to an error file. If the 3 field values are not in the control file also if it has a trailer record then it's a good one and i have to write this to the output file.

3) And the control file which is a flat file should have only 20 records, if it is more i have to delete the old records and maintain only 20 records.

Could anyone please suggest me how to proceed with the above requirements. For comparing the 3 fields in the header with that a control file, i can use an array but i am not sure about how to check for that set of trailer.
Back to top
View user's profile Send private message

Raphael Bacay

New User


Joined: 04 May 2007
Posts: 58
Location: Manila, Philippines

PostPosted: Mon May 21, 2007 3:32 pm    Post subject:
Reply with quote

I would like to offer a suggestion:

You seem to be right in using a table for the control-file. You can load the
control file first into your array. You can keep a field as running index where you last inserted into the table. The purpose of this is to keep the last position in the array where you last put in a control key. For example,
if there are only 7 control-keys in the control file then the running index should contain 8 so that the next header will be written to the 8th element in the array. If the running index exceeds 20, you have to rewrite your earliest control key so you move 1 to your running index to point it to the
oldest control-key (and the first element in your array) and overwrite with new control-key which you just got from your input file. This way your running index stores the position where you last inserted into the table and it makes sure that the oldest keys are overwritten with a new key.
At the end of processing you have to rewrite you control-file with the data in your array.

For your second problem, You might want to use a VSAM file for your input. If it's a flat file you can IDCAMS it to a VSAM file. I can't see
any field as unique so I think you must add a new field as a key even if it is just a sequential count field. When you have your VSAM file set-up you can use readnext to process your file. If you find a header with no trailer, you can use readprev to write to error file or readprev-readnext combo to write to output file in proper order.

You can use a flag for the header-trailer switching.


I hope that was useful.
Back to top
View user's profile Send private message
sangee27

New User


Joined: 16 Mar 2007
Posts: 19
Location: Pune

PostPosted: Mon May 21, 2007 4:51 pm    Post subject:
Reply with quote

Thanks for your inputs.

But should i maintain one more column in the array for the last record count. I could not understand properly about running index concept.
Back to top
View user's profile Send private message
Raphael Bacay

New User


Joined: 04 May 2007
Posts: 58
Location: Manila, Philippines

PostPosted: Tue May 22, 2007 7:49 am    Post subject:
Reply with quote

Hello,

No, you don't have to maintain another column for it. You maintain an index field(one variable allocated in ws) which contains the last position in the array where you can insert into the table. I would explalin further...

Suppose you have your control file set-up already and it only contains for example 4 control keys(3 digit items you identified above). You are going to load the contents of the file at the start of the program into your array. So you load all your items up... your array contains
array(1) = value
array(2) = value
array(3) = value
array(4) = value
the array index is at 4. You store (last index + 1) into the index field you declared. In this case index field will contain 5, to allow you to insert into the array at the next available space. Within the program, when you next
insert, it will insert at the 5the element of the array. Don't forget to increment your index field by 1 so that it will point to the next available space in your array for insert. In this case it is 6...

When your running index because of the procedure stated above reaches 21, this will mean you have exceeded the 20 limit mark. You make your running field index point to 1 by moveing 1 into the field index.
If you move 1 into it, use it in the array which will mean you will overwrite the 1st element of your array. This is good because the first element in your array contains the oldest value in your array. You overwrite this. Then you move the running index to the next element in your array, in this case 2, which will make your array insertable to the next oldest control key in your array. You can keep this up overwriting control keys as much as necessary.
Back to top
View user's profile Send private message
Raphael Bacay

New User


Joined: 04 May 2007
Posts: 58
Location: Manila, Philippines

PostPosted: Tue May 22, 2007 8:05 am    Post subject:
Reply with quote

By the way, just so it's clear you can use SEARCH in your array to see if the latest control key is in your array. If it is not then you can use the procedure above to insert into it.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Sort Card to Remove Duplicate records... raj4neo SYNCSORT 0 Wed Jan 25, 2017 4:44 am
This topic is locked: you cannot edit posts or make replies. Full Time COBOL Software Development ... shally Mainframe Jobs 0 Fri Jan 20, 2017 5:24 am
This topic is locked: you cannot edit posts or make replies. COBOL Software Development Lead at Fi... shally Mainframe Jobs 0 Fri Jan 20, 2017 5:21 am
No new posts Executing OO COBOL program invoking J... Virendra Shambharkar COBOL Programming 2 Tue Jan 10, 2017 6:37 pm
No new posts OO COBOL compile error Virendra Shambharkar COBOL Programming 3 Tue Jan 10, 2017 6:05 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us