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 

Finding out the total of a particular field.

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Job Control Language(JCL)
View previous topic :: View next topic  
Author Message
mainframemouli
Beginner


Joined: 23 Feb 2005
Posts: 87
Topics: 33

PostPosted: Tue Sep 13, 2005 12:38 pm    Post subject: Finding out the total of a particular field. Reply with quote

This is my input file ( i given some records there more than 8000 records)
Code:

RPT-HED-TYPE  RPT-CONTROL-1-2  RPT-UNION-CODE  RPT-CONTRACT-NBR
C(1) (1-1)      C(6) (2-7)             C(5) (8-12)                  Z(3) (13-15)   
------------  ---------------          --------------                      ----------------
1              NSAR00                  01445                                 002               
1              NSAR00                  01445                                 002               
1              NSAR00                  01445                                 002               
1              NSAS00                  01445                                 002               
1              NSAU00                  01445                                002               
1              NSAU00                  01445                                003               


RPT-DEDUCTION-AMT
ZS(3,2) (121-125)
-----------------
A ***************
+008.25         
+016.50         
+008.25         
+008.25         
+006.75         
+005.00         
+006.75         


The Output file should have only one record that is for 01445 and the RPT-DEDUCTION-AMT field should contain its summation of all values.

I tried with the following two Jcls...
//STEP0001 EXEC PGM=ICETOOL                                 
//DFSMSG   DD SYSOUT=*                                     
//TOOLMSG  DD SYSOUT=*                                     
//TOOLIN   DD *                                             
  SORT FROM(IN) TO(OUTX) USING(ICE0)                       
/*                                                         
//IN       DD DSN=XX2.SMS.N0HR0.JHRU2.FILE.SORT,DISP=SHR   
//OUTX     DD DSN=XX2.SMS.N0HR0.JHRU2.FILE.SUM,             
//         DISP=(,CATLG,DELETE),                           
//         DCB=(BLKSIZE=0,LRECL=275,RECFM=FB),             
//         UNIT=DASD,SPACE=(CYL,(5,5),RLSE)                 
//ICE0CNTL DD *                                             
  OPTION ZDPRINT                                           
  SORT   FIELDS=(8,5,CH,A)                               
  SUM    FIELDS=(121,5,ZD)                                 
/*                                                         
//                             


and

//PSTEP020 EXEC PGM=SORT                                 
//SYSOUT   DD  SYSOUT=*                                   
//SYSPRINT DD  SYSOUT=*                                   
//*                                                       
//SORTIN   DD DSN=XX2.SMS.N0HR0.JHRU2.FILE.SORT,DISP=SHR 
//SYSIN    DD *                                           
   SORT FIELDS=(8,5,CH,A),EQUALS               
   SUM FIELDS=(121,5,ZD)                                 
//SORTOUT  DD DSN=XX2.SMS.N0HR0.JHRU2.FILE.SUM,           
//         DISP=(,CATLG,DELETE),                         
//         DCB=(BLKSIZE=0,LRECL=275,RECFM=FB),           
//         UNIT=DASD,SPACE=(CYL,(5,5),RLSE)               
//           


I am trying to sort by RPT-UNION-CODE = 01445

But i am instead of a single record i am getting some 46 records in both the jcl output...
can anyone pls clarify this....how the jcl should be...
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


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

PostPosted: Tue Sep 13, 2005 1:32 pm    Post subject: Reply with quote

mainframemouli,

Ok lets us clarify something here.

You are summing on the field at 121 for 5 bytes and you show the quantities with imbedded decimal point. You would get S0c7 abend when you try to sum the zoned decimal with imbedded decimal point.

How is the summing field defined in cobol?

Kolusu
_________________
Kolusu - DFSORT Development Team (IBM)
DFSORT is on the Web at:
www.ibm.com/storage/dfsort

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


Joined: 23 Feb 2005
Posts: 87
Topics: 33

PostPosted: Tue Sep 13, 2005 10:19 pm    Post subject: Reply with quote

This is layout for that file.

045400 01 WS-REPORT-RECORD.
045400 03 RPT-HED-TYPE PIC X(01) VALUE SPACES.
045400 03 RPT-CONTROL-1-2 PIC X(06) VALUE SPACES.
045400 03 RPT-UNION-CODE PIC X(05) VALUE SPACES.
045400 03 RPT-CONTRACT-NBR PIC 9(03) VALUE ZEROS.
045400 03 RPT-LOCATION PIC X(04) VALUE SPACES.
045400 03 RPT-DEPARTMENT PIC X(04) VALUE SPACES.
045400 03 RPT-JOB-CODE PIC X(06) VALUE SPACES.
045400 03 RPT-EMPLOYEE-NAME.
045400 05 RPT-LAST-NAME PIC X(30) VALUE SPACES.
045400 05 RPT-FIRST-NAME PIC X(30) VALUE SPACES.
045400 05 RPT-MIDDLE-INIT PIC X(01) VALUE SPACES.
045400 03 RPT-HED PIC X(03) VALUE SPACES.
045400 03 RPT-EMPL-SSN PIC X(09) VALUE SPACES.
045400 03 RPT-WK-END-DATE.
045400 05 RPT-WK-END-CC PIC X(02) VALUE SPACES.
045400 05 RPT-WK-END-YY PIC X(02) VALUE SPACES.
045400 05 RPT-WK-END-MM PIC X(02) VALUE SPACES.
045400 05 RPT-WK-END-DD PIC X(02) VALUE SPACES.
045400 03 RPT-PROCESS-DATE.
045400 05 RPT-PROCESS-CC PIC X(02) VALUE SPACES.
045400 05 RPT-PROCESS-YY PIC X(02) VALUE SPACES.
045400 05 RPT-PROCESS-MM PIC X(02) VALUE SPACES.
045400 05 RPT-PROCESS-DD PIC X(02) VALUE SPACES.
045400 03 RPT-PAYMENT-TYPE PIC X(02) VALUE SPACES.
045400 03 RPT-DEDUCTION-AMT PIC S9(03)V99 VALUE ZEROS.
045400 03 RPT-EMPL-DATE.
045400 05 RPT-EMPL-CC PIC X(02) VALUE SPACES.
045400 05 RPT-EMPL-YY PIC X(02) VALUE SPACES.
045400 05 RPT-EMPL-MM PIC X(02) VALUE SPACES.
045400 05 RPT-EMPL-DD PIC X(02) VALUE SPACES.
045400 03 RPT-SENIORITY-DATE.
045400 05 RPT-SENIORITY-CC PIC X(02) VALUE SPACES.
045400 05 RPT-SENIORITY-YY PIC X(02) VALUE SPACES.
045400 05 RPT-SENIORITY-MM PIC X(02) VALUE SPACES.
045400 05 RPT-SENIORITY-DD PIC X(02) VALUE SPACES.
045400 03 RPT-RESULT-STATUS PIC X(02) VALUE SPACES.
045400 03 RPT-RES-STAT-DESC PIC X(20) VALUE SPACES.
045400 03 RPT-TERM-DATE.
045400 05 RPT-TERM-CC PIC X(02) VALUE SPACES.
045400 05 RPT-TERM-YY PIC X(02) VALUE SPACES.
045400 05 RPT-TERM-MM PIC X(02) VALUE SPACES.
045400 05 RPT-TERM-DD PIC X(02) VALUE SPACES.
045400 03 RPT-ADDRESS-1 PIC X(30) VALUE SPACES.
045400 03 RPT-ADDRESS-2 PIC X(30) VALUE SPACES.
045400 03 RPT-CITY PIC X(30) VALUE SPACES.
045400 03 RPT-STATE PIC X(02) VALUE SPACES.
045400 03 RPT-ZIP-CODE PIC X(05) VALUE SPACES.
045400 03 RPT-EMPL-go-away-spammer-sucker PIC X(01) VALUE SPACES.



Here this is the cobol declarationn for that filed 03 RPT-DEDUCTION-AMT PIC S9(03)V99 VALUE ZEROS.

I am not using a cobol program for thsi...can i do this is JCl itself or i need to write a cobol program for this
Back to top
View user's profile Send private message
ANIL SARATHY
Beginner


Joined: 30 Aug 2005
Posts: 88
Topics: 3
Location: Syracuse,New york

PostPosted: Wed Sep 14, 2005 12:12 am    Post subject: Reply with quote

INCLUDE COND=(8,5,CH,EQ,C'01445')
SORT FIELDS=(8,5,CH,A)
SUM FIELDS=(121,5,ZD)

This should get desired result.


Previuosly your trying to sort on field , but not on value in field.
Sum field will sum records whose sort field value are same or equal.

I guess u have 46 different values in sort field RPT-UNION-CODE . ( like 01445,0122, xxxxx...).

Sum field should be anumeric , not a edited value.

otherwie u have to go for inrec and outrec, if it is edited value.

Smile
_________________
Anil Sarathy
Back to top
View user's profile Send private message Send e-mail Yahoo Messenger
mainframemouli
Beginner


Joined: 23 Feb 2005
Posts: 87
Topics: 33

PostPosted: Wed Sep 14, 2005 3:03 am    Post subject: Reply with quote

Quote:
I guess u have 46 different values in sort field RPT-UNION-CODE . ( like 01445,0122, xxxxx...).


all the Values in the Input file for RPT-UNION-CODE is 01445 only
hence there is nessesity to have include condition over there...
Back to top
View user's profile Send private message
ANIL SARATHY
Beginner


Joined: 30 Aug 2005
Posts: 88
Topics: 3
Location: Syracuse,New york

PostPosted: Wed Sep 14, 2005 3:32 am    Post subject: Reply with quote

If the lengh of input file and output file is equal , then this problem occurs

i/p file :

aaaa8888bb
aaaa8888cc if summed on 5th -8th position

o/p file :

aaaa8888bb
aaaa8888cc


If ur output file is 11 bytes or more than ( using inrec)

inrec=( 1:1,4,6:5,4,10:9,2)
sort fields=(....)
sum fields=(6,4,zd)

aaaa17776bb.

Since the sum is greater than 4 digits.
_________________
Anil Sarathy
Back to top
View user's profile Send private message Send e-mail Yahoo Messenger
Phantom
Data Mgmt Moderator
Data Mgmt Moderator


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

PostPosted: Wed Sep 14, 2005 3:46 am    Post subject: Reply with quote

Mainframemouli,

Quote:

all the Values in the Input file for RPT-UNION-CODE is 01445 only


So, the reason for getting multiple records after SUM is due to SUM-OVERFLOW. SORT tries to sum as many records it can accomodate whose Total sum <= 5 digits. If there is a overflow then the record which causes the overflow and subsequent records are summed up separately (again limited to 5 digits) are written as 2nd record and so on....

So, if you are sure that the SUM is going to exceed 5 digits, use INREC and prefix couple of zeroes (to be used as Carry-Over digits) before the field to be summed up.

Code:

INREC FIELDS=(1,120,               *  First 120 Bytes *
              C'0000',121,5,       *  Prefix 4 zeroes before Amount field*
              126,150)             *  Copy rest of data *
SORT FIELDS=(8,5,CH,A)
SUM FIELDS=(121,9,ZD)              * Note: length is increased to 9 *


You can also force Sort to abend incase of an SUM Overflow.

Hope this helps,

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


Joined: 23 Feb 2005
Posts: 87
Topics: 33

PostPosted: Thu Sep 15, 2005 2:58 am    Post subject: Reply with quote

Thanks Phantom and Anil ,
You are correct , there is Sum overflow , i used Inrec and now its working.
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 -> Job Control Language(JCL) 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