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
 

 

Sort step to Bring the last record to Beginning
Goto page 1, 2  Next
 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DFSORT/ICETOOL
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    Post subject: Sort step to Bring the last record to Beginning
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: 2150
Location: At my coffee table

PostPosted: Fri Apr 24, 2009 7:32 pm    Post subject:
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    Post subject: Reply to: Sort step to Bring the last record to Beginning
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: 2150
Location: At my coffee table

PostPosted: Fri Apr 24, 2009 8:27 pm    Post subject:
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 Moderator


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

PostPosted: Fri Apr 24, 2009 9:05 pm    Post subject:
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

Site Director


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

PostPosted: Fri Apr 24, 2009 9:59 pm    Post subject:
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    Post subject: Reply to: Sort step to Bring the last record to Beginning
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 Moderator


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

PostPosted: Sat Apr 25, 2009 3:59 am    Post subject:
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: 1238
Location: Richfield, MN, USA

PostPosted: Sat Apr 25, 2009 6:12 am    Post subject: Re: Reply to: Sort step to Bring the last record to Beginnin
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    Post subject: Reply to: Sort step to Bring the last record to Beginning
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 Moderator


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

PostPosted: Mon Apr 27, 2009 2:36 am    Post subject:
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    Post subject:
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    Post subject: I hope this will help, too.
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    Post subject: Reply to: Sort step to Bring the last record to Beginning
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    Post subject: Extracting last record without depending on the content
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 Moderator


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

PostPosted: Mon Apr 27, 2009 9:24 pm    Post subject:
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    Post subject:
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    Post subject: Reply to: Sort step to Bring the last record to Beginning
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    Post subject: It is simple!!
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    Post subject:
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
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DFSORT/ICETOOL All times are GMT + 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Limit duplicate records in the SORT pshongal SYNCSORT 6 Mon Nov 21, 2016 12:54 pm
No new posts How to convert the VBM file to VB or... Sulabh Agrawal JCL & VSAM 4 Fri Nov 18, 2016 1:04 pm
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 records based on numeric field. Alks SYNCSORT 2 Wed Oct 19, 2016 10:14 pm
No new posts How to delete second instance from Fl... Gunapala CN DFSORT/ICETOOL 6 Tue Oct 18, 2016 11:42 pm


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