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 

Pick First , Middle and Last but one Records from File

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Utilities
View previous topic :: View next topic  
Author Message
Deepthi
Beginner


Joined: 20 Aug 2005
Posts: 27
Topics: 6
Location: MN

PostPosted: Fri Oct 07, 2005 8:32 am    Post subject: Pick First , Middle and Last but one Records from File Reply with quote

Hi,
I have an input dataset ,whose count of records change every day . That is, the number of records in this dataset is not a constant. I want to extract the first ,middle and the 'last but one' record of this data set on a daily basis.The problem here is only with selecting the middle record as the count of records is not a constant.I have two options.But i am confused as to how to proceed with those.
Options:
1)Will i be able to divide the value got in the count parameter of sort utility by 2 and use it in a sort card to pick the required middle record.

2)Can i use a splitby option of outfile and use count/2 as a parameter for splitby .

Can someone suggest how can i proceed with any of those two options.
Thanks,
Deepthi
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


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

PostPosted: Fri Oct 07, 2005 9:07 am    Post subject: Reply with quote

Deepthi,

It can be done but a couple of clarifications.

1. what happens when the total no: of records is an ODD number. How do you pick the middle record?

ex: total no: of records 7. what is the middle record ? is it record no:3 or record no: 4?

Quote:

2)Can i use a splitby option of outfile and use count/2 as a parameter for splitby .


Nope.

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


Joined: 20 Aug 2005
Posts: 27
Topics: 6
Location: MN

PostPosted: Fri Oct 07, 2005 9:21 am    Post subject: Reply with quote

Thanks for the quick reply.For odd number of records it can be either (n+1)/2 or (n-1)/2. Moreoever ,if dataset has only one record,i want these steps in the job which selects three records to be overrided . I know ,empty datasets can be detected using Idcams and fileaid etc,Is there any similar way where a single record file can be identified . If so,i can use it to override these steps, when an single record dataset is an input, just by using COND=(RC,NE,STEPnumber) in my next step.
_________________
Thanks,
Deepthi.

Our lives begin to end the day we become silent about things that matter.
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


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

PostPosted: Fri Oct 07, 2005 9:55 am    Post subject: Reply with quote

Deepthi,

The following JCL will give you the desired results. I am assumed that your input lrecl is 80 bytes and is of FB recfm.

Code:

//STEP0100 EXEC PGM=SORT                                       
//SYSOUT    DD SYSOUT=*                                       
//SORTIN    DD DSN=YOUR INPUT FILE,
//             DISP=SHR                                       
//SORTOUT   DD DSN=&T1,DISP=(,PASS),SPACE=(TRK,(1,1),RLSE)     
//SYSIN     DD *                                               
  SORT FIELDS=COPY                                             
  OUTREC FIELDS=(SEQNUM,8,ZD,X,SEQNUM,8,ZD,START=0,INCR=1,80:X)
  OUTFIL NODETAIL,REMOVECC,
  TRAILER1=(C' FIRST,00000001',/,                             
            C' MIDDLE,',AVG=(1,8,ZD,M11,LENGTH=8),/,           
            C' LASTBUTONE,',MAX=(10,8,ZD,M11,LENGTH=8),80:X)   
/*                                                             
//STEP0200 EXEC PGM=SORT       
//SYSOUT    DD SYSOUT=*       
//SYMNAMES  DD DSN=&T1,DISP=OLD
//SORTIN    DD DSN=YOUR INPUT FILE,
//             DISP=SHR   
//SORTOUT   DD DSN=YOUR OUTPUT FIEL,
//             DISP=(NEW,CATLG,DELETE),
//             UNIT=SYSDA,
//             SPACE=(CYL,(X,Y),RLSE)
//SYSIN     DD *                         
  INREC FIELDS=(1,80,SEQNUM,8,ZD)       
  SORT FIELDS=COPY                       
  OUTFIL INCLUDE=(81,8,ZD,EQ,FIRST,OR,   
                  81,8,ZD,EQ,MIDDLE,OR, 
                  81,8,ZD,EQ,LASTBUTONE),
  OUTREC=(1,80)                         
/*


This job will take care of even if your input file is empty.

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
Frank Yaeger
Sort Forum Moderator
Sort Forum Moderator


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

PostPosted: Fri Oct 07, 2005 10:08 am    Post subject: Reply with quote

Quote:
Is there any similar way where a single record file can be identified . If so,i can use it to override these steps, when an single record dataset is an input, just by using COND=(RC,NE,STEPnumber) in my next step.


You could use the COUNT operator of DFSORT's ICETOOL:

COUNT FROM(IN) EQUAL(1)

This will give you RC=12 if IN has 1 record or RC=0 if it doesn't.

Similarly:

COUNT FROM(IN) NOTEQUAL(1)

will give you RC=0 if IN has 1 record or RC=12 if it doesn't.
_________________
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
Deepthi
Beginner


Joined: 20 Aug 2005
Posts: 27
Topics: 6
Location: MN

PostPosted: Fri Oct 14, 2005 5:24 am    Post subject: Reply with quote

Thanks Kolusu and Frank for your great solutions. And sorry for the delay in reply too.

Kolusu,

I am not clear about the syntax of AVG and MAX.Could you please explain me the Syntax of AVG=(1,8,ZD,M11,LENGTH=5) and MAX=(10,8,ZD,M11,LENGTH=5). That would be of great help.

Note: I have changed the length to 5 to suit my requirements.
_________________
Thanks,
Deepthi.

Our lives begin to end the day we become silent about things that matter.
Back to top
View user's profile Send private message
Phantom
Data Mgmt Moderator
Data Mgmt Moderator


Joined: 07 Jan 2003
Posts: 1056
Topics: 91
Location: The Blue Planet

PostPosted: Fri Oct 14, 2005 5:48 am    Post subject: Reply with quote

Deepthi,

The syntax of AVG command is AVG=(start_pos, length, format, output_format, output_length)

Code:

AVG=(1,8,ZD,M11,LENGTH=5)


In the above code, you are trying to find the average of some field which is available in columns 1-8 and stored in ZD (Zoned Decimal) format. ZD is nothing but your COBOL S9(nn)V9(nn).

M11 is a pre-defined Edit mask. It is equivalent to specifying EDIT=(TTTTTT...T) where T is similar to COBOL '9'. And you force the output to be Length 5. (EDIT=(TTTTT)). Character 'I' in EDIT mask is equivalent to COBOL 'Z' (Zero Suppressor).

The same is the case with MAX operator.

Please let me know if I am not clear / if you need more information.

Thanks,
Phantom


Last edited by Phantom on Fri Oct 14, 2005 7:44 am; edited 1 time in total
Back to top
View user's profile Send private message
Phantom
Data Mgmt Moderator
Data Mgmt Moderator


Joined: 07 Jan 2003
Posts: 1056
Topics: 91
Location: The Blue Planet

PostPosted: Fri Oct 14, 2005 5:57 am    Post subject: Reply with quote

Deepthi,

The following link provides information on the 27 pre-defined EDIT Masks in DFSORT. This should help you.

http://publibz.boulder.ibm.com/cgi-bin/bookmgr_OS390/BOOKS/ice1ca10/3.13?DT=20050222160456

And this link gives details about AVG in OUTREC.

http://publibz.boulder.ibm.com/cgi-bin/bookmgr_OS390/BOOKS/ice1ca10/3.13?DT=20050222160456

Hope this helps,

Thanks,
Phantom
Back to top
View user's profile Send private message
Deepthi
Beginner


Joined: 20 Aug 2005
Posts: 27
Topics: 6
Location: MN

PostPosted: Fri Oct 14, 2005 7:19 am    Post subject: Reply with quote

Thanks a lot for ur quick response ,Phantom.
I understood the syntax. Thanks a lot again. Very Happy
_________________
Thanks,
Deepthi.

Our lives begin to end the day we become silent about things that matter.
Back to top
View user's profile Send private message
Phantom
Data Mgmt Moderator
Data Mgmt Moderator


Joined: 07 Jan 2003
Posts: 1056
Topics: 91
Location: The Blue Planet

PostPosted: Fri Oct 14, 2005 7:54 am    Post subject: Reply with quote

Deepthi,

There is a small change in my previous post. 'T' actually is equivalent to COBOL 9 and 'I' is equivalent to cobol 'Z'. I have corrected it. Please see the data highlighted in bold.

Thanks,
Phantom
Back to top
View user's profile Send private message
Deepthi
Beginner


Joined: 20 Aug 2005
Posts: 27
Topics: 6
Location: MN

PostPosted: Fri Oct 14, 2005 11:09 pm    Post subject: Reply with quote

Phantom,
Thanks a lot for that !! I was not aware of those .

Kolusu,
I noticed that in my input dataset ,the sequence number of records are already present in the first five positions.Hence, i felt there is no need of using the SEQNUM and thus modified your solution to generate a sortcard .Below is the job that i used to generate the sortcard.


Code:



//STEP010  EXEC    PGM=SORT                                     
//SYSOUT   DD      SYSOUT=*                                     
//SORTIN   DD      DSN=INPUTFILE,                   
//             DISP=SHR                                         
//SORTOUT   DD     DSN=SORTCARD,   
//             DISP=(NEW,CATLG,DELETE),                         
//             UNIT=SYSDA,                                       
//             SPACE=(TRK,(10,5),RLSE),                         
//             DCB=(RECFM=FB,LRECL=71,BLKSIZE=0)                 
//*                                                             
//SYSIN     DD *                                                 
  SORT FIELDS=COPY                                               
  OUTFIL NODETAIL,REMOVECC,                                     
  TRAILER1=(C' INCLUDE COND=(1,5,CH,EQ,C',                       
            C'''',                                               
            C'00001',C'''',                                     
            C',OR,',/,                         
            C' 1,5,CH,EQ,C',                   
            C'''',AVG=(1,5,ZD,M11,LENGTH=5),   
            C'''',                             
            C',OR,',/,                         
            C' 1,5,CH,EQ,C',                   
            C'''',MAX=(1,5,ZD,M11,LENGTH=5),   
            C'''',                             
            C')',                               
            71:X)                               
/*                                             
//*                             



I used this sortcard in the next step to get my required output.This job went fine and i got the required results.

Moreover,I understood the solution provided by you earlier clearly.I submitted ur job as it is, only changes being the record length ,as my input record length is 71,and the job abended with - ABEND S013 REASON=00000020.But i couldn't trace the reason for the above abend. Could you please let me know.
_________________
Thanks,
Deepthi.

Our lives begin to end the day we become silent about things that matter.
Back to top
View user's profile Send private message
Phantom
Data Mgmt Moderator
Data Mgmt Moderator


Joined: 07 Jan 2003
Posts: 1056
Topics: 91
Location: The Blue Planet

PostPosted: Sat Oct 15, 2005 11:53 am    Post subject: Reply with quote

Deepthi,

S013 Abend due the following reasons.
Code:

Forgot the DCB information, or used the wrong DCB information.
BLKSIZE does not match the file blocksize.
BLKSIZE is not a multiple of LRECL.
PDS member name can not be found.


1. Try removing the BLKSIZE=0 from the SPACE parameter of your output file. Actually you don't have to code DCB for SORTOUT. Sort takes it automatically. So, better leave it to its discretion.

2. Do you have the sort card as a PDS Member or have you used an Inline sort card. If you have given that as a PDS Member then check whether the member name specified in the JCL is correct.

Let us know if any of these solves the problem.

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


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

PostPosted: Sat Oct 15, 2005 2:36 pm    Post subject: Reply with quote

Quote:

I used this sortcard in the next step to get my required output.This job went fine and i got the required results.


Deepthi,

Not exactly true. Your requirement was to get the "last but one" record along with the first and middle records. Your solution will get the "Last" record, unless the sequence number in your file starts with a zero. Starting a seqnum from zero isn't that common.

Quote:

I submitted ur job as it is, only changes being the record length ,as my input record length is 71,and the job abended with - ABEND S013 REASON=00000020.But i couldn't trace the reason for the above abend. Could you please let me know.


It would be easy for us to pinpoint the exact error if you have posted the SYSOUT error messages.

Well if my memory serves right , you get an error S013 when DCB parameters are off. I guess you created the SYMNAMES input with lrecl of 71 . A SYMNAMES DD statement data set must have the following attributes: RECFM=F or RECFM=FB and LRECL=80.

The only changes in the JCL posted by me are in the second step(STEP0200).

Code:

//SYSIN     DD *                         
  INREC FIELDS=(1,71,SEQNUM,8,ZD)       
  SORT FIELDS=COPY                       
  OUTFIL INCLUDE=(72,8,ZD,EQ,FIRST,OR,   
                  72,8,ZD,EQ,MIDDLE,OR, 
                  72,8,ZD,EQ,LASTBUTONE),
  OUTREC=(1,71)                         
/*


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
Deepthi
Beginner


Joined: 20 Aug 2005
Posts: 27
Topics: 6
Location: MN

PostPosted: Tue Oct 18, 2005 3:04 am    Post subject: Reply with quote

Phantom/Kolusu,

Thanks much for your responses.Phantom,I had problems with the code that Kolusu had posted in the beginning.I guess, you provided me solutions based on the code i had posted.But still,i really thank you for providing me the possible reasons for the abend and next time,i get a S013 abend,i will definitely try to remember those possibilities. Very Happy

Actually,the mistake was in the record length of the SYMNAMES DD statement dataset.Since i was not aware of the attributes,I had changed the record length for the same to 71. I submitted the original job(by Kolusu) now with the right attributes for SYMNAMES dataset and the job ran fine.


Quote:
Your requirement was to get the "last but one" record along with the first and middle records. Your solution will get the "Last" record, unless the sequence number in your file starts with a zero. Starting a seqnum from zero isn't that common


I had put the requirement in the beginning that i need last but one record.This requirement came into picture because,last record in the input dataset always comprised of zeros.The sort card i created ,checked for the maximum value in the first five digit field ,and in this case,that happens to be the last but one record only.And because of this,the sort card i created ,fulfilled my requirement and picked up the last but one record.

I really thank you both and Frank too for making me gain a lot through this. Very Happy
_________________
Thanks,
Deepthi.

Our lives begin to end the day we become silent about things that matter.
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
Page 1 of 1

 
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