View previous topic :: View next topic
|
Author |
Message |
Anil Minumula
New User
Joined: 24 Feb 2009 Posts: 12 Location: Frankfurt
|
|
|
|
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 |
|
|
CICS Guy
Senior Member
Joined: 18 Jul 2007 Posts: 2146 Location: At my coffee table
|
|
|
|
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 |
|
|
Anil Minumula
New User
Joined: 24 Feb 2009 Posts: 12 Location: Frankfurt
|
|
|
|
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 |
|
|
CICS Guy
Senior Member
Joined: 18 Jul 2007 Posts: 2146 Location: At my coffee table
|
|
|
|
Well, the SELECT Operator of ICETOOL does have a LAST operand, maybe that could help. |
|
Back to top |
|
|
Frank Yaeger
DFSORT Developer
Joined: 15 Feb 2005 Posts: 7129 Location: San Jose, CA
|
|
|
|
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 |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
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 |
|
|
Anil Minumula
New User
Joined: 24 Feb 2009 Posts: 12 Location: Frankfurt
|
|
|
|
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 |
|
Back to top |
|
|
Frank Yaeger
DFSORT Developer
Joined: 15 Feb 2005 Posts: 7129 Location: San Jose, CA
|
|
|
|
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 |
|
|
Terry Heinze
JCL Moderator
Joined: 14 Jul 2008 Posts: 1249 Location: Richfield, MN, USA
|
|
|
|
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 |
As someone once said, "Can't usually means won't." |
|
Back to top |
|
|
Anil Minumula
New User
Joined: 24 Feb 2009 Posts: 12 Location: Frankfurt
|
|
|
|
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 |
|
|
Frank Yaeger
DFSORT Developer
Joined: 15 Feb 2005 Posts: 7129 Location: San Jose, CA
|
|
|
|
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 |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
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 |
|
|
dominickim
New User
Joined: 28 Feb 2007 Posts: 65 Location: NS, CA
|
|
|
|
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 |
|
|
Anil Minumula
New User
Joined: 24 Feb 2009 Posts: 12 Location: Frankfurt
|
|
|
|
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 |
|
|
dominickim
New User
Joined: 28 Feb 2007 Posts: 65 Location: NS, CA
|
|
|
|
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 |
|
|
Frank Yaeger
DFSORT Developer
Joined: 15 Feb 2005 Posts: 7129 Location: San Jose, CA
|
|
|
|
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 |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
thx Frank. |
|
Back to top |
|
|
Anil Minumula
New User
Joined: 24 Feb 2009 Posts: 12 Location: Frankfurt
|
|
|
|
Thanks Frank.. |
|
Back to top |
|
|
dominickim
New User
Joined: 28 Feb 2007 Posts: 65 Location: NS, CA
|
|
|
|
Frank,
I like your simple solution.
Dominic |
|
Back to top |
|
|
Binaya
New User
Joined: 03 Jul 2007 Posts: 77 Location: Hyderabad
|
|
|
|
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 |
|
|
gcicchet
Senior Member
Joined: 28 Jul 2006 Posts: 1702 Location: Australia
|
|
|
|
Hi,
try this
Code: |
SUBSET FROM(IN) TO(OUT) KEEP INPUT FIRST LAST
|
Gerry |
|
Back to top |
|
|
|