View previous topic :: View next topic
|
Author |
Message |
suresh111
New User
Joined: 14 Feb 2005 Posts: 17
|
|
|
|
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 |
|
|
superk
Global Moderator
Joined: 26 Apr 2004 Posts: 4652 Location: Raleigh, NC, USA
|
|
|
|
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 |
|
|
muthuvel
Active User
Joined: 29 Nov 2005 Posts: 217 Location: Canada
|
|
|
|
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 |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
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 |
|
|
suresh111
New User
Joined: 14 Feb 2005 Posts: 17
|
|
|
|
Thanks for the solution
Regards,
Suresh |
|
Back to top |
|
|
arvind.m
Active User
Joined: 28 Aug 2008 Posts: 205 Location: Hyderabad
|
|
|
|
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 |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10873 Location: italy
|
|
|
|
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 |
|
|
suresh111
New User
Joined: 14 Feb 2005 Posts: 17
|
|
|
|
Thanks a lot All of you.......... |
|
Back to top |
|
|
|