View previous topic :: View next topic
|
Author |
Message |
ajaikumar andy robert Warnings : 1 New User
Joined: 01 Dec 2006 Posts: 23 Location: India
|
|
|
|
hi i need to group records present in a file based on one field..
say for example,
if there is a field acct-no in the file for every record, then i have to group all the records based on this acct-no.
similarly after grouping i have to sum up another field in every record.. say there is an amount field in each record, i have to sum up all the amount values in the file after the records are grouped.
it ll be very helpful if i get the solution ASAP..
|
|
Back to top |
|
|
nbalajibe Warnings : 1 New User
Joined: 28 Nov 2006 Posts: 75 Location: India
|
|
|
|
HI,
U can use loops using condition to seperate the records based on the filed.
Inside the loop itself u can keep adding the amount of those records which satisfy the condition.
Inform me if i'm wrong. |
|
Back to top |
|
|
William Thompson
Global Moderator
Joined: 18 Nov 2006 Posts: 3156 Location: Tucson AZ
|
|
|
|
Sort and sum. |
|
Back to top |
|
|
guptae
Moderator
Joined: 14 Oct 2005 Posts: 1208 Location: Bangalore,India
|
|
|
|
Hi ajaikumar andy robert,
It can be done using sort if u give us file layout then we will be able to provide u sort card. |
|
Back to top |
|
|
SSR Warnings : 1 New User
Joined: 26 Feb 2006 Posts: 38
|
|
|
|
Hi,
You can sort the file based on the account number(using the position of account number) and then sum it.
This can be done using JCL sort i think that would be more efficient.
Regards
SSR |
|
Back to top |
|
|
ajaikumar andy robert Warnings : 1 New User
Joined: 01 Dec 2006 Posts: 23 Location: India
|
|
|
|
thank you guys for all those replies..
but how do i group the records in cobol, that too based on one field?
is there any specific or command to do so?
if not can any of u give me a sample syntax for this grouping and finding the sum of the amount field..
the file consists of some 40 fields and has a total length of 930..
the field acct-no occupies the position 34-42..
the amount field is in the position 560-574..
assume ther are 50 records in the file..
now can any of u give me a sample syntax for groupin these records based on the acct-no field pls....... |
|
Back to top |
|
|
Arun Raj
Moderator
Joined: 17 Oct 2006 Posts: 2481 Location: @my desk
|
|
|
|
Hi
Do you want this to be done through COBOL pgm???
Thanks
Arun |
|
Back to top |
|
|
William Thompson
Global Moderator
Joined: 18 Nov 2006 Posts: 3156 Location: Tucson AZ
|
|
|
|
Create a 50 row table with an account number field and an amount field (don't forget to initialize the fields).
Read a record and scan the table looking for an account number match.
If found, add the record amount to the table amount.
If not found, find the first "empty" row and move the account number and amount from the record to that row.
At eof, done (unless you wanted them sorted also ). |
|
Back to top |
|
|
|