file header and detail writing



Support for OS/VS COBOL, VS COBOL II, COBOL for OS/390 & VM and Enterprise COBOL for z/OS

file header and detail writing

Postby reebahs » Fri Aug 19, 2011 12:43 pm

Hi!

Could any one tel me how to create header record after reading few records with person-name ? After writing header record i should write detail records which are having the same person-name?
header record should be created only when the amount of all its detail records is >10$
detail record should be created only when the amount in that record is >0

Eg:

i/p file :

abc savings 10000
abc current 20000
pqr savings 5000
pqr current 3000
xyz savings 0
xyz current 0


o/p file:

abc ====header=== 30000
abc savings 10000
abc current 20000
pqr ====header=== 8000
pqr savings 5000
pqr current 3000


========No header record for xyz=======
========No detail record for xyz=========
reebahs
 
Posts: 28
Joined: Thu Dec 09, 2010 1:03 pm
Has thanked: 0 time
Been thanked: 0 time

Re: file header and detail writing

 

Re: file header and detail writing

Postby dick scherrer » Fri Aug 19, 2011 12:53 pm

Hello,

Does this mean there can be detail output record with no header? What should happen when the value is greater than zero but the total is not greater than 105?

How many records is the max for a person-name?
Hope this helps,
d.sch.
User avatar
dick scherrer
Global moderator
 
Posts: 6304
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 91 times

Re: file header and detail writing

Postby reebahs » Fri Aug 19, 2011 2:11 pm

Hi Dick,

There cannot be a detail record without a header.
One header record means it has atleast one detail record .
reebahs
 
Posts: 28
Joined: Thu Dec 09, 2010 1:03 pm
Has thanked: 0 time
Been thanked: 0 time

Re: file header and detail writing

Postby BillyBoyo » Fri Aug 19, 2011 5:30 pm

Assuming this is a continuation from your previous topic, accumulate a total per key. On change of key, don't write out header or detail records if your total < 10.
BillyBoyo
Global moderator
 
Posts: 3804
Joined: Tue Jan 25, 2011 12:02 am
Has thanked: 22 times
Been thanked: 264 times

Re: file header and detail writing

Postby dick scherrer » Fri Aug 19, 2011 10:34 pm

Hello,

There cannot be a detail record without a header.
One header record means it has atleast one detail record .

What should happen when the value is greater than zero but the total is not greater than 105?


If thee are 3 detail records that total 98, what should the output be?
Hope this helps,
d.sch.
User avatar
dick scherrer
Global moderator
 
Posts: 6304
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 91 times

Re: file header and detail writing

Postby reebahs » Sat Aug 20, 2011 3:29 pm

Hi Dick,

i/p file won`t be having header and detail records.
It is a sequential file with LRECL 82, all records have same layout and all are data records only.If the person-name is repeating then we need to generate a header for him by accumulating the total amt from detail amounts, we need to write detail records under that header.
Both header and detail layouts have different layouts.

ThankQ
reebahs
 
Posts: 28
Joined: Thu Dec 09, 2010 1:03 pm
Has thanked: 0 time
Been thanked: 0 time

Re: file header and detail writing

Postby BillyBoyo » Sat Aug 20, 2011 3:46 pm

Hi Dick,

The 105 is down to our aging eyes. It actually says 10 dollars, with "$" masquerading as a "5". $10 would have been easier to spot!

Hi reebahs,

Did you look at what I wrote? Your main problem, as before, is "what if there are too many detail records for my table". With the minimum value (0.01) you could still get 999 details records and not need them. You could allow for 1000, and know that you have to write them once you hit that limit, you'd have to change the logic to write the trailer at the end, then put a SORT step after your program to get the header back where you want it.

Of course, the more you know about the data, the better you can set the limit for the table.
BillyBoyo
Global moderator
 
Posts: 3804
Joined: Tue Jan 25, 2011 12:02 am
Has thanked: 22 times
Been thanked: 264 times

Re: file header and detail writing

Postby reebahs » Sat Aug 20, 2011 3:58 pm

Hi,
my input file is a sorted file where sorting is done on person-name.
And all records are data records (no header and detail records in input file).
We need to generate Header and corresponding detail records for each person-name
reebahs
 
Posts: 28
Joined: Thu Dec 09, 2010 1:03 pm
Has thanked: 0 time
Been thanked: 0 time

Re: file header and detail writing

Postby BillyBoyo » Sat Aug 20, 2011 4:44 pm

Yes?

Well, I suggest that you need another key as well, not just the name of the person. The problem is, people's names have a tendency not to be unique. You don't want to mix the data of two customers, do you? No, you don't.

It doesn't matter what your key is (as long as it is unique per customer). The work you did from your previous example will be good for this, with different key lengths, amended record layouts.

Then add the logic to only write anything if not <10. And decide how you deal with the table filling up.
BillyBoyo
Global moderator
 
Posts: 3804
Joined: Tue Jan 25, 2011 12:02 am
Has thanked: 22 times
Been thanked: 264 times

Re: file header and detail writing

Postby BillyBoyo » Sat Aug 20, 2011 5:26 pm

If you don't want to use an array, let everyone know please, not just me.

Write out all detail records. Only write headers (on change of key) if not < 10.

Post-process your file, sort, drop records which have no header. By "drop records" I would write them to a seperate file, personally, gives me a trail of where the data went. I never like just "dropping" things.
BillyBoyo
Global moderator
 
Posts: 3804
Joined: Tue Jan 25, 2011 12:02 am
Has thanked: 22 times
Been thanked: 264 times

Next

Return to IBM Cobol

 


  • Related topics
    Replies
    Views
    Last post