MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Making the Last Record as the First Record in File
Goto page 1, 2  Next
 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Utilities
View previous topic :: View next topic  
Author Message
vini
Intermediate


Joined: 12 Jan 2004
Posts: 240
Topics: 48
Location: Maryland

PostPosted: Fri May 28, 2004 10:08 am    Post subject: Making the Last Record as the First Record in File Reply with quote

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.

The File has an LRECL of 340
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12375
Topics: 75
Location: San Jose

PostPosted: Fri May 28, 2004 10:22 am    Post subject: Reply with quote

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?

Kolusu
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
vini
Intermediate


Joined: 12 Jan 2004
Posts: 240
Topics: 48
Location: Maryland

PostPosted: Fri May 28, 2004 10:31 am    Post subject: Reply with quote

Kolusu,

1. Since its the Header , preference is it being only in one place and that is the Top ( thats the whole problem ) Mr. Green

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 Wink For now , lets assume we should not change the order of the detail records , feels safer this way.

3. Yes , File Aid is there at my shop.

Thanks
Vini
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12375
Topics: 75
Location: San Jose

PostPosted: Fri May 28, 2004 10:50 am    Post subject: Reply with quote

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.

Code:

//STEP0100  EXEC  PGM=ICETOOL                             
//TOOLMSG   DD SYSOUT=*                                   
//DFSMSG    DD SYSOUT=*                                   
//IN        DD DSN=YOUR INPUT FILE,
//             DISP=SHR
//T1        DD DSN=&T1,DISP=(,PASS),SPACE=(TRK,(1,1),RLSE)
//T2        DD DSN=&T2,DISP=(,PASS),SPACE=(CYL,(1,1),RLSE)
//CON       DD DSN=&T1,DISP=OLD,VOL=REF=*.T1               
//          DD DSN=&T2,DISP=OLD,VOL=REF=*.T2               
//OUT       DD DSN=YOUR HEADER RECORD AS FIRST RECORD FILE,
//             DISP=(NEW,CATLG,DELETE),
//             UNIT=SYSDA,
//             SPACE=(CYL,(X,Y),RLSE)
//TOOLIN    DD    *                                       
  SORT FROM(IN)  USING(CTL1)                               
  SORT FROM(CON) USING(CTL2)                               
//CTL1CNTL DD    *                                         
  INREC FIELDS=(1,340,SEQNUM,8,ZD)                         
  SORT FIELDS=(341,8,ZD,D)                                 
  OUTFIL FNAMES=T1,ENDREC=1,OUTREC=(1,340,8C'0')           
  OUTFIL FNAMES=T2,STARTREC=2                             
//CTL2CNTL DD    *                                         
  SORT FIELDS=(341,8,ZD,A)                                 
  OUTFIL FNAMES=OUT,OUTREC=(1,340)                         
/*                                                         


If the order of the detail records does not matter then the following JCL's will give you the desired results.


Code:

//STEP0100 EXEC PGM=SORT
//SYSOUT   DD SYSOUT=*
//SORTIN   DD DSN=YOUR INPUT FILE,
//            DISP=SHR
//SORTOUT  DD DSN=YOUR HEADER RECORD AS FIRST RECORD FILE,
//            DISP=(NEW,CATLG,DELETE),
//            UNIT=SYSDA,
//            SPACE=(CYL,(X,Y),RLSE)
//SYSIN    DD *
  INREC FIELDS=(1,340,            $ TOTAL LRECL
                SEQNUM,8,ZD)      $ SEQUENCE NUMBER
  SORT FIELDS=(341,8,ZD,D)        $ SORT ON SEQ NUM DESC
  OUTREC FIELDS=(1,340)           $ STRIP OFF THE SEQ NUM
/*



or
Code:

//STEP0100 EXEC PGM=FILEAID,REGION=4M           
//SYSPRINT DD SYSOUT=*                         
//SYSLIST  DD SYSOUT=*                         
//DD01     DD DSN=YOUR INPUT FILE,
//            DISP=SHR
//DD01O    DD DSN=YOUR HEADER RECORD AS FIRST RECORD FILE,
//            DISP=(NEW,CATLG,DELETE),
//            UNIT=SYSDA,
//            SPACE=(CYL,(X,Y),RLSE),
//            DCB=(LRECL=340,RECFM=FB,BLKSIZE=0)
//SYSIN    DD  *                                 
$$DD01 COPYBACK
/*


Hope this helps...

Cheers

Kolusu
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
vini
Intermediate


Joined: 12 Jan 2004
Posts: 240
Topics: 48
Location: Maryland

PostPosted: Fri May 28, 2004 12:35 pm    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
vini
Intermediate


Joined: 12 Jan 2004
Posts: 240
Topics: 48
Location: Maryland

PostPosted: Fri May 28, 2004 12:38 pm    Post subject: Reply with quote

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. Confused
Back to top
View user's profile Send private message
vini
Intermediate


Joined: 12 Jan 2004
Posts: 240
Topics: 48
Location: Maryland

PostPosted: Fri May 28, 2004 12:43 pm    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12375
Topics: 75
Location: San Jose

PostPosted: Fri May 28, 2004 12:51 pm    Post subject: Reply with quote

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.

Kolusu
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
vini
Intermediate


Joined: 12 Jan 2004
Posts: 240
Topics: 48
Location: Maryland

PostPosted: Fri May 28, 2004 1:16 pm    Post subject: Reply with quote

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.

Thanks & Appreciate
Vini
Back to top
View user's profile Send private message
vini
Intermediate


Joined: 12 Jan 2004
Posts: 240
Topics: 48
Location: Maryland

PostPosted: Fri May 28, 2004 1:21 pm    Post subject: Reply with quote

Correction : By "8 " I meant length of the Record Id on which the Sort is based, and not the number of records.
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12375
Topics: 75
Location: San Jose

PostPosted: Fri May 28, 2004 1:28 pm    Post subject: Reply with quote

vini,

A 8 digit number would hold almost 100 million ( just 1 record short). I wouldn't recommend implementing the solution posted by me on a file that big.

100 million records in a file is huge and you expect the records more than 100 million ?

I would recommend changing the program

Kolusu
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
vini
Intermediate


Joined: 12 Jan 2004
Posts: 240
Topics: 48
Location: Maryland

PostPosted: Fri May 28, 2004 5:00 pm    Post subject: Reply with quote

I was being over-pessimistic , I guess it shouldnt exceed a million in the next decade or so Very Happy , 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 Surprised & 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 Wink
Back to top
View user's profile Send private message
Frank Yaeger
Sort Forum Moderator
Sort Forum Moderator


Joined: 02 Dec 2002
Posts: 1618
Topics: 31
Location: San Jose

PostPosted: Fri May 28, 2004 7:02 pm    Post subject: Reply with quote

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
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Frank Yaeger
Sort Forum Moderator
Sort Forum Moderator


Joined: 02 Dec 2002
Posts: 1618
Topics: 31
Location: San Jose

PostPosted: Fri May 28, 2004 7:07 pm    Post subject: Reply with quote

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
Back to top
View user's profile Send private message Send e-mail Visit poster's website
dhruv
Beginner


Joined: 01 Jun 2004
Posts: 10
Topics: 1

PostPosted: Tue Jun 01, 2004 10:26 am    Post subject: Reply with quote

Hi vini,


If the order of records needs to be maintained. then one way you can avoid all this sorting is to

. Write the header record to a seperate file
. Concatenate this 'header' file ahead of the original file and then do a SORT FIELDS=COPY

The above method should avoid sorts, and will not have any limiations on the number of records in the file.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Utilities All times are GMT - 5 Hours
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
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


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group