View previous topic :: View next topic
|
Author |
Message |
myingling
New User
Joined: 09 Jul 2007 Posts: 6 Location: Hartford, CT
|
|
|
|
I already searched the forums looking for an answer to my question, but was unable to find one. If I missed it, please link me directly instead of just saying "search harder."
Anyway, my issue is that I want to bring a header record in a file to the top of that file. I KNOW the record will be at the bottom of the file.
Example input:
Code: |
00221123ABC312FV
00221123ABC312FV
00221123ABC312FV
00221123ABC312FV
MEYAP0004
|
Desired output:
Code: |
MEYAP0004
00221123ABC312FV
00221123ABC312FV
00221123ABC312FV
00221123ABC312FV
|
Needless to say, pretty simple. I just don't know how to do it. Help much appreciated.
Thank you! |
|
Back to top |
|
|
William Thompson
Global Moderator
Joined: 18 Nov 2006 Posts: 3156 Location: Tucson AZ
|
|
|
|
myingling wrote: |
Anyway, my issue is that I want to bring a header record in a file to the top of that file. I KNOW the record will be at the bottom of the file. |
Are you saying that the last record No matter what it looks like) is to be made the first record?
Or is the header record identifiable in some way different from the data records? |
|
Back to top |
|
|
myingling
New User
Joined: 09 Jul 2007 Posts: 6 Location: Hartford, CT
|
|
|
|
The last record - no matter what it looks like - is to be made the first record.
However it is ALSO true that the last record will always start with "YYYYY" and none of the others will, if that's easier.
I'd prefer NOT use a sort on the whole file (i.e., putting records that start with alphabetic records before records that start with numbers) since input file could contain a few thousand records, and it would be much less efficient to perform a sort when I only need a single record moved.
Let me know if that helps! Thanks!
(And sorry for spelling errors, it's a weakness of mine.) |
|
Back to top |
|
|
William Thompson
Global Moderator
Joined: 18 Nov 2006 Posts: 3156 Location: Tucson AZ
|
|
|
|
All I can think of is to include/omit copy the data to one temp file and the header to another and then concatenate the header in front of the data and copy back to a real dataset....I'm not sure if that concat will run into a (known) problem.
I'm looking forward to the inventiveness of Frank's solution. |
|
Back to top |
|
|
superk
Global Moderator
Joined: 26 Apr 2004 Posts: 4652 Location: Raleigh, NC, USA
|
|
|
|
Two possibilities occur to me:
1. "Flip" the data upside-down so the last record is now the first record. Write the first record only to one dataset, and all the other records (in their original order) to another. Then, concatenate the two datasets into a third.
2. Count the number of records in the dataset (max). Use the highest value to retrieve just the last record (max), then retrieve records 1 through (max - 1) for the rest. This one is probably more efficient. |
|
Back to top |
|
|
myingling
New User
Joined: 09 Jul 2007 Posts: 6 Location: Hartford, CT
|
|
|
|
superk,
How, in code, would I implement your second suggestion?
The reason I ask is, the input file I'm using for this step IS a temp file, and the output is going to be the final (master) file. Therefore copying over just the last line first, then the lines before it might make sense.
Thanks! |
|
Back to top |
|
|
Frank Yaeger
DFSORT Developer
Joined: 15 Feb 2005 Posts: 7129 Location: San Jose, CA
|
|
|
|
Quote: |
However it is ALSO true that the last record will always start with "YYYYY" and none of the others will, if that's easier. |
Yes, that does make it easier. Here's a DFSORT/ICETOOL job that will do what you asked for using two copy operators (no sort). I'm using //IN DD * to show what the input looks like - you can, of course, use //IN DD DSN=... instead.
Code: |
//S1 EXEC PGM=ICETOOL
//TOOLMSG DD SYSOUT=*
//DFSMSG DD SYSOUT=*
//IN DD *
00121123ABC312FV
00221123ABC312FV
00321123ABC312FV
00421123ABC312FV
YYYY
/*
//*** OUT MUST BE A MOD DATA SET
//OUT DD DISP=MOD,DSN=... MOD ouput file
//TOOLIN DD *
COPY FROM(IN) TO(OUT) USING(CTL1)
COPY FROM(IN) TO(OUT) USING(CTL2)
/*
//CTL1CNTL DD *
INCLUDE COND=(1,4,CH,EQ,C'YYYY')
/*
//CTL2CNTL DD *
OMIT COND=(1,4,CH,EQ,C'YYYY')
/*
|
|
|
Back to top |
|
|
William Thompson
Global Moderator
Joined: 18 Nov 2006 Posts: 3156 Location: Tucson AZ
|
|
|
|
Frank Yaeger wrote: |
Code: |
//*** OUT MUST BE A MOD DATA SET
//OUT DD DISP=MOD,DSN=... MOD ouput file
//TOOLIN DD *
COPY FROM(IN) TO(OUT) USING(CTL1)
COPY FROM(IN) TO(OUT) USING(CTL2)
/*
|
|
Frank,
Clean solution, I knew you had a better way.
Does Dfsort processes each COPY in order?
Or does it process them on the same pass but output them in order? |
|
Back to top |
|
|
Frank Yaeger
DFSORT Developer
Joined: 15 Feb 2005 Posts: 7129 Location: San Jose, CA
|
|
|
|
Quote: |
Does Dfsort processes each COPY in order? |
Yes. It takes two passes over the data to get the last record and then the other records. But two copys for a few thousand records is hardly worth talking about. |
|
Back to top |
|
|
William Thompson
Global Moderator
Joined: 18 Nov 2006 Posts: 3156 Location: Tucson AZ
|
|
|
|
Frank,
Thanks, I was just wondering.....
Bill |
|
Back to top |
|
|
krisprems
Active Member
Joined: 27 Nov 2006 Posts: 649 Location: India
|
|
|
|
myingling
If you could use File-Aid, then the solution would be:
Code: |
//*******************************************************
//faid EXEC PGM=FILEAID
//SYSPRINT DD SYSOUT=*
//DD01 DD DSN=input file ,DISP=SHR
//DD01O DD DSN=output file ,DISP=MOD
//SYSIN DD *
$$DD01 COPYBACK OUT=1
/*
//SORTSTP EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//SORTIN DD DSN=input file ,DISP=SHR
//SORTOUT DD DSN=output file ,DISP=MOD
//SYSIN DD *
SORT FIELDS=COPY
OMIT COND=(1,4,CH,EQ,C'YYYY')
/*
|
The file aid step
Code: |
$$DD01 COPYBACK OUT=1 |
Read's the file through backwards(so no over head on system) and writes the header to the o/p file(with DISP=MOD), OUT=1 ensures that only 1 record is written to the o/p file.
Then in the SORT step, you would be excluding the header record and appending the remaining record's below the header to the o/p file.
This is tested one, you can try implementing as per your requirements. |
|
Back to top |
|
|
myingling
New User
Joined: 09 Jul 2007 Posts: 6 Location: Hartford, CT
|
|
|
|
I used Frank's method and got it working, thanks! |
|
Back to top |
|
|
|