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

Sort step to Bring the last record to Beginning


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

New User


Joined: 24 Feb 2009
Posts: 12
Location: Frankfurt

PostPosted: Fri Apr 24, 2009 6:54 pm
Reply with quote

Hi,

Can you please help me with this.

I have a requirement in which, we receive a flat file. We are supposed to process this file based on Date it was created. But unfortunately this date is available in the last record. So either I have to read the file until end to see which date it was generated or somehow get the date to the beginning of the file. So thought of using sort steps to bring the date to beginning of the file as the file is too huge.

I know that we can extract this record alone in one step and merge the files in a second step. But is there any way of doing this job in a single step?

Please note that ther is no key using which we can sort this file. Below I have have a sample layout.
-------------------------------------------------------------
Data Record1
Date Record2
.....
Data Recordn
File created on 18-Mar-2009
-------------------------------------------------------------

Thanks a lot
Back to top
View user's profile Send private message
CICS Guy

Senior Member


Joined: 18 Jul 2007
Posts: 2146
Location: At my coffee table

PostPosted: Fri Apr 24, 2009 7:32 pm
Reply with quote

Assuming that the last record is uniquely identifiable by content rather than just being the last record, adding a sequence number upon input to the data records and a sequence number of zero to the date record and just sort the file by the seqnum will get you what you want.
It won't be as fast as a straight copy, but, depending on the volume of records, sort will end up with basically two strings to merge to output. And it beats going through the file twice.
Back to top
View user's profile Send private message
Anil Minumula

New User


Joined: 24 Feb 2009
Posts: 12
Location: Frankfurt

PostPosted: Fri Apr 24, 2009 8:10 pm
Reply with quote

Thanks a lot for your reply. I have used an almost similar approach.

OK, I was hoping to find the last record instead of identifying using the content (Reason - to avoid probable errors which can arrive because of data transfer).

Below is how presently am handling this. If someone thinks we can have a better solution please let me know. Thanks a lot.

Code:
//SYSIN    DD *
  INREC IFTHEN=(WHEN=(1,12,CH,NE,C'File Created'),BUILD=(C'999',1,200)),
        IFTHEN=(WHEN=(1,12,CH,EQ,C'File Created',BUILD=(C'000',1,200))
  SORT FIELDS=(1,3,ZD,A)
  OUTFIL OUTREC(4,200)
//* --------------------------------------------------------------------
Back to top
View user's profile Send private message
CICS Guy

Senior Member


Joined: 18 Jul 2007
Posts: 2146
Location: At my coffee table

PostPosted: Fri Apr 24, 2009 8:27 pm
Reply with quote

Well, the SELECT Operator of ICETOOL does have a LAST operand, maybe that could help.
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: Fri Apr 24, 2009 9:05 pm
Reply with quote

Anil,

It's not clear what you're trying to do.

Quote:
We are supposed to process this file based on Date it was created


Process how?

Quote:
But is there any way of doing this job in a single step?


Doing what?

Perhaps if you explained in more detail the bigger picture of what you're trying to do, we could offer some help.
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Fri Apr 24, 2009 9:59 pm
Reply with quote

Hello,

Suggest you negotiate a change to how the file is created so that there is a "header" record first with the info you need. The remainder of the file would be unchanged and processes that did not need the header info would simply skip it. . .
Back to top
View user's profile Send private message
Anil Minumula

New User


Joined: 24 Feb 2009
Posts: 12
Location: Frankfurt

PostPosted: Sat Apr 25, 2009 2:38 am
Reply with quote

Hello Mr. Yaeger,

Thanks a lot for your reply and sorry for the confusion.

Our requirement is, we get a file with some data to be processed from an external system. The file is an input to a cobol program, but the cobol program has to work on this file only when the date present in the last record is current date.

So we wanted to use some sort step to bring this last record to the beginning.

Can you please suggest an efficient way of processing the last record in a flat file first?

Mr. Scherrer,

Unfortunately the sender of this cant really change the structure, the file is generated in an open systems world and is used by many stake holders icon_sad.gif
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: Sat Apr 25, 2009 3:59 am
Reply with quote

So you want to make the last record the first record and keep all of the other records in their original order? So using your input example, would the expected output be:

Code:

File created on 18-Mar-2009
Data Record1
Date Record2
.....
Data Recordn


Does the input file have RECFM=FB and LRECL=200?

What is the approximate number of records in the input file?
Back to top
View user's profile Send private message
Terry Heinze

JCL Moderator


Joined: 14 Jul 2008
Posts: 1249
Location: Richfield, MN, USA

PostPosted: Sat Apr 25, 2009 6:12 am
Reply with quote

Anil Minumula wrote:
Unfortunately the sender of this cant really change the structure, the file is generated in an open systems world and is used by many stake holders icon_sad.gif

As someone once said, "Can't usually means won't." icon_sad.gif
Back to top
View user's profile Send private message
Anil Minumula

New User


Joined: 24 Feb 2009
Posts: 12
Location: Frankfurt

PostPosted: Sun Apr 26, 2009 1:46 pm
Reply with quote

Hello Mr Yaeger,

Thanks for your reply.

Code:
File created on 18-Mar-2009
Data Record1
Date Record2
.....
Data Recordn


Yes we need the file in this format.

The file format is FB and record length of 900.

This file can havv upto 1 million records.
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: Mon Apr 27, 2009 2:36 am
Reply with quote

You have the right idea. Here's a slightly simpler version of a DFSORT job to do what asked for. It wasn't clear if the string in the last record has 'created' or 'Created'. Adjust as needed.

Code:

//S1    EXEC  PGM=SORT
//SYSOUT    DD  SYSOUT=*
//SORTIN DD DSN=...  input file (FB/900)
//SORTOUT DD DSN=...  output file (FB/900)
//SYSIN    DD    *
  INREC IFTHEN=(WHEN=(1,12,CH,EQ,C'File created'),
    OVERLAY=(901:Z))
  OPTION EQUALS
  SORT FIELDS=(901,1,BI,A)
  OUTREC BUILD=(1,900)
/*
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


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

PostPosted: Mon Apr 27, 2009 2:51 am
Reply with quote

Frank,

let's say it is the last record of the file.
nothing to compare to,
we just know that it is the last record and we want it up front -
the rest of the file to remain in current order.

My question actually is:
what would replace the IFTHEN,
what keyword would mean last record?

thx.
Back to top
View user's profile Send private message
dominickim

New User


Joined: 28 Feb 2007
Posts: 65
Location: NS, CA

PostPosted: Mon Apr 27, 2009 3:25 am
Reply with quote

Anil,
How about separating input file into two output files using simple OMIT/INCLUDE.
Your next input will be those concatenated files but file that having last record first.
Dominic
Back to top
View user's profile Send private message
Anil Minumula

New User


Joined: 24 Feb 2009
Posts: 12
Location: Frankfurt

PostPosted: Mon Apr 27, 2009 12:03 pm
Reply with quote

Hi all,

Thanks a lot for all your replies.

Mr. Yaeger,

We will implement one of either Frank's solution OR the idea which we had.

It would be still interesting to know if DFSORT/ICETOOL can just take the last record and paste it in the Front in a single step, without depending on the content.

Thanks a lot
Back to top
View user's profile Send private message
dominickim

New User


Joined: 28 Feb 2007
Posts: 65
Location: NS, CA

PostPosted: Mon Apr 27, 2009 5:45 pm
Reply with quote

This will give you an idea to extract last record without depending on the content.
Code:
//STEP1 EXEC  PGM=ICETOOL                                       
//TOOLMSG  DD SYSOUT=*                                         
//DFSMSG   DD SYSOUT=*                                         
//IN       DD *                                                 
DATA RECORD1                                                   
DATE RECORD2                                                   
DATA RECORDN                                                   
FILE CREATED ON 18-MAR-2009                                     
//CTL2CNTL DD DSN=&&C2,UNIT=SYSDA,SPACE=(TRK,(1,1)),DISP=(,PASS)
//CTL2OUT  DD SYSOUT=*                                         
//TOOLIN   DD *                                                 
COPY FROM(IN) USING(CTL1)                                       
COPY FROM(IN) TO(CTL2OUT) USING(CTL2)                           
/*                                                             
//CTL1CNTL DD *                                                 
 OUTFIL FNAMES=CTL2CNTL,REMOVECC,NODETAIL,OUTREC=(900X),       
        TRAILER1=(' OUTFIL STARTREC=',COUNT=(M11,LENGTH=8))     
/*                                                             

Outout
Code:

********************************* TOP OF DATA **************************
FILE CREATED ON 18-MAR-2009                                             
******************************** BOTTOM OF DATA ************************
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: Mon Apr 27, 2009 9:24 pm
Reply with quote

Quote:
let's say it is the last record of the file.
nothing to compare to,
we just know that it is the last record and we want it up front -
the rest of the file to remain in current order.


Quote:
It would be still interesting to know if DFSORT/ICETOOL can just take the last record and paste it in the Front in a single step, without depending on the content.


Here's a DFSORT/ICETOOL job that will do that.

Code:

//S1    EXEC  PGM=ICETOOL
//TOOLMSG DD SYSOUT=*
//DFSMSG DD SYSOUT=*
//IN DD DSN=...  input file
//****>>> USE MOD FOR //OUT
//OUT DD DISP=(MOD,CATLG,DELETE),DSN=...  output file
//TOOLIN   DD    *
SUBSET FROM(IN) TO(OUT) INPUT KEEP LAST
SUBSET FROM(IN) TO(OUT) INPUT REMOVE LAST
/*
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


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

PostPosted: Mon Apr 27, 2009 9:57 pm
Reply with quote

thx Frank.
Back to top
View user's profile Send private message
Anil Minumula

New User


Joined: 24 Feb 2009
Posts: 12
Location: Frankfurt

PostPosted: Mon Apr 27, 2009 10:01 pm
Reply with quote

Thanks Frank..
Back to top
View user's profile Send private message
dominickim

New User


Joined: 28 Feb 2007
Posts: 65
Location: NS, CA

PostPosted: Mon Apr 27, 2009 10:02 pm
Reply with quote

Frank,
I like your simple solution.
Dominic
Back to top
View user's profile Send private message
Binaya

New User


Joined: 03 Jul 2007
Posts: 77
Location: Hyderabad

PostPosted: Thu Aug 27, 2009 4:07 pm
Reply with quote

Hi Guys,

The method expalined by DOMINICKIM is working fine to extract the trailer record from a file.
Can you please explain me how to extract Header along with the trailer (i.e 1st record along with last record) using the above technic.

Thnks.
Back to top
View user's profile Send private message
gcicchet

Senior Member


Joined: 28 Jul 2006
Posts: 1702
Location: Australia

PostPosted: Thu Aug 27, 2009 4:39 pm
Reply with quote

Hi,

try this

Code:
  SUBSET FROM(IN) TO(OUT) KEEP INPUT FIRST LAST



Gerry
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