Joined: 07 Jan 2003 Posts: 1056 Topics: 91 Location: The Blue Planet
Posted: Thu Mar 18, 2004 2:05 am Post subject: Inserting a header records while merging two different files
I have two or more files with me that needs to be merged into one. But before merging, I need to insert a header record before each file to differentiate the records from two different files. Please see below.
Code:
OUTPUT:
HEADER RECORD: FILE 1 STARTS HERE
<data of file 1>
HEADER RECORD: FILE 2 STARTS HERE
<data of file 2>
HEADER RECORD: FILE 3 STARTS HERE
<data of file 3>
....
Please let me know how I can accomplish this.....
Its an emergency....I didn't go through all the posts in the forum....so please forgive me if anyone has already posted question...
Joined: 07 Jan 2003 Posts: 1056 Topics: 91 Location: The Blue Planet
Posted: Thu Mar 18, 2004 6:11 am Post subject:
I tried to code something like the one shown below. Can someone help me in fine tuning the code. I would like to eliminate the Temporaray file (T2) from my code.
Joined: 26 Nov 2002 Posts: 12378 Topics: 75 Location: San Jose
Posted: Thu Mar 18, 2004 6:28 am Post subject:
phantom,
Did you try running the job shown by ravi? It will indeed give you the desired results. All you need to change in that Job is the SYSPRINT DD statement. SORT requires SYSOUT DD SYSOUT=*
Joined: 07 Jan 2003 Posts: 1056 Topics: 91 Location: The Blue Planet
Posted: Thu Mar 18, 2004 7:15 am Post subject:
Thanks Kolusu,
The job which Ravi gave me had all the header lines clubbed together. So, they were copied at the end. Your solution will work fine as a Instream JCL. When I invoke the job as a Job-Proc, then I need to have 3 different controlcards / flat files containing the header lines. This is similar to storing the header lines into some flat files and concatenating them while u merge.
I am looking for a solution which requires only one SORT CONTROL CARD and NO FLAT files to hold the header lines. I am sorry for not making this clear in my initial request. Is there any command in SORT or some other utility which can include the header lines in between two different files.
Please let me know whether this could be accomplished.
Joined: 07 Jan 2003 Posts: 1056 Topics: 91 Location: The Blue Planet
Posted: Thu Mar 18, 2004 7:23 am Post subject:
Ravi,
I was a little confused... In your solution I thought AAAAA, BBBB....were the header lines that I was talking about. Sorry about that...But still, as I have said, my requirement is to accomplish using only one SORT Control card. Also, I donot want to store the header lines into any flat files. I want to hardcode them somewhere in the sort control card and when the job executes the header lines should be added before each file. Thanks for your help and sorry for confusing.
Joined: 26 Nov 2002 Posts: 12378 Topics: 75 Location: San Jose
Posted: Thu Mar 18, 2004 8:33 am Post subject:
Ravi,
Yes you are right about sysout being optional. But I suggest having sysout as it will provide more information regarding your syntax errors as well as sort statistics , like no: of records copied and sortin and sortout dataset properties.
Phantom,
The following DFSORT/ICETOOL JCL will give you the desired results.If you have syncsort at your shop then change the pgm name to synctool.Just make sure that you delete the output file before every run as we are using disp=mod.
Joined: 07 Jan 2003 Posts: 1056 Topics: 91 Location: The Blue Planet
Posted: Thu Mar 18, 2004 9:55 am Post subject:
Thanks a lot Kolusu, But removing the temporary file (T2) from my code, you have made the code much cleaner...
Sorry to bother you more...Now I am facing another small problem in this...When the above code is put into a proc, I need to create 4 control cards for the SYNCTOOL, one for the TOOLIN and other 3 for the OUTFIL statements. Is there any other way to have the same thing accomplished using only 1 card !!!...
The above requirement can be easily accomplished by having the header records within flat files and concatenate them (as you & Ravi had already given) while sorting. In that case, the programmer needs to create a new header file everytime he adds a new file....If by any chance he forgets to create the file, the job will BLOW. All I wanted is to minimize the programmers work, and inturn minimize the amount of possible errors....
Please let me know if there is any way to accomplish this....
Joined: 26 Nov 2002 Posts: 12378 Topics: 75 Location: San Jose
Posted: Thu Mar 18, 2004 10:49 am Post subject:
Phantom,
You can follow ravi's suggested solution if you don't care about the file number on the header. Here is another alternative solution which will create the header with file number and it is done with just one control card and even the no: of passes are also reduced. This also eliminates the programmer having to create the header datasets.
Joined: 07 Jan 2003 Posts: 1056 Topics: 91 Location: The Blue Planet
Posted: Fri Mar 19, 2004 9:25 am Post subject:
Kolusu,
I think we are missing something here....The no. of records in the temp. datasets (which hold the Header info.) T1, T2 and T3 will be equal to the no. of records in the DUMMY file (DD Name = NULL). Since DD DUMMY has no records in it. the header info. is not populated in the output. We need to look into this....If you look at the code that I sent first... I had a step which creates a dummy file with only one record in it...
Now, we need to find a way out to get the header records in the file. Your previous solution (below) will give the desired result, but it takes more control cards i.e one control card for every new file that is added.
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum