Joined: 12 Jan 2004 Posts: 240 Topics: 48 Location: Maryland
Posted: Fri May 28, 2004 10:08 am Post subject: Making the Last Record as the First Record in File
When the FB File is created in the program , the Header record is written as the Last record (owing to presence of counts etc).
Before sending the File to the Interface this record needs to be moved to the Top , as it is actually the Header.
The constraint is that there is No Item in File which distinguishes the Detail records from the Header. i.e there is no Record Type field.
I vaguely recall reading in this Forum that there is a way to Append a Record type/Record id in DFSORT and then sort the records based on that temporary field and eliminate it before the final step. However ,I am no aware of how to execute this.
I tried to search but I did not find what I was looking for ( not to say its not there ), someone pls. guide me.
Joined: 26 Nov 2002 Posts: 12375 Topics: 75 Location: San Jose
Posted: Fri May 28, 2004 10:22 am Post subject:
Vini,
A few clarifications to avoid more passes of the data.
1.Does it matter if you have the header at the top as well at the bottom?
2.once the header is at the top , can the detail records be in any order?
3.Do you have file-aid at your shop?
Joined: 12 Jan 2004 Posts: 240 Topics: 48 Location: Maryland
Posted: Fri May 28, 2004 10:31 am Post subject:
Kolusu,
1. Since its the Header , preference is it being only in one place and that is the Top ( thats the whole problem )
2. I have been thinking about this one myself, and I dont have a definite answer as the detail documents unfortunately dont mention these level of details. I would know only after I send a file and they reject it For now , lets assume we should not change the order of the detail records , feels safer this way.
Joined: 26 Nov 2002 Posts: 12375 Topics: 75 Location: San Jose
Posted: Fri May 28, 2004 10:50 am Post subject:
Vini,
The following DFSORT/ICETOOL JCl will give you the desired results. If you have syncsort at your shop then change the pgm name to synctool.
A brief explanation of the job.
The first sort takes the input file and adds a seq num at the end of each record. Now we sort on the seqnum descending so that we have the last record as the first record. Now we split this file into 2 seperate files. One with a header and the other with all other records. For the header record we will overwrite the seqnum with zeroes so that it will stay at the top.
The next sort operator takes in the concatenation of the above 2 files and sorts on the seqnum ascending so that we can retain the sequence of the detail records. Since the seqnum on the header record is zero it will always stay as the first record. While writting the output we strip off the seqnum.
Joined: 12 Jan 2004 Posts: 240 Topics: 48 Location: Maryland
Posted: Fri May 28, 2004 12:35 pm Post subject:
Kolusu ,
Why dont we instead append a Record-Type of 1 Char . An 'A' for the Last record and any other alphabet ..say 'D' for the Detail Records , and then sort them on this record type ?!
If that is anyway possible , I see the following advantages :
1) We dont make an assumption on number of records in the file when we define
length of the record-id , because if we do this and when the max possible record count is a unknown figure (as in this case), guess the order would mess up .
2) We probably save one or maybe two passes/steps
If this is possible , pls. show me how to do it this way.
Joined: 12 Jan 2004 Posts: 240 Topics: 48 Location: Maryland
Posted: Fri May 28, 2004 12:38 pm Post subject:
In saying that I have made the assumption that since all the Details would have 'D' , the Sort should not change the order of these record , as they all have the same value , not sure though.
Joined: 12 Jan 2004 Posts: 240 Topics: 48 Location: Maryland
Posted: Fri May 28, 2004 12:43 pm Post subject:
On second thoughts , even if the Sort result would be unpredictable in regard of the Order of the 'D' records ,I would still like to see how to execute this and hence I will not concern myself with the Order of the 'D' records in the solution for this one.
Joined: 26 Nov 2002 Posts: 12375 Topics: 75 Location: San Jose
Posted: Fri May 28, 2004 12:51 pm Post subject:
Vini,
If your are talking of appending the character 'd' for header and 'a' for detail records in the program which creates the file , then you would definitely save an extra pass.
If you are talking of appending the character in the sort , then there should be a way to identify the header record.
Actually if you are willing to change the pgm , then I would recommend writting the header record to a seperate file and the detail records to another file. Then you can concatenate these 2 file with header file being the first file in the concatenation list.
Joined: 12 Jan 2004 Posts: 240 Topics: 48 Location: Maryland
Posted: Fri May 28, 2004 1:16 pm Post subject:
Kolusu ,
If I wanted to take the Program route I wouldnt have posted here , that is always an alternative.
I will use the solution given by you , only thing was that I did not want to put a limit on the possible number of total records , which in your example is 8.
My concern was , what would happen if I have records greater than 99999999 , even if I increase that length to 10 ,what if record count exceeded that too ..I guess I am being too pessimistic here , so I will go with length of 10 / 12 I guess that should suffice.
I am still curious to know , why this cannot be done using a RECORD TYPE (2 Unique values ) instead of a UNIQUE RECORD ID (n unique values) ? If we do not care for the Order of the Detail records i,e. , except that they should all be below the Header.
Joined: 12 Jan 2004 Posts: 240 Topics: 48 Location: Maryland
Posted: Fri May 28, 2004 5:00 pm Post subject:
I was being over-pessimistic , I guess it shouldnt exceed a million in the next decade or so , so I guess I do not need to change the program to write the header in a seperate file.
While I incorporate Kolusus suggested Steps , I am hoping someone can address my concerns around
Quote:
1) What happens to the Order of records if while sorting in DFSORT ,it encounters contiguous records with same values in the sort field , is the resulting order predictable or unpredictable
2) Using record type vs. unique record ids
What I like about this forum , is the open exchange of ideas ,and getting to learn new things. I try to keep myself awake & motivated by visiting MVSFORUMS. It defintitely has been a source of inspiration for me and I am surprised that I even want to experiment with JCL/Utilities today ,these very two things would scare and bore me to death in the past
Joined: 02 Dec 2002 Posts: 1618 Topics: 31 Location: San Jose
Posted: Fri May 28, 2004 7:02 pm Post subject:
Here's another DFSORT/ICETOOL solution for this problem. I believe it's a more efficient solution because it doesn't do any sorting, just copying and doesn't require inserting sequence numbers. Note that we're using a 15-digit ZD number for the count, so no worries about the number of records. (DFSORT allows 15-digit ZD sequence numbers too.)
Code:
//S1 EXEC PGM=ICETOOL
//TOOLMSG DD SYSOUT=*
//DFSMSG DD SYSOUT=*
//IN DD DSN=... input file
//CTL2CNTL DD DSN=&&T2,UNIT=SYSDA,SPACE=(TRK,(1,1)),DISP=(,PASS)
//** USE MOD FOR OUT
//OUT DD DISP=MOD,DSN=... output file
//TOOLIN DD *
* Copy input record n (the last record) to OUT
* (as the first record)
* Generate CTL2CNTL with:
* OPTION STOPAFT=x where x is n-1
COPY FROM(IN) USING(CTL1)
* Use OPTION STOPAFT=x to copy input records 1 to n-1 to OUT
COPY FROM(IN) TO(OUT) USING(CTL2)
//CTL1CNTL DD *
* Get last record from IN as first record in OUT
OUTFIL FNAMES=OUT,REMOVECC,NODETAIL,
TRAILER1=(1,256,257,84)
* Generate the following control statement in CTL2CNTL
* OPTION STOPAFT=x
* where x is the number of input records - 1
OUTFIL FNAMES=CTL2CNTL,REMOVECC,NODETAIL,
STARTREC=2, - skip the first record to get n-1
TRAILER1=(' OPTION STOPAFT=',
COUNT=(M11,LENGTH=15),80:X)
/*
_________________ Frank Yaeger - DFSORT Development Team (IBM)
Specialties: JOINKEYS, FINDREP, WHEN=GROUP, ICETOOL, Symbols, Migration
DFSORT is on the Web at:
www.ibm.com/storage/dfsort
Joined: 02 Dec 2002 Posts: 1618 Topics: 31 Location: San Jose
Posted: Fri May 28, 2004 7:07 pm Post subject:
vini wrote
Quote:
1) What happens to the Order of records if while sorting in DFSORT ,it encounters contiguous records with same values in the sort field , is the resulting order predictable or unpredictable
If EQUALS is in effect, the original order of duplicate records will be kept. You can ensure that EQUALS is in effect by specifying:
Code:
OPTION EQUALS
_________________ Frank Yaeger - DFSORT Development Team (IBM)
Specialties: JOINKEYS, FINDREP, WHEN=GROUP, ICETOOL, Symbols, Migration
DFSORT is on the Web at:
www.ibm.com/storage/dfsort
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum