IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Sum based on criteria for each id, each name


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
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
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: 792
Location: Pennsylvania

PostPosted: Sat May 02, 2020 12:20 am
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 View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts To search DB2 table based on Conditio... DB2 1
This topic is locked: you cannot edit posts or make replies. Merge 2 input files based on the reco... JCL & VSAM 2
No new posts Split large FB file based on Key coun... DFSORT/ICETOOL 4
No new posts Mass JCL release via IDZ tool(eclipse... CA Products 1
No new posts Merge 2 lines based on Space from a S... DFSORT/ICETOOL 5
Search our Forums:

Back to Top