View previous topic :: View next topic
|
Author |
Message |
N.Nirmal Raj
New User
Joined: 19 Sep 2013 Posts: 7 Location: India
|
|
|
|
Hi,
How to process single sequential file to do rollup
of data as follows using cobol,
Requirement,
Key1 Key2 Value
a 1 0.1
a 1 0.2
a 1 0.4
b 2 0.9
b 3 0.2
b 3 0.1
c 1 0.1
c 1 0.1
Result,
Key1 Key2 Value
a 1 0.7
b 2 0.9
b 3 0.3
c 1 0.2 |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
What have you tried and what are you having trouble with?
We help with problems; we don't write code for you. Is this a homework problem? |
|
Back to top |
|
|
Pandora-Box
Global Moderator
Joined: 07 Sep 2006 Posts: 1592 Location: Andromeda Galaxy
|
|
|
|
If this is not a homework or testing of skills work would suggest to have this work with SORT aswell |
|
Back to top |
|
|
Gary McDowell
Active User
Joined: 15 Oct 2012 Posts: 139 Location: USA
|
|
|
|
If I'm not mistaken the requestor is not asking for any code (yet), and not asking for a SORT solution but a COBOL solution.
This look like a typical COBOL Control Break process. Most, if not all, "teaching" COBOL books will have examples/process.
There are many ways to accomplish Control Breaks process but this is how I tend to proceed (more or less):
In a one-time Initialize routine I Perform an input Read, and then move the input keys to Working Storage.
Something like this…
Move input-key1 to WS-KEY1. Move input-key2 to WS-KEY2. WS-KEY1 PIC X(05) i.e. 'A 1 0' WS-KEY2 PIC 9(01) i.e. 1
In your Mainline routine, Perform an Input Read, and determine if input-key1 is different from Working Storage key1 (WS-KEY1);
if different (Control Break) move your Working Storage key information to your output record, write output, and move your input "break" key to working storage key.
If key1 not different add your input key2 to Working Storage key2 (WS-KEY2).
Pseudo-code something like this…
If input-key1 not equal to WS-KEY1 {Control Break}
Move WS-KEY1 to output-key1
Move WS-KEY2 to output-key2
Perform Write
Move input-key1 to WS-KEY1 {Break key}
Move zero to WS-KEY2 [clear-out rollup accumulator]
End of If.
Add input-key2 to WS-KEY2.
Perform Read.
If you have any coding problems/questions come on back and ask! Another hint…at end-of-file be sure to move your Working Storage keys to output and write [most beginner developers miss writing the last key rollup]. Good luck. |
|
Back to top |
|
|
|