IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Copy a new record inbetween file


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
suresh111

New User


Joined: 14 Feb 2005
Posts: 17

PostPosted: Fri Apr 03, 2009 5:57 pm
Reply with quote

QSAM File A has 10 records and QSAM File B has 1 record but I want to include File B record after the 5th record of file A as well as already existing 6th record should move to 7th like wise all ...now total 11 records should show in the File A.

Thanks & Regards,
Suresh
Back to top
View user's profile Send private message
superk

Global Moderator


Joined: 26 Apr 2004
Posts: 4652
Location: Raleigh, NC, USA

PostPosted: Fri Apr 03, 2009 6:07 pm
Reply with quote

Read File B and store the contents in Working-Storage.

Read File A with a record-counter incremented by 1 for each read. Write each record to File C. When you reach record 5, write it to File C, write the stored records from File B to File C, then continue the read-write process until File A reaches its EOF.

Afterward, you can delete or rename File A, then either rename File C or copy File C to a new File A.
Back to top
View user's profile Send private message
muthuvel

Active User


Joined: 29 Nov 2005
Posts: 217
Location: Canada

PostPosted: Fri Apr 03, 2009 6:08 pm
Reply with quote

For the above scenario, there are few questions,Is 1 record in file B is going to be the same or will it vary for every run?
If it varies,how you want them to be processed.


Keeping the questions apart,for your scenario ,

You cannot wirte a record intermediate in a sequential file,so you have to create a new file- File C
the solution will be ; Open file A in Input ;file B in Input;Open file C in output;
Code:
Read file A;
Increment FileA-Read-Cntr
If FileA-Read-Cntr =5
  Read fileB
  Write FileB rec to File C
Else
  Write FileA rec to File C
End-if
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Fri Apr 03, 2009 6:12 pm
Reply with quote

muthuvel: what happens to the fifth record in file A using your algorithm? Do you see a difference between what Kevin posted and what you posted?
Back to top
View user's profile Send private message
suresh111

New User


Joined: 14 Feb 2005
Posts: 17

PostPosted: Fri Apr 03, 2009 6:18 pm
Reply with quote

Thanks for the solution

Regards,
Suresh
Back to top
View user's profile Send private message
arvind.m

Active User


Joined: 28 Aug 2008
Posts: 205
Location: Hyderabad

PostPosted: Fri Apr 03, 2009 6:22 pm
Reply with quote

Yes. the 5th record from file-A is not written into output file. Maybe try this:

Code:

Read file A;
Increment FileA-Read-Cntr
If FileA-Read-Cntr =5
  Read fileB
  Write FileA rec to File C
  Write FileB rec to File C
Else
  Write FileA rec to File C
End-if
Back to top
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10873
Location: italy

PostPosted: Fri Apr 03, 2009 6:42 pm
Reply with quote

Code:
Read file A;
Increment FileA-Read-Cntr
If FileA-Read-Cntr =5
  Read fileB
  Write FileA rec to File C
  Write FileB rec to File C
Else
  Write FileA rec to File C
End-if


wonder why not keep things simpler

Code:
Read file A;
Write FileA rec to File C
Increment FileA-Read-Cntr
If FileA-Read-Cntr =5
  Read fileB
  Write FileB rec to File C
End-if
Back to top
View user's profile Send private message
suresh111

New User


Joined: 14 Feb 2005
Posts: 17

PostPosted: Fri Apr 03, 2009 7:59 pm
Reply with quote

Thanks a lot All of you..........
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts Compare 2 files and retrive records f... DFSORT/ICETOOL 3
No new posts FTP VB File from Mainframe retaining ... JCL & VSAM 8
No new posts Extract the file name from another fi... DFSORT/ICETOOL 6
No new posts How to split large record length file... DFSORT/ICETOOL 10
No new posts Extracting Variable decimal numbers f... DFSORT/ICETOOL 17
Search our Forums:

Back to Top