IBM Mainframe Forum Index
 
Register
 
IBM Mainframe Forum Index Mainframe: Search Log in to check your private messages Log in
 

How to process single seq file


 
IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: :: View next topic  
Author Message
N.Nirmal Raj

New User


Joined: 19 Sep 2013
Posts: 7
Location: India

PostPosted: Wed Sep 25, 2013 11:39 pm
Reply with quote

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
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8568
Location: Dubuque, Iowa, USA

PostPosted: Wed Sep 25, 2013 11:42 pm
Reply with quote

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
View user's profile Send private message
Pandora-Box

Moderator


Joined: 07 Sep 2006
Posts: 1566
Location: Andromeda Galaxy

PostPosted: Thu Sep 26, 2013 3:16 pm
Reply with quote

If this is not a homework or testing of skills work would suggest to have this work with SORT aswell
Back to top
View user's profile Send private message
Gary McDowell

Active User


Joined: 15 Oct 2012
Posts: 139
Location: USA

PostPosted: Thu Sep 26, 2013 6:11 pm
Reply with quote

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
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic All times are GMT + 6 Hours
Forum Index -> COBOL Programming
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Forum Replies
No new posts COBOL VS SORT Utility for file format... COBOL Programming 6
No new posts How to find which file contains my se... DFSORT/ICETOOL 6
No new posts Need to split single line into two li... DFSORT/ICETOOL 7
No new posts IGZ0035S THERE WAS AN UNSUCCESSFUL OP... COBOL Programming 3
No new posts Hex Value - vb file replace old date ... DFSORT/ICETOOL 14

Back to Top