Portal | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Forum Index
 
Register
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Profile Log in to check your private messages Log in
 
Sum based on criteria for each id, each name

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
Soumya Bhat

New User


Joined: 01 May 2020
Posts: 1
Location: India

PostPosted: Fri May 01, 2020 11:57 pm    Post subject: Sum based on criteria for each id, each name
Reply with quote

Hi All,

I have a query. I want to know if this can be achieved by using JCL or a COBOL program is required. If JCL or COBOL, then what is the way to achieve it? I m trying to do via COBOL program. Its seems to be getting more complex than required.

Please find the more details below:
INput file ---->
1st column is id, 2nd column is type, 3rd column is record type, 4th column is value, 5th column is name

123 0000 000 00000 -> Header rec
123 0001 002 00555 XYZ
123 0001 002 00600 XYZ
123 0001 002 00200 ABC
123 0001 002 00250 ABC
123 0008 002 00050 XYZ
123 0009 002 00010 LMN
234 0000 000 00000
234 0001 002 00200 XYZ
234 0001 002 00250 XYZ
234 0008 002 00050 OOO

Output criteria:
1. no change in header record, should be copied as it is
2. Total for value should be done only when type is '1' and record type is '2'(detail record)
3. Different total should be done for each 'id'
(a) within each 'id', different total for each "name"
3. rest all records other than type '1' should be written as it is

Output record:

123 0000 000 00000
123 0001 002 01155 XYZ
123 0001 002 00450 ABC
123 0008 002 00050 XYZ
123 0009 002 00010 LMN
234 0000 000 00000
234 0001 002 00450 XYZ
234 0008 002 00050 OOO
Back to top
View user's profile Send private message

daveporcelan

Active Member


Joined: 01 Dec 2006
Posts: 741
Location: Pennsylvania

PostPosted: Sat May 02, 2020 12:20 am    Post subject:
Reply with quote

I am sure you can do it with COBOL, it does not appear too complex.

I am sure you CAN NOT do it with JCL, as all IT professionals know that JCL can ONLY call a program to perform a function.

With that being understood, I was able to do it easily with Syncsort.

I ignored most of your 'criteria' and assume that your input data is a correct representation of reality (probably foolish of me).

By this I mean that 0000 000, 0008 002, 0009 002 are never duplicated for a particular ID and name.

If this is indeed true, then here is a very simple Syncsort solution:

Code:
//SORT1      EXEC PGM=SORT
//*
//SYSUDUMP   DD SYSOUT=*
//SYSOUT     DD SYSOUT=*
//*
//SORTIN     DD *
123 0000 000 00000 -> HEADER REC
123 0001 002 00555 XYZ
123 0001 002 00600 XYZ
123 0001 002 00200 ABC
123 0001 002 00250 ABC
123 0008 002 00050 XYZ
123 0009 002 00010 LMN
234 0000 000 00000
234 0001 002 00200 XYZ
234 0001 002 00250 XYZ
234 0008 002 00050 OOO
/*
//*
//SORTOUT    DD DSN=MY.OUTPUT.DATASET,
//           DISP=(NEW,CATLG,CATLG),
//           UNIT=SYSDA,
//           SPACE=(TRK,(1,5),RLSE)
//*
//SYSIN      DD *
  SORT FIELDS=(1,12,CH,A,20,3,CH,A)
  SUM FIELDS=(14,5,ZD)


Results:
Code:
123 0000 000 00000 -> HEADER REC
123 0001 002 00450 ABC
123 0001 002 01155 XYZ
123 0008 002 00050 XYZ
123 0009 002 00010 LMN
234 0000 000 00000
234 0001 002 00450 XYZ
234 0008 002 00050 OOO
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts How to process dependent file based o... HithaSri JCL & VSAM 8 Sun Sep 06, 2020 12:42 pm
This topic is locked: you cannot edit posts or make replies. SORT the records based on the second ... Ramsee SYNCSORT 1 Wed Aug 19, 2020 3:01 pm
No new posts How to filter out certain records bas... manugeorge2004 JCL & VSAM 5 Wed Jun 17, 2020 10:05 pm
No new posts Include Group record based on detail ... guptae DFSORT/ICETOOL 11 Thu Mar 12, 2020 1:54 pm
No new posts Conditional step execution based on P... Lccole10 JCL & VSAM 9 Wed Feb 19, 2020 10:07 pm

Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us