View previous topic :: View next topic
|
Author |
Message |
sabarikanth
New User
Joined: 07 Jun 2010 Posts: 59 Location: coimbatore
|
|
|
|
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 |
|
|
Binop B
Active User
Joined: 18 Jun 2009 Posts: 407 Location: Nashville, TN
|
|
|
|
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... |
|
Back to top |
|
|
saurabh39 Warnings : 1 Active User
Joined: 11 Apr 2008 Posts: 144 Location: Jamshedpur
|
|
|
|
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 |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
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 |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
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 . . .
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 |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
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 |
|
|
sabarikanth
New User
Joined: 07 Jun 2010 Posts: 59 Location: coimbatore
|
|
|
|
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 |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Good to hear it is working - thanks for the followup
Someone will be here if there are additional questions.
d |
|
Back to top |
|
|
|