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
 

 

calculate count for duplicate records

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

New User


Joined: 21 Aug 2006
Posts: 72

PostPosted: Fri Jul 30, 2010 3:01 am    Post subject: calculate count for duplicate records
Reply with quote

Hi,

Can anyone help me with the logic for getting the below output. The input file is a sequential file . Filed 1 and 2 are the key. The 3rd field in the output file is the counter for number of duplicate occurances per unique key value.

INPUT
----------
Field1 Field2
AAA 111
AAA 111
AAA 111
BBB 111
BBB 222
CCC 111
CCC 111

OUTOUT
------------
AAA 111 3
BBB 111 1
BBB 222 1
CCC 111 2
Back to top
View user's profile Send private message

bipinpeter

Active User


Joined: 18 Jun 2007
Posts: 208
Location: Cochin/Kerala/India

PostPosted: Fri Jul 30, 2010 10:17 am    Post subject:
Reply with quote

hI baljinders,
tRY THE BELOW CODE


Code:
SORT FIELDS=(1,7,CH,A)
         INREC FIELDS=(1,7,8:C'001')
         SUM FIELDS=(8,3,ZD)
Back to top
View user's profile Send private message
baljinders

New User


Joined: 21 Aug 2006
Posts: 72

PostPosted: Fri Jul 30, 2010 10:22 am    Post subject:
Reply with quote

Thanks Bipin,

But i want to do it through a cobol program...Also field 1 and Field2 are not contiguos i.e there are some other fields in between them...i should have mentioned it earlier...
Back to top
View user's profile Send private message
dick scherrer

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Fri Jul 30, 2010 10:35 am    Post subject:
Reply with quote

Hello,

You need to post what you have done so far and explain where your are stuck.

We will help you work on your code but will not write it for you (if the complete code is posted, it will be deleted).

If your data is in sequence you need to read the file accumulating the count for each "key". Each time a new key is detected, print the previous key and the accumulated count.
Back to top
View user's profile Send private message
baljinders

New User


Joined: 21 Aug 2006
Posts: 72

PostPosted: Fri Jul 30, 2010 10:53 am    Post subject:
Reply with quote

The approach is something like this.. i am not sure it its correct.

Read file
at end
move y to eof
not at end
add 1 to rec-cnt.

process-para.

If ((field1 = ws-field1) and (field2=ws-field2))
add +1 to counter
else
move +1 to counter
move field1 to ws-field1
move field2 to ws-field2
end-if

perform write-para.

inital value of working storage fields is spaces. Here i am trying to do a match with the previous field values, if match is found , i increment the counter else i move 1 to the counter. But i m stuck at how to write the record with the count value of duplicates records whenever a unique record is encountered. I also need to write if the there''s is only one occurance of the record. in that case the counter will contain value as 1.

I don't have my actual code with me right now, but its similar to this approach.
Back to top
View user's profile Send private message
xknight

Active User


Joined: 22 Jan 2008
Posts: 117
Location: Liberty city

PostPosted: Fri Jul 30, 2010 3:39 pm    Post subject: Reply to: calculate count for duplicate records
Reply with quote

D you need to just calculate the count or sort the records and display in o/p files,

To do that,

1) Should sort the i/p file for the binary sort.
2) Determine the count and sort the records eventually.

PSEUDOCODE:

1) SORT THE FILE

READ I/P FILE
AT END SET 'Y' TO EOF

WS-ARRAY1 PIC 9(9) OCCURS 999999.

ADD +1 WS-STOCK

MOVE WS-FIELD1 TO WS-ARRAY1(WS-STOCK)
MOVE WS-FIELD2 TO WS-ARRAY2(WS-STOCK)

< --REST OF THE PROCESS -->

2) NOW WE HAVE THE TOTAL RECORDS COUNT, AND FROM FILE THE RECORDS HAS BEEN MOVED TO THE OCCURANCE.

3) SHALL SORT THE RECORDS

PERFORM UNTIL SW-SORTED = 'N'
MOVE 1 TO WS-I-CNTR
PERFORM UNTIL WS-I-CNTR >= WS-J-CNTR
IF (( WS-FIELD1(I) & WS-FIELD2(I) > WS-FIELD1(I+1) & WS- FIELD2(I+1) ))
THEN
MOVE WS-FIELD1(I) = WS-FIELD1-TEMP
MOVE WS-FIELD1-(I+1) TO WS-FIELD1(I)
MOVE WS-FIELD1-TEMP TO WS-FIELD1(I+1)
MOVE 'N' TO SW-SORTED
ELSE
MOVE 'Y' TO SW-SORTED
END-IF
COMPUTE WS-I-CNTR = WS-I-CNTR + 1
END-PERFORM
COMPUTE J-CNTR = J-CNTR - 1
END-PERFORM
END-PERFORM

Hope this helps
Back to top
View user's profile Send private message
expat

Global Moderator


Joined: 14 Mar 2007
Posts: 8593
Location: Back in jolly old England

PostPosted: Fri Jul 30, 2010 3:53 pm    Post subject:
Reply with quote

baljinders wrote:
But i want to do it through a cobol program...Also field 1 and Field2 are not contiguos i.e there are some other fields in between them...i should have mentioned it earlier...
I want to ...

Hello, but what am I missing here. Surely the most efficient and readily available method of getting what you want is far easier than wasting the time and money of your employer in reinventing the wheel.

If your personal wants are so overwhelming then call your SORT product from a COBOL program and waste the minimum amount of resource.
Back to top
View user's profile Send private message
dick scherrer

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Sat Jul 31, 2010 2:59 am    Post subject:
Reply with quote

Hello,

Most often there is more to a requirement than simply counting by some key. . . Most often these "other parts of the requirement" are not posted in these topics (which often causes them to grow as the additional details of the requirement become known).

Also, many organizations do no permit "sort-grams" - the standard for the organization is one or more coding languages - not utility statements for things like sort, file-aid, etc.

When someone asks for help with a cobol (or some other language) requirement, i believe we should support this (after all most posters here are programmers of one kind or another) and not send them to a sort, file-aid, selcopy, etc solution.

I believe in exploiting the "programming features" of the sort products as well as other utilities, but i also believe that actually using code ia quite important also.
Back to top
View user's profile Send private message
baljinders

New User


Joined: 21 Aug 2006
Posts: 72

PostPosted: Sat Jul 31, 2010 11:30 am    Post subject:
Reply with quote

Hi All,

I wanted to use cobol because that was the requirement given to me. That's the reason i posted it on cobol section instead of sort utility section. I know sort would give me the desired result with minimum of effort. But sometimes we got to do things the way the organisation wants it done.

In my case it turned out that i was given wrong information and we are indeed allowed to use sort utility . Its just that we are not allowed to use Icetool.

So got my desired result using the below sort card.

SORT FIELDS=(1,3,CH,A,5,3,CH,A)
SUM FIELDS=(8,5,ZD)
INREC BUILD=(1,7,C'00001')
OUTREC BUILD=(1,7,C' ',8,5)

Thanks everyone for your time and help. You guys are simply awesome. I will stilll go ahead and try to use the psuedo code given by xavierrajnaveen

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

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Sun Aug 01, 2010 4:51 am    Post subject: Reply to: calculate count for duplicate records
Reply with quote

Good to hear you have a solution - thank you for posting what you used icon_smile.gif

Quote:
I will stilll go ahead and try to use the psuedo code given by xavierrajnaveen
If there are any questions/problems, reply back here and someone will be able to help.

d
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 Count the length of the record & ... sreekusr DFSORT/ICETOOL 4 Thu Mar 23, 2017 7:52 pm
No new posts Display FTP Session Count within TSO Yolanda Harvey TSO/ISPF 3 Fri Mar 10, 2017 10:31 pm
No new posts Join giving more records than expected Danielle.Filteau SYNCSORT 2 Thu Mar 09, 2017 3:28 am
No new posts TSO or command line utility to genera... kishpra JCL & VSAM 3 Thu Mar 09, 2017 1:11 am
No new posts Extract set of records matching on ac... bhaskar_kanteti DFSORT/ICETOOL 3 Mon Mar 06, 2017 7:19 am


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