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

Move Header Record to Top using SORT


IBM Mainframe Forums -> DFSORT/ICETOOL
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
myingling

New User


Joined: 09 Jul 2007
Posts: 6
Location: Hartford, CT

PostPosted: Mon Jul 09, 2007 11:54 pm
Reply with quote

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
View user's profile Send private message
William Thompson

Global Moderator


Joined: 18 Nov 2006
Posts: 3156
Location: Tucson AZ

PostPosted: Tue Jul 10, 2007 12:15 am
Reply with quote

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
View user's profile Send private message
myingling

New User


Joined: 09 Jul 2007
Posts: 6
Location: Hartford, CT

PostPosted: Tue Jul 10, 2007 12:20 am
Reply with quote

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
View user's profile Send private message
William Thompson

Global Moderator


Joined: 18 Nov 2006
Posts: 3156
Location: Tucson AZ

PostPosted: Tue Jul 10, 2007 12:50 am
Reply with quote

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
View user's profile Send private message
superk

Global Moderator


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

PostPosted: Tue Jul 10, 2007 12:59 am
Reply with quote

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
View user's profile Send private message
myingling

New User


Joined: 09 Jul 2007
Posts: 6
Location: Hartford, CT

PostPosted: Tue Jul 10, 2007 1:16 am
Reply with quote

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
View user's profile Send private message
Frank Yaeger

DFSORT Developer


Joined: 15 Feb 2005
Posts: 7129
Location: San Jose, CA

PostPosted: Tue Jul 10, 2007 1:21 am
Reply with quote

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
View user's profile Send private message
William Thompson

Global Moderator


Joined: 18 Nov 2006
Posts: 3156
Location: Tucson AZ

PostPosted: Tue Jul 10, 2007 2:11 am
Reply with quote

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
View user's profile Send private message
Frank Yaeger

DFSORT Developer


Joined: 15 Feb 2005
Posts: 7129
Location: San Jose, CA

PostPosted: Tue Jul 10, 2007 2:18 am
Reply with quote

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
View user's profile Send private message
William Thompson

Global Moderator


Joined: 18 Nov 2006
Posts: 3156
Location: Tucson AZ

PostPosted: Tue Jul 10, 2007 3:46 am
Reply with quote

Frank,

Thanks, I was just wondering.....

Bill
Back to top
View user's profile Send private message
krisprems

Active Member


Joined: 27 Nov 2006
Posts: 649
Location: India

PostPosted: Wed Jul 11, 2007 6:44 pm
Reply with quote

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
View user's profile Send private message
myingling

New User


Joined: 09 Jul 2007
Posts: 6
Location: Hartford, CT

PostPosted: Tue Jul 24, 2007 7:25 pm
Reply with quote

I used Frank's method and got it working, thanks!
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 -> DFSORT/ICETOOL

 


Similar Topics
Topic Forum Replies
No new posts Need to set RC4 through JCL SORT DFSORT/ICETOOL 5
No new posts How to split large record length file... DFSORT/ICETOOL 10
No new posts SFTP Issue - destination file record ... All Other Mainframe Topics 2
No new posts FINDREP - Only first record from give... DFSORT/ICETOOL 3
No new posts JCL sort card - get first day and las... JCL & VSAM 9
Search our Forums:

Back to Top