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
 

 

Change the last record to 2nd

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DFSORT/ICETOOL
View previous topic :: :: View next topic  
Author Message
Bhargav_1058

New User


Joined: 13 Dec 2008
Posts: 53
Location: New York

PostPosted: Wed Jun 27, 2012 8:54 pm    Post subject: Change the last record to 2nd
Reply with quote

Hi,

Could anyone let me know if the below is possible in single sort?

I have an input file (LRECL=80, RECFM=FB) and I would like to change the last record position to 2nd record. I have achieved this using 2 steps
1). to extract first and last records into file1 and rest of the records into file2.
2). Then I merged FILE1 and FILE2.

Just curious to know if this is possible in single sort step. Any help would be greatly appreciated.

Code:
Input file:
1st record
2nd record
3rd record
Last record


My output should look like below.

Code:
Output file:
1st record
Last record
2nd record
3rd record
Back to top
View user's profile Send private message

Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7223

PostPosted: Wed Jun 27, 2012 9:19 pm    Post subject: Reply to: Change the last record to 2nd
Reply with quote

Other than its physical position, is there something which identifies the record as the "last"?
Back to top
View user's profile Send private message
Pandora-Box

Moderator


Joined: 07 Sep 2006
Posts: 1529
Location: Andromeda Galaxy

PostPosted: Wed Jun 27, 2012 9:20 pm    Post subject:
Reply with quote

Is there are way to identify last and second record as unique?
Back to top
View user's profile Send private message
Bhargav_1058

New User


Joined: 13 Dec 2008
Posts: 53
Location: New York

PostPosted: Wed Jun 27, 2012 9:28 pm    Post subject:
Reply with quote

The last record will always have "last" in 1st 4 positions. But is it possible without identifying the last record?
Back to top
View user's profile Send private message
Pandora-Box

Moderator


Joined: 07 Sep 2006
Posts: 1529
Location: Andromeda Galaxy

PostPosted: Wed Jun 27, 2012 9:30 pm    Post subject:
Reply with quote

Is that a homework request?
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Wed Jun 27, 2012 9:37 pm    Post subject:
Reply with quote

Quote:
2). Then I merged FILE1 and FILE2.


no you did not, you concatenated file1 with file2.

Quote:
But is it possible without identifying the last record?


i am afraid that even i can not come up with the snark which that deserves.
Back to top
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7223

PostPosted: Wed Jun 27, 2012 9:41 pm    Post subject: Reply to: Change the last record to 2nd
Reply with quote

If you already have the two-records and rest, there'd be no real problem with just using them in a "concatenation" in the JCL.

If you can't identify the last, you make it more tricky.

If you can identify the last, it is straightforward. Append a sequence number starting from 2 (for the first record).

IFTHEN to test for sequence equal to 2, change it to 1 (OVERLAY)
IFTHEN to identify last record, change it to 2 (OVERLAY)
SORT on sequence number.
Strip off sequence number.

The concatenation route would avoid the SORT. Might be good with a big file.

Maybe search around if you don't know anything to identify the last record. You might have a look at the TRAILER stuff, which would have the final record available and mess about like that.
Back to top
View user's profile Send private message
Pandora-Box

Moderator


Joined: 07 Sep 2006
Posts: 1529
Location: Andromeda Galaxy

PostPosted: Wed Jun 27, 2012 9:59 pm    Post subject:
Reply with quote

What you could do is generate Symbol Cnt which would have the valie of total number of records have the value of lemgth 8


Then copy the inpuy file overlay with sequence of length 8

Then again use inrec init overlay add 01 for first record , 04 for second, 03 for all records until before last, 02 when Cnt equals sequence

Sort based on these two bytes

Am afraid if this can be done in 1 step
Back to top
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7223

PostPosted: Wed Jun 27, 2012 10:09 pm    Post subject: Reply to: Change the last record to 2nd
Reply with quote

Might be OK if you know the number of records :-)

Not sure why you want the "04". Bear in mind that to retain the order the SORT would have to use EQUALS, which is more resource-hungry.

It is probably one ICETOOL operator to take the first and last records to one file, the remaining records to another, and then use as concatenation for later input.

SORT with FIELDS=COPY would have to identify the last record to do the same.
Back to top
View user's profile Send private message
Pandora-Box

Moderator


Joined: 07 Sep 2006
Posts: 1529
Location: Andromeda Galaxy

PostPosted: Wed Jun 27, 2012 10:51 pm    Post subject:
Reply with quote

Yes the Symname will be prepared using Count funtion in Trailer

04 because it is just to ensure on sort it falls as last record
Back to top
View user's profile Send private message
Skolusu

Senior Member


Joined: 07 Dec 2007
Posts: 2205
Location: San Jose

PostPosted: Wed Jun 27, 2012 10:57 pm    Post subject:
Reply with quote

Bhargav_1058 wrote:
The last record will always have "last" in 1st 4 positions. But is it possible without identifying the last record?


If you can identify the last record, then you can do it in a single step. However you would have to perform a SORT on the sequence number to do it. ex:
Code:

//STEP0100 EXEC PGM=SORT                                     
//SYSOUT   DD SYSOUT=*                                       
//SORTIN   DD *                                             
1ST RECORD                                                   
2ND RECORD                                                   
3RD RECORD                                                   
LAST RECORD                                                 
//SORTOUT  DD SYSOUT=*                                       
//SYSIN    DD *                                             
  INREC IFTHEN=(WHEN=INIT,OVERLAY=(81:SEQNUM,8,ZD)),         
  IFTHEN=(WHEN=(1,4,CH,EQ,C'LAST'),OVERLAY=(81:C'00000001'))
  SORT FIELDS=(81,8,CH,A),EQUALS                             
  OUTREC BUILD=(1,80)                                       
//*


If you cannot the last record , then you need two steps to get the desired results. However I think it is a good solution to have 2 steps instead of sorting the data.
Back to top
View user's profile Send private message
Bhargav_1058

New User


Joined: 13 Dec 2008
Posts: 53
Location: New York

PostPosted: Thu Jun 28, 2012 3:35 am    Post subject:
Reply with quote

Hi kolusu,

Thank you very much for your code. That works exactly the way I needed. Now I have 2 solutions to achieve this, but I would prefer to have single step (your sort solution). By this way I can avoid creating another temporary files. Thank you very much for your help!!
Back to top
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7223

PostPosted: Thu Jun 28, 2012 1:54 pm    Post subject: Reply to: Change the last record to 2nd
Reply with quote

Code:
1ST RECORD                                                   
2ND RECORD                                                   
3RD RECORD                                                   
LAST RECORD


Your existing solution.

Output 1
Code:
1ST RECORD   
LAST RECORD                                                 

Output 2
Code:
2ND RECORD                                                   
3RD RECORD                                                   


Code:
//INFILE DD DISP=SHR,DSN=OUTPUT1
//       DD DISP=SHR,DSN=OUTPUT2


No temporary files (why would that be a problem anyway?), no sort. Just change the JCL where the output is read.
Back to top
View user's profile Send private message
Skolusu

Senior Member


Joined: 07 Dec 2007
Posts: 2205
Location: San Jose

PostPosted: Thu Jun 28, 2012 10:03 pm    Post subject:
Reply with quote

Bhargav_1058 wrote:
Hi kolusu,

Thank you very much for your code. That works exactly the way I needed. Now I have 2 solutions to achieve this, but I would prefer to have single step (your sort solution). By this way I can avoid creating another temporary files. Thank you very much for your help!!


Did you read this line in my post?
skolusu wrote:

However I think it is a good solution to have 2 steps instead of sorting the data.
Back to top
View user's profile Send private message
Bhargav_1058

New User


Joined: 13 Dec 2008
Posts: 53
Location: New York

PostPosted: Fri Jun 29, 2012 5:30 am    Post subject:
Reply with quote

Yes - I did read your line. I don't have any problem in sorting the file. I only required to bring the last record to 2nd position. Thanks for your help!
Back to top
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7223

PostPosted: Sun Jul 08, 2012 6:47 pm    Post subject:
Reply with quote

Bhargav_1058 wrote:
Yes - I did read your line. I don't have any problem in sorting the file. I only required to bring the last record to 2nd position. Thanks for your help!


I suppose you probably won't read this, but if you prefer to SORT over the suggested two-step solution, be aware that somewhere along the way someone is paying for this.

You might not mind and "they" might not realise. Still, it is good practice to do things the best way you can, and a good idea to take good advice when it is handed to you on a plate.
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 update a portion of text in a ... Bill Woodger DFSORT/ICETOOL 25 Wed Nov 09, 2016 9:41 pm
No new posts sort with previous record anatol DFSORT/ICETOOL 9 Thu Oct 06, 2016 2:36 am
No new posts Get Record count in summary record fo... Atul Banke DFSORT/ICETOOL 21 Fri Sep 23, 2016 4:17 pm
No new posts Change date (DD/MM/YY) in 2nd record ... uday kiran DFSORT/ICETOOL 12 Wed Sep 07, 2016 10:57 pm
No new posts Using 'parm' to vary SORTOUT record v... Sysaron DFSORT/ICETOOL 13 Wed Sep 07, 2016 9:24 pm


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