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

Adding fields of two consecutive records


IBM Mainframe Forums -> DFSORT/ICETOOL
Post new topic   Reply to topic
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
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

Superior Member


Joined: 14 Mar 2007
Posts: 10872
Location: italy

PostPosted: Mon May 13, 2013 2:40 am
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

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Mon May 13, 2013 5:16 am
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
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: 316
Location: Room: TREE(3). Hilbert's Hotel

PostPosted: Mon May 13, 2013 10:21 am
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

Global Moderator


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

PostPosted: Mon May 13, 2013 12:01 pm
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

Superior Member


Joined: 14 Mar 2007
Posts: 10872
Location: italy

PostPosted: Mon May 13, 2013 1:54 pm
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

Global Moderator


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

PostPosted: Mon May 13, 2013 2:05 pm
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
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

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Mon May 13, 2013 6:12 pm
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
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 View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DFSORT/ICETOOL

 


Similar Topics
Topic Forum Replies
No new posts Compare only first records of the fil... SYNCSORT 7
No new posts Pulling a fixed number of records fro... DB2 2
No new posts Adding QMF and SPUFI to the ISPF menu DB2 20
No new posts Sort First/last record of a subset th... DFSORT/ICETOOL 7
No new posts Adding first / last acct numerber to ... DFSORT/ICETOOL 7
Search our Forums:

Back to Top