copy of records between 2 files

This is a Mainframe COBOL forum - you can post your queries on Mainframe COBOL, VS COBOL II, COBOL/370 , Enterprise COBOL

Moderators: dbzTHEdinosauer, Moderator Group

Post Reply
ravikumarmft
Member
Posts: 1
Joined: Wed Jul 20, 2011 4:50 pm

copy of records between 2 files

Post by ravikumarmft » Wed Jul 20, 2011 5:01 pm

I want to the logic of copying last 10 records from one file to another file, by using only cobol
RAVIKUMAR

MrSpock
Active Member
Posts: 273
Joined: Wed Jun 27, 2007 5:37 pm

Post by MrSpock » Wed Jul 20, 2011 9:42 pm

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.

User avatar
dbzTHEdinosauer
Moderator
Posts: 981
Joined: Mon Oct 02, 2006 8:31 pm

Post by dbzTHEdinosauer » Thu Jul 21, 2011 2:15 am

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.
Dick Brenholtz
JCL, SQL and code in programs have an irritating habit of doing what you say,
not what you meant.

ramana murthy
Member
Posts: 10
Joined: Thu Jul 21, 2011 1:34 pm

Post by ramana murthy » Thu Jul 21, 2011 7:28 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
:D

email address removed from post. if you want members to email you, provide an email address in your profile dbz

User avatar
dbzTHEdinosauer
Moderator
Posts: 981
Joined: Mon Oct 02, 2006 8:31 pm

Post by dbzTHEdinosauer » Thu Jul 21, 2011 7:40 pm

ramana murthy wrote:It would be a better option if u use arrays if the file does not contain many records.
that is a really poor answer.

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.

ramana murthy
Member
Posts: 10
Joined: Thu Jul 21, 2011 1:34 pm

thank you

Post by ramana murthy » Thu Jul 21, 2011 9:36 pm

Thank you for the reply.
I am learning mainframes...
All your suggestions are valuable to me.

Ramana Murthy.

Post Reply

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



Other References
Mainframe Tools and others