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

How to check repetations?


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
sabarikanth

New User


Joined: 07 Jun 2010
Posts: 59
Location: coimbatore

PostPosted: Sat Aug 07, 2010 3:11 pm
Reply with quote

Hi all,
This may be a simple question.
But i need a solution for this.

My question is,
I have to check a group of values from a database which has a primary key say for e.g Emp.Number. Here this emp.number has another set of number inturn called Roll.Number. This Roll.Number has a value. The Roll.Number can be repeated any number of times(There may be duplicates). Here i need to calculate the sum of the repeated Roll.Number's value together for a Emp.Number. If their is no repeated values it must give the same value.

Please go thru the example.

Let me Give u an example:
Code:
Emp.Number- 00100

Roll.number :1 value-10
Roll.number :2 value-20
Roll.number :3 value-30
Roll.number :1 value-40
Roll.number :2 value-50
Roll.number :6 value-60


My output should be sum of oly repeated Roll.numbers:

Code:
10+40=50 for Roll.number :1
20+50=70 for Roll.number :2
and
30 for Roll.number :3
60 for Roll.number :6


Please help me with a sample code to begin with.

Thanks,
Sabari
Back to top
View user's profile Send private message
Binop B

Active User


Joined: 18 Jun 2009
Posts: 407
Location: Nashville, TN

PostPosted: Sat Aug 07, 2010 4:01 pm
Reply with quote

Hi Sabari,

Quote:
Please help me with a sample code to begin with.
Sorry to dampen your spirit... but this is not how we work here... Start with your coding or design... and in case you are facing any problems, surely some one here should be able to help you ....

On a personal note...
Could you please provide a sample for us to know exactly how your input is and what is expected in the output... Please dont have anything else (calculations, comments, ... ) inside the code tag ... that's confusing... icon_sad.gif
Back to top
View user's profile Send private message
saurabh39
Warnings : 1

Active User


Joined: 11 Apr 2008
Posts: 144
Location: Jamshedpur

PostPosted: Sat Aug 07, 2010 9:54 pm
Reply with quote

HI Sabari,

If I understand your question......which is just to add up or sum values for a duplicate roll number......then i guess you should start looking at Sort rather than coding logic in COBOL. It will save you lot of time & hassles
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Sat Aug 07, 2010 11:32 pm
Reply with quote

sounds like simple enough sql.

had you explained it properly, you would have had a head start:

you want the sum of the values for like emp_no and like roll number.

or,
you want your results to reflect a 'GROUPed BY' accumulation.


you want to select the emp_no, roll_no, and a sum of the value column.
combine that with a group by clause and order by.

hint:
you use sum in the select,
so that the group by can sum the duplicates,
and with an Aggregate function - SUM(VALUE) - in the select,
it does not have to be part of the group by clause.
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


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

PostPosted: Sun Aug 08, 2010 1:43 am
Reply with quote

Hello,

Quote:
then i guess you should start looking at Sort rather than coding logic in COBOL. It will save you lot of time & hassles

Not . . . icon_sad.gif

There is rarely a good reason to to drop cobol code for sort code. . .

In fact, more than 99% of business requirements need more processing than a sort alone can accomplish. . . When a sort solution can meet an entire requirement it may be the best choice, but on any "real" system there are multiple inputs and outputs including qsam fles, vsam files, and database info. . .

To add to what DBZ mentioned - the requirement does not sound overly complicated. If it cannot be clearly described, it will be almost impossible to implement. . .
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Sun Aug 08, 2010 6:41 pm
Reply with quote

if this needs to be done completely in cobol code,
1. insure that your input is sorted on the double-key
2. read input - eof output last accumulation - goback
3. if new double-key = last double-key accumulate value, goto read
4. output accumulation, move new double-key and value to last, goto read
Back to top
View user's profile Send private message
sabarikanth

New User


Joined: 07 Jun 2010
Posts: 59
Location: coimbatore

PostPosted: Mon Aug 09, 2010 12:10 pm
Reply with quote

Hi all,
Thanks for your comments. Sorry for late reply.
I started to code in COBOL. Because my requirement is to code in COBOl.
I cant use SQl codes here. I got the aggregate value with simple preform statement and i used IDMS for binding the database. thank you all. If in case I have any concerns i'l reach you.

Thanks,
Sabari.
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


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

PostPosted: Mon Aug 09, 2010 7:49 pm
Reply with quote

Good to hear it is working - thanks for the followup icon_smile.gif

Someone will be here if there are additional questions.

d
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 SCOPE PENDING option -check data DB2 2
No new posts Check data with Exception Table DB2 0
No new posts How to check whether who renamed the ... JCL & VSAM 3
No new posts No ++JCLIN, APPLY CHECK job JCL & VSAM 1
No new posts EMPTY file check scenario JCL & VSAM 6
Search our Forums:

Back to Top