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

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: 8696
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

Global Moderator


Joined: 07 Sep 2006
Posts: 1592
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 View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts How to split large record length file... DFSORT/ICETOOL 7
No new posts Extracting Variable decimal numbers f... DFSORT/ICETOOL 17
No new posts SFTP Issue - destination file record ... All Other Mainframe Topics 2
No new posts Access to non cataloged VSAM file JCL & VSAM 18
No new posts Need help for File Aid JCL to extract... Compuware & Other Tools 23
Search our Forums:

Back to Top