copy of records between 2 files
Moderators: dbzTHEdinosauer, Moderator Group
-
- Member
- Posts: 1
- Joined: Wed Jul 20, 2011 4:50 pm
copy of records between 2 files
I want to the logic of copying last 10 records from one file to another file, by using only cobol
RAVIKUMAR
I'm not a COBOL programmer, but ...
I'd use a table of 10 occurences. Read a record and store it in working-storage. For each record read, bump the entries in the table down one (move the 9th occurent to the 10th, the 8th to the 9th, etc.) and replace the first with the most recently read record.
When you reach the EOF, you'll have the last ten records read stored in the table. You'd want to write them out in inverse order to keep them in their original order.
I'd use a table of 10 occurences. Read a record and store it in working-storage. For each record read, bump the entries in the table down one (move the 9th occurent to the 10th, the 8th to the 9th, etc.) and replace the first with the most recently read record.
When you reach the EOF, you'll have the last ten records read stored in the table. You'd want to write them out in inverse order to keep them in their original order.
- dbzTHEdinosauer
- Moderator
- Posts: 981
- Joined: Mon Oct 02, 2006 8:31 pm
good idea MrSpock,
but if you set up the data layout correctly, you can use a group move to shuffle everthing up instead of 10 individual moves.
define an area consisting of 10 fields, each the length of a record.
redefine the area twice,
once with two fields, the first 9 records long the last 1 record long.
second with two fields, the first 1 record long, then second 9 records long.
instead of the index bumping,
just always read the record into the 10th field,
then move the last 9 to the first 9 as a group move. (move is left to right).
(move 9 fields in redef 2 to 9 fields in redef 1.
then at end of file write bumping an index from first to 10th.
the obvious choice of course is a sort solution,
but obviously this is homework and we have done the work the TS should have done
in order to learn something.
we will probably see a lot of RAVIKUMAR, asking us to do his work for him.
but if you set up the data layout correctly, you can use a group move to shuffle everthing up instead of 10 individual moves.
define an area consisting of 10 fields, each the length of a record.
redefine the area twice,
once with two fields, the first 9 records long the last 1 record long.
second with two fields, the first 1 record long, then second 9 records long.
instead of the index bumping,
just always read the record into the 10th field,
then move the last 9 to the first 9 as a group move. (move is left to right).
(move 9 fields in redef 2 to 9 fields in redef 1.
then at end of file write bumping an index from first to 10th.
the obvious choice of course is a sort solution,
but obviously this is homework and we have done the work the TS should have done
in order to learn something.
we will probably see a lot of RAVIKUMAR, asking us to do his work for him.
Dick Brenholtz
JCL, SQL and code in programs have an irritating habit of doing what you say,
not what you meant.
JCL, SQL and code in programs have an irritating habit of doing what you say,
not what you meant.
-
- Member
- Posts: 10
- Joined: Thu Jul 21, 2011 1:34 pm
It would be a better option if u use arrays if the file does not contain many records.
1.)Move the file records one by one into an indexed array, until all end-of file.
maintain a counter to know how many records are present.
2.)now u can get the the lat record by retrieving it from the array as u already know the last record number.(how many records are present in the file).
3.)write a loop using perform decrementing the index and WRITE it into a new file
any queries PM or EMAIL me
email address removed from post. if you want members to email you, provide an email address in your profile dbz
1.)Move the file records one by one into an indexed array, until all end-of file.
maintain a counter to know how many records are present.
2.)now u can get the the lat record by retrieving it from the array as u already know the last record number.(how many records are present in the file).
3.)write a loop using perform decrementing the index and WRITE it into a new file
any queries PM or EMAIL me
email address removed from post. if you want members to email you, provide an email address in your profile dbz
- dbzTHEdinosauer
- Moderator
- Posts: 981
- Joined: Mon Oct 02, 2006 8:31 pm
that is a really poor answer.ramana murthy wrote:It would be a better option if u use arrays if the file does not contain many records.
1. the program would be bound by the number of items declared for the COBOL Internal Table. You would not longer have a solution if the file increased in size.
Arrays are host variables for DB2
2. You are forcing the program to use more memory that would be required by 10 records. This is a waste of resources and could impact the STARTing of other tasks in the system.
Dick Brenholtz
JCL, SQL and code in programs have an irritating habit of doing what you say,
not what you meant.
JCL, SQL and code in programs have an irritating habit of doing what you say,
not what you meant.
-
- Member
- Posts: 10
- Joined: Thu Jul 21, 2011 1:34 pm
thank you
Thank you for the reply.
I am learning mainframes...
All your suggestions are valuable to me.
Ramana Murthy.
I am learning mainframes...
All your suggestions are valuable to me.
Ramana Murthy.
FREE TUTORIALS
Tutorials
Free tutorials from mainframegurukul
- JCL Tutorial
Covers all important JCL concepts. - Cobol Tutorial
This tutorials covers all Cobol Topics from STRING to COMP-3. - DB2 Tutorial
DB2 Tutorial focuses on DB2 COBOL Programming. - SORT Tutorial
This Tutorial covers all important aspects of DFSORT with examples - CICS Tutorial
This CICS tutorial covers CICS concepts and CICS Basics, CICS COBOL Programming.
Interview
Mainframe Interview questions
- Cobol Interview Questions
50+ Interview Questions - JCL Interview Questions
50+ Interview Questions - DB2 Interview Questions
100+ Interview Questions - CICS Interview Questions
70+ Interview Questions - VSAM Interview Questions
27 Interview Questions
Other References
Mainframe Tools and others
- XPEDITER Reference
Explains how we can debug a program - FILEAID Reference
Explains how to browse , edit and delete datasets - Change Man Reference
Quick Start tutorial on Changeman - Abend Reference
Important Abend codes explained - FaceBook Page
MainframeGurukul FaceBook Page - LinkedIn Page
MainframeGurkul Linkedin Page