Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Adding fields of two consecutive records

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DFSORT/ICETOOL
View previous topic :: :: View next topic  
Author Message
Shriram Jogdand

New User


Joined: 14 Oct 2008
Posts: 65
Location: Pune

PostPosted: Mon May 13, 2013 2:04 am    Post subject: Adding fields of two consecutive records
Reply with quote

Hi,

I tried to search related topic on forum but I didn't get any.

I have a file having records as below

100 AAAAA
002
200 BBBBB
005
250 CCCCC
001
700 XXXXX
007

I want to do sum of first field of every two consecutive records (e.g, record no. 1&2, 3&4, 5&6, 7&8,etc). I want o/p something like this

102 AAAAA
207 BBBBB
251 CCCCC
707 XXXXX


Thanks
Back to top
View user's profile Send private message

enrico-sorichetti

Global Moderator


Joined: 14 Mar 2007
Posts: 10201
Location: italy

PostPosted: Mon May 13, 2013 2:40 am    Post subject: Reply to: Adding fields of two consecutive records
Reply with quote

if the data is EXACTLY what You showed, this snippet does it

Code:

 ****** ***************************** Top of Data ******************************
 - - -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  3 Line(s) not Displayed
 000004 //S1      EXEC PGM=SORT
 000005 //SYSPRINT  DD SYSOUT=*
 000006 //SYSOUT    DD SYSOUT=*
 000007 //SORTIN    DD *
 000008 100 AAAAA
 000009 002
 000010 200 BBBBB
 000011 005
 000012 250 CCCCC
 000013 001
 000014 700 CCCCC
 000015 007
 000016 333 ZZZZZ
 000017 222
 000018 //SORTOUT   DD SYSOUT=*,
 000019 //             DCB=(RECFM=FB,LRECL=80)
 000020 //SYSIN     DD *
 000021   OPTION EQUALS
 000022   SORT   FIELDS=(21,4,CH,A)
 000023   INREC  IFTHEN=(WHEN=GROUP,BEGIN=(5,5,CH,NE,C'     '),
 000024                  PUSH=(21:ID=4))
 000025   SUM FIELDS=(1,3,ZD)
 000026   OUTREC BUILD=(1,20,80:X)
 000027 //*
 ****** **************************** Bottom of Data ***************************


to obtain

Code:
********************************* TOP OF DATA **********************************
102 AAAAA 
205 BBBBB   
251 CCCCC           
707 CCCCC         
555 ZZZZZ       
******************************** BOTTOM OF DATA *******************************


change according to YOUR TRUE LAYOUT
disregard the control stuff in column 21
Back to top
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7223

PostPosted: Mon May 13, 2013 5:16 am    Post subject: Reply to: Adding fields of two consecutive records
Reply with quote

It should be possible with OPTION COPY and OUTFIL, REMOVECC, SECTIONS.

Remove the SORT and the SUM, replace with the above (you'll need a little detail, there are examples in the forum).
Back to top
View user's profile Send private message
Shriram Jogdand

New User


Joined: 14 Oct 2008
Posts: 65
Location: Pune

PostPosted: Mon May 13, 2013 6:19 am    Post subject: Reply to: Adding fields of two consecutive records
Reply with quote

Thanks Enrico and Bill for your reply. I should have given you the real example as first field have decimal in it and suppressed zeros. Below is the real example of file (here b means space)

100.77 AAAAA
bb2.50
200.00 BBBBB
bb5.00
250.00 CCCCC
bb1.00
700.00 CCCCC
bb7.00
300.80 ZZZZZ
b22.80
Back to top
View user's profile Send private message
mistah kurtz

Active User


Joined: 28 Jan 2012
Posts: 268
Location: Room: TREE(3). Hilbert's Hotel

PostPosted: Mon May 13, 2013 10:21 am    Post subject:
Reply with quote

In that case, you will have to make some minor changes to the SORT card which Enrico has provided.

Code:
//S1      EXEC PGM=SORT                                   
//SYSPRINT  DD SYSOUT=*                                   
//SYSOUT    DD SYSOUT=*                                   
//SORTIN    DD *                                           
100.77 AAAAA                                               
  2.50                                                     
200.00 BBBBB                                               
  5.00                                                     
250.00 CCCCC                                               
  1.00                                                     
700.00 CCCCC                                               
  7.00                                                     
300.80 ZZZZZ                                               
 22.80                                                     
//SORTOUT   DD SYSOUT=*,                                   
//             DCB=(RECFM=FB,LRECL=80)                     
//SYSIN     DD *                                           
  OPTION EQUALS                                           
  SORT   FIELDS=(21,4,CH,A)                               
  INREC  IFTHEN=(WHEN=INIT,OVERLAY(1:1,6,SFF,ZD,LENGTH=6)),
         IFTHEN=(WHEN=GROUP,BEGIN=(8,5,CH,NE,C'     '),     
                 PUSH=(21:ID=4))                           
  SUM FIELDS=(1,6,ZD)                                       
  OUTREC BUILD=(1:1,6,ZD,EDIT=(TTT.TT),7,14,80:X)


Output:
Code:
********************************* TOP OF DATA **********************************
103.27 AAAAA                                                                   
205.00 BBBBB                                                                   
251.00 CCCCC                                                                   
707.00 CCCCC                                                                   
323.60 ZZZZZ                                                                   
******************************** BOTTOM OF DATA ********************************
Back to top
View user's profile Send private message
Pandora-Box

Moderator


Joined: 07 Sep 2006
Posts: 1529
Location: Andromeda Galaxy

PostPosted: Mon May 13, 2013 12:01 pm    Post subject:
Reply with quote

Shriram,

According to your input

would you expect output as

Code:
251.00 CCCCC                                                                   
707.00 CCCCC


or

Code:
958.00 CCCCC


??
Back to top
View user's profile Send private message
enrico-sorichetti

Global Moderator


Joined: 14 Mar 2007
Posts: 10201
Location: italy

PostPosted: Mon May 13, 2013 1:54 pm    Post subject: Reply to: Adding fields of two consecutive records
Reply with quote

my bad,
it was a typo in the sample data ...
the second CCCCC should have been DDDDD,

anyway the TS asked for the sum of TWO CONSECUTIVE records,
where the first one contain NON BLANKS in position 5-9
and the second record contains BLANKS

so it is correct to show two output records even for the same <key>
Back to top
View user's profile Send private message
Pandora-Box

Moderator


Joined: 07 Sep 2006
Posts: 1529
Location: Andromeda Galaxy

PostPosted: Mon May 13, 2013 2:05 pm    Post subject:
Reply with quote

Yes Enrico as per TS requirement the solution will suit him best

But though I had this question..
Back to top
View user's profile Send private message
Shriram Jogdand

New User


Joined: 14 Oct 2008
Posts: 65
Location: Pune

PostPosted: Mon May 13, 2013 6:09 pm    Post subject: Reply to: Adding fields of two consecutive records
Reply with quote

Thanks enrico, Bill and Mistah. I got the desired output. icon_biggrin.gif
Back to top
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7223

PostPosted: Mon May 13, 2013 6:12 pm    Post subject: Reply to: Adding fields of two consecutive records
Reply with quote

Would you like to show the code, it may help someone with a similar requirement?
Back to top
View user's profile Send private message
Skolusu

Senior Member


Joined: 07 Dec 2007
Posts: 2205
Location: San Jose

PostPosted: Tue May 14, 2013 2:53 am    Post subject:
Reply with quote

I wouldn't recommend using a SORT operation for this. A COPY with sections and trailer3 would do it or even splice with COPY operation.
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 -> DFSORT/ICETOOL All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Limit duplicate records in the SORT pshongal SYNCSORT 6 Mon Nov 21, 2016 12:54 pm
No new posts How to split the records using the am... vnktrrd DFSORT/ICETOOL 24 Fri Oct 28, 2016 7:33 pm
No new posts Access SQLCA fields inside a stored p... gangapd DB2 4 Thu Oct 27, 2016 10:20 am
No new posts Sort records based on numeric field. Alks SYNCSORT 2 Wed Oct 19, 2016 10:14 pm
No new posts abend sort based on count records in ... anatol DFSORT/ICETOOL 5 Mon Oct 17, 2016 10:10 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us