View previous topic :: View next topic
|
Author |
Message |
Shriram Jogdand
New User
Joined: 14 Oct 2008 Posts: 65 Location: Pune
|
|
|
|
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 |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10872 Location: italy
|
|
|
|
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 |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
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 |
|
|
Shriram Jogdand
New User
Joined: 14 Oct 2008 Posts: 65 Location: Pune
|
|
|
|
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 |
|
|
mistah kurtz
Active User
Joined: 28 Jan 2012 Posts: 316 Location: Room: TREE(3). Hilbert's Hotel
|
|
|
|
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 |
|
|
Pandora-Box
Global Moderator
Joined: 07 Sep 2006 Posts: 1592 Location: Andromeda Galaxy
|
|
|
|
Shriram,
According to your input
would you expect output as
Code: |
251.00 CCCCC
707.00 CCCCC |
or
?? |
|
Back to top |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10872 Location: italy
|
|
|
|
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 |
|
|
Pandora-Box
Global Moderator
Joined: 07 Sep 2006 Posts: 1592 Location: Andromeda Galaxy
|
|
|
|
Yes Enrico as per TS requirement the solution will suit him best
But though I had this question.. |
|
Back to top |
|
|
Shriram Jogdand
New User
Joined: 14 Oct 2008 Posts: 65 Location: Pune
|
|
|
|
Thanks enrico, Bill and Mistah. I got the desired output. |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
Would you like to show the code, it may help someone with a similar requirement? |
|
Back to top |
|
|
Skolusu
Senior Member
Joined: 07 Dec 2007 Posts: 2205 Location: San Jose
|
|
|
|
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 |
|
|
|