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 

mulitplication in DFSORT
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
cobcurious
Beginner


Joined: 04 Oct 2003
Posts: 68
Topics: 25

PostPosted: Wed Sep 29, 2004 7:24 am    Post subject: mulitplication in DFSORT Reply with quote

Hi,
Can anybody please help me out as to how to go about multiplying the records in a file with a fixed number say -1 ?
Secondly,is it possible to add alternate records in a file with a fixed number say -1 ?
Thanks
Cobcurious
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


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

PostPosted: Wed Sep 29, 2004 7:55 am    Post subject: Reply with quote

Cobcurious,

The following JCl will multiply -1 to all records in a file.

Code:

//STEP0100 EXEC PGM=SORT                                   
//SYSOUT   DD SYSOUT=*                                     
//SORTIN   DD *                                             
123
456                                                       
//SORTOUT  DD SYSOUT=*                                     
//SYSIN    DD *                                             
  SORT FIELDS=COPY                                           
  OUTREC FIELDS=(-1,MUL,1,3,ZD,EDIT=(STTT),SIGNS=('+','-',,))
/*                                                           


The output from this job is:

Code:

-123
-456



Quote:

Secondly,is it possible to add alternate records in a file with a fixed number say -1 ?


Let me get this staright. If there are 6 records in a file , you want to add -1 to record no 2 , 4 & 6?

If that is the requirement then please post the LRECL, RECFM, position of the filed to subtracted and also the format of the field

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: Wed Sep 29, 2004 10:26 am    Post subject: Reply with quote

For complete information on using arithmetic expressions and decimal constants in DFSORT's INREC, OUTREC and OUTFIL statements, see:

http://www.storage.ibm.com/software/sort/mvs/uq90053/online/srtmurfm.html#exp

Like Kolusu, I don't understand your requirement about "alternate records". Please explain in detail what you're trying to do, and show an example of the input records and what you want the output records to look like.
_________________
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
cobcurious
Beginner


Joined: 04 Oct 2003
Posts: 68
Topics: 25

PostPosted: Wed Sep 29, 2004 11:09 pm    Post subject: Reply with quote

Hi Kolusu & Frank,
Thanks for the reply.I am sorry for not being clear on my second question. Embarassed .Regarding my second question..let me explain...suppose i have 5 records in my file say 1,2,3,4,5..then I need to add/subtract records 1,2 and 3,4 and so on...Can you please suggest me any work around this problem ?
Thanks
Cobcurious
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: Thu Sep 30, 2004 4:08 am    Post subject: Reply with quote

Cobcurious,

Is this what u r trying to do ?

Code:

Input:
123
100
246
140
500

Output: U said u need to add 1,2 and 3,4....
223
386
500


If this is the case, the following job will give u desired results. If you have DFSORT in your shop change the program name to ICETOOL instead of SYNCTOOL.

A Brief Explanation of the job. The job takes 1 Step & 4 Passes over the input file to accomplish the result.
Pass 1: The input file is split into two using OUTFIL SPLIT operand.
Pass 2: An 8 digit Sequence number is added at position 41-48 to Temp file 1
Pass 3: Same as Step 2. Seq. number is added at Pos 41-48 to Temp File 2
Pass 4: The outputs of Step 2 & 3 are merged together and sorted on the sequence number added at Position 41, so that the alternate records (of the input file) are grouped one below the other and SUM FIELDS is issued on the first three columns where we have the data.

Code:

//R010     EXEC PGM=SYNCTOOL 
//DFSMSG   DD SYSOUT=*       
//TOOLMSG  DD SYSOUT=*       
//INFILE   DD *               
123                           
100                           
246                           
140                           
500                           
/*                           
//T1       DD DSN=&&TEMP1,   
//            DISP=(,PASS)   
//T2       DD DSN=&&TEMP2,   
//            DISP=(,PASS)   
//T3       DD DSN=&&TEMP3,   
//            DISP=(,PASS)   
//T4       DD DSN=&&TEMP4,   
//            DISP=(,PASS)   
//FULLFILE DD DSN=&&TEMP3,   
//            DISP=SHR,VOL=REF=*.T3   
//         DD DSN=&&TEMP4,             
//            DISP=SHR,VOL=REF=*.T4   
//OUTFILE  DD SYSOUT=*                 
//TOOLIN   DD *                       
  COPY FROM(INFILE)    USING(CTL1)     
  COPY FROM(T1) TO(T3) USING(CTL2)     
  COPY FROM(T2) TO(T4) USING(CTL2)     
  SORT FROM(FULLFILE)  USING(CTL3)     
/*                                     
//CTL1CNTL DD *                       
  OUTFIL FNAMES=(T1,T2),SPLIT         
/*                                     
//CTL2CNTL DD *                       
  OUTREC FIELDS=(1,40,SEQNUM,8,ZD)     
/*                                     
//CTL3CNTL DD *                       
  OUTFIL FNAMES=OUTFILE               
  SORT FIELDS=(41,8,ZD,A)             
  SUM FIELDS=(1,3,ZD)   
/*                     


To subtract records, all you have to do is to Multiply the contents of File 1 or File 2 by a constant -1. Now when u issue a SUM, the records will actually be subtracted.

Hope this helps,

Kolusu / Frank, my solution uses 4 passes. Is there any other way to accomplish the result without so many passes ?

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


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

PostPosted: Thu Sep 30, 2004 4:58 am    Post subject: Reply with quote

Quote:

Kolusu / Frank, my solution uses 4 passes. Is there any other way to accomplish the result without so many passes ?


Phantom,

Sure can , The following DFSORT/ICETOOL Jcl just uses 2 passes to get the desired results.

A brief description of the solution. We first 2 seqnum's at the end using INREC. The first seqnum we use a START number as 500 and increment it by 500. So every even numbered record will have '000' . The other seqnum is a 8 byte seqnum.

Using a CHANGE command on the OUTREC FIELDS we change the '000' to a zero , and all other records we change it to 1.

Now using OUTREC On OUTFIL we add this number with the regular seqnum. By doing so every 2 records have the same seqnum.

Now sort on that seqnum and sum on the desired fields.While writting remove the seqnum.

Code:

//STEP0100 EXEC PGM=ICETOOL                             
//TOOLMSG  DD SYSOUT=*                                   
//DFSMSG   DD SYSOUT=*                                   
//IN       DD *                                         
123                                                     
100                                                     
246                                                     
140                                                     
500                                                     
//T1       DD DSN=&T1,DISP=(,PASS),SPACE=(CYL,(1,1),RLSE)
//OUT      DD SYSOUT=*                                   
//TOOLIN   DD *                                   
  COPY FROM(IN) USING(CTL1)                         
  SORT FROM(T1) USING(CTL2)                         
//CTL1CNTL DD *                                   
  INREC FIELDS=(1,40,                               
                SEQNUM,3,ZD,START=500,INCR=500,     
                SEQNUM,8,ZD)                       
  OUTREC FIELDS=(1,40,41,3,CHANGE=(1,C'500',C'1'), 
                           NOMATCH=(C'0'),             
                 44,8)                               
  OUTFIL FNAMES=T1,                                 
  OUTREC=(1,40,41,1,ZD,ADD,42,8,ZD,EDIT=(TTTTTTTT))
//CTL2CNTL DD *                                   
  SORT FIELDS=(41,8,CH,A)                           
  SUM FIELDS=(1,3,ZD)                               
  OUTFIL FNAMES=OUT,                               
  OUTREC=(1,40)                                     
/*


Note that you may have overflow when summing if the number is huge. However you can overcome that by padding zeroes.

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
Phantom
Data Mgmt Moderator
Data Mgmt Moderator


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

PostPosted: Thu Sep 30, 2004 5:15 am    Post subject: Reply with quote

Excellent !!!

Thanks so much Kolusu.
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


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

PostPosted: Thu Sep 30, 2004 5:26 am    Post subject: Reply with quote

Phantom,

If the change command is too complicated , then here is an alternative Job.

Code:

//STEP0100 EXEC PGM=ICETOOL                             
//TOOLMSG  DD SYSOUT=*                                   
//DFSMSG   DD SYSOUT=*                                   
//IN       DD *                                         
123                                                     
100                                                     
246                                                     
140                                                     
500                                                     
//T1       DD DSN=&T1,DISP=(,PASS),SPACE=(CYL,(X,Y),RLSE)
//T2       DD DSN=&T2,DISP=(,PASS),SPACE=(CYL,(X,Y),RLSE)
//CON      DD DSN=&T1,DISP=OLD,VOL=REF=*.T1
//         DD DSN=&T2,DISP=OLD,VOL=REF=*.T2
//OUT      DD SYSOUT=*                                   
//TOOLIN   DD *                                   
  COPY FROM(IN)  USING(CTL1)                         
  SORT FROM(CON) USING(CTL2)                         
//CTL1CNTL DD *                                   
  INREC FIELDS=(1,40,SEQNUM,3,ZD,START=500,INCR=500) 
  OUTFIL FNAMES=T1,INCLUDE=(41,3,ZD,C'500'),
  OUTREC=(1,40,SEQNUM,8,ZD)
  OUTFIL FNAMES=T2,SAVE,
  OUTREC=(1,40,SEQNUM,8,ZD)
//CTL2CNTL DD *       
  OPTION EQUALS                           
  SORT FIELDS=(41,8,CH,A)                           
  SUM FIELDS=(1,3,ZD)                               
  OUTFIL FNAMES=OUT,                               
  OUTREC=(1,40)                                     
/*



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
Phantom
Data Mgmt Moderator
Data Mgmt Moderator


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

PostPosted: Thu Sep 30, 2004 6:13 am    Post subject: Reply with quote

Wow,

thanks for enlightening me Kolusu...
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


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

PostPosted: Thu Sep 30, 2004 7:40 am    Post subject: Reply with quote

Phantom,

If you want to play around a little , here is a small challenge.

If there are 6 records in a file , we need to subtract 1 from even records i.e record no 2 , 4 & 6

ex:
Input:

Code:

123
100
246
140
500
600


Desired output :

Code:

123
099
246
139
500
599


The trick is to get it done in 1 pass of data.

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


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

PostPosted: Thu Sep 30, 2004 9:13 am    Post subject: Reply with quote

Kolusu,

Here is the code.

Code:

//R010     EXEC PGM=SYNCTOOL                                       
//DFSMSG   DD SYSOUT=*                                             
//TOOLMSG  DD SYSOUT=*                                             
//INFILE   DD *                                                     
123                                                                 
100                                                                 
246                                                                 
140                                                                 
500                                                                 
600                                                                 
/*                                                                 
//OUTFILE  DD SYSOUT=*                                             
//TOOLIN   DD *                                                     
  COPY FROM(INFILE) USING(CTL1)                                     
/*                                                                 
//CTL1CNTL DD *                                                     
  INREC FIELDS=(1,10,SEQNUM,1,ZD,START=5,INCR=5)                   
  OUTREC FIELDS=(1,10,11,1,CHANGE=(1,C'5',C'0'),NOMATCH=(C'1'),80:X)
  OUTFIL FNAMES=OUTFILE,OUTREC=(1:(1,3,ZD,SUB,11,1,ZD),80:X)       
/*


Did I pass the Exam ????? Question

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


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

PostPosted: Thu Sep 30, 2004 9:19 am    Post subject: Reply with quote

Phantom,

Cool trick !


Quote:

Did I pass the Exam ?????


of course you did , But you should also have taken care of the output and format of the field. With your Job you will create a 16 byte ZD fields with leading zeroes supressed, where as the Input field is only 3 bytes.

Btw avoid using synctool/icetool when it involves just 1 pass of data.

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


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

PostPosted: Thu Sep 30, 2004 9:32 am    Post subject: Reply with quote

Thanks Kolusu,

How about this code. (I saw your question very late, so I had to rush before someone posts a reply and I'm not an expert Crying or Very sad in sort to get the solution in the first run itself).

Code:

//R010     EXEC PGM=SORT                                           
//SYSOUT   DD SYSOUT=*                                             
//SORTIN   DD *                                                     
123                                                                 
100                                                                 
246                                                                 
140                                                                 
500                                                                 
600                                                                 
/*                                                                 
//SORTOUT  DD SYSOUT=*                                             
//SYSIN    DD *                                                     
  SORT FIELDS=COPY                                                 
  INREC FIELDS=(SEQNUM,1,ZD,START=5,INCR=5,1,10)                   
  OUTREC FIELDS=(1,1,CHANGE=(1,C'5',C'0'),NOMATCH=(C'1'),2,10,80:X)
  OUTFIL OUTREC=((1,1,ZD,SUB,2,3,ZD),EDIT=(TTT),80:X)               
/*                                                                 


Thanks,
Phantom
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: Thu Sep 30, 2004 9:36 am    Post subject: Reply with quote

Code:

Job you will create a 16 byte ZD fields with leading zeroes supressed


I never knew this. I was looking at my previous output and it was right justified. This is the first time I'm trying the ADD/SUB operators in sort. I learned something new today.

Thanks a lot.
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


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

PostPosted: Thu Sep 30, 2004 9:53 am    Post subject: Reply with quote

Phantom,

You are indeed an Expert in sort. So just play around a little with the requests on this board.


Kolusu
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
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