Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Move Header Record to Top using SORT

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DFSORT/ICETOOL
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    Post subject: Move Header Record to Top using SORT
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: 3158
Location: Tucson AZ

PostPosted: Tue Jul 10, 2007 12:15 am    Post subject: Re: Move Header Record to Top using SORT
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    Post subject:
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: 3158
Location: Tucson AZ

PostPosted: Tue Jul 10, 2007 12:50 am    Post subject:
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

Moderator Team Head


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

PostPosted: Tue Jul 10, 2007 12:59 am    Post subject: Re: Move Header Record to Top using SORT
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    Post subject:
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 Moderator


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

PostPosted: Tue Jul 10, 2007 1:21 am    Post subject:
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: 3158
Location: Tucson AZ

PostPosted: Tue Jul 10, 2007 2:11 am    Post subject:
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 Moderator


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

PostPosted: Tue Jul 10, 2007 2:18 am    Post subject:
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: 3158
Location: Tucson AZ

PostPosted: Tue Jul 10, 2007 3:46 am    Post subject:
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    Post subject:
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    Post subject:
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    IBMMAINFRAMES.com Support Forums -> DFSORT/ICETOOL All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts How to change 'K' or 'M' use Sort vice_versa DFSORT/ICETOOL 5 Thu May 18, 2017 7:11 am
No new posts Adding big TEXT lines to each record ... bshkris SYNCSORT 4 Sat May 06, 2017 1:40 am
This topic is locked: you cannot edit posts or make replies. Merge two files and update Trailer re... Yashashri JCL & VSAM 1 Thu May 04, 2017 12:54 pm
This topic is locked: you cannot edit posts or make replies. SORT trick needed bshkris SYNCSORT 6 Tue May 02, 2017 4:35 am
No new posts SORT JSON type of data maxsubrat DFSORT/ICETOOL 8 Wed Apr 19, 2017 6:01 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us