Page 1 of 2

file header and detail writing

PostPosted: Fri Aug 19, 2011 12:43 pm
by reebahs
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=========

Re: file header and detail writing

PostPosted: Fri Aug 19, 2011 12:53 pm
by dick scherrer
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?

Re: file header and detail writing

PostPosted: Fri Aug 19, 2011 2:11 pm
by reebahs
Hi Dick,

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

Re: file header and detail writing

PostPosted: Fri Aug 19, 2011 5:30 pm
by BillyBoyo
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.

Re: file header and detail writing

PostPosted: Fri Aug 19, 2011 10:34 pm
by dick scherrer
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?

Re: file header and detail writing

PostPosted: Sat Aug 20, 2011 3:29 pm
by reebahs
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

Re: file header and detail writing

PostPosted: Sat Aug 20, 2011 3:46 pm
by BillyBoyo
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.

Re: file header and detail writing

PostPosted: Sat Aug 20, 2011 3:58 pm
by reebahs
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

Re: file header and detail writing

PostPosted: Sat Aug 20, 2011 4:44 pm
by BillyBoyo
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.

Re: file header and detail writing

PostPosted: Sat Aug 20, 2011 5:26 pm
by BillyBoyo
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.