View previous topic :: View next topic
|
Author |
Message |
Bhargav_1058
New User
Joined: 13 Dec 2008 Posts: 53 Location: New York
|
|
|
|
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 |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
Other than its physical position, is there something which identifies the record as the "last"? |
|
Back to top |
|
|
Pandora-Box
Global Moderator
Joined: 07 Sep 2006 Posts: 1592 Location: Andromeda Galaxy
|
|
|
|
Is there are way to identify last and second record as unique? |
|
Back to top |
|
|
Bhargav_1058
New User
Joined: 13 Dec 2008 Posts: 53 Location: New York
|
|
|
|
The last record will always have "last" in 1st 4 positions. But is it possible without identifying the last record? |
|
Back to top |
|
|
Pandora-Box
Global Moderator
Joined: 07 Sep 2006 Posts: 1592 Location: Andromeda Galaxy
|
|
|
|
Is that a homework request? |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
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 |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
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 |
|
|
Pandora-Box
Global Moderator
Joined: 07 Sep 2006 Posts: 1592 Location: Andromeda Galaxy
|
|
|
|
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 |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
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 |
|
|
Pandora-Box
Global Moderator
Joined: 07 Sep 2006 Posts: 1592 Location: Andromeda Galaxy
|
|
|
|
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 |
|
|
Skolusu
Senior Member
Joined: 07 Dec 2007 Posts: 2205 Location: San Jose
|
|
|
|
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 |
|
|
Bhargav_1058
New User
Joined: 13 Dec 2008 Posts: 53 Location: New York
|
|
|
|
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 |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
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 |
|
|
Skolusu
Senior Member
Joined: 07 Dec 2007 Posts: 2205 Location: San Jose
|
|
|
|
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 |
|
|
Bhargav_1058
New User
Joined: 13 Dec 2008 Posts: 53 Location: New York
|
|
|
|
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 |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
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 |
|
|
|