View previous topic :: View next topic
|
Author |
Message |
faizm
New User
Joined: 13 Apr 2012 Posts: 59 Location: India
|
|
|
|
Hi,
I have first created a sequential file in the program. The file has unique as well as multiple records based on contract id. For same contracts, different payments of different amount is present. Now, I need to read the last record for amount under same contract and then have to move the amount of this record into the first record of this payment and move zeroes for the amount for other records of this contract.
Here is an example: (line number increases for same)
Contract Amount line-no.
Code: |
AAAA 20.5 1
BBBB 20.0 1
BBBB 40.0 2
BBBB 60.0 3
CCCC 20.0 1 |
Result should be:
Contract Amount line-no.
Code: |
AAAA 20.5 1
BBBB 60.0 1
BBBB 00.0 2
BBBB 00.0 3
CCCC 20.0 1
|
My approach: I am first closing the file that got created and then opened it in the I-O mode. then reading the file until the contract is equal to the previous one, getting the amount and then writing the amount in the record by opening another file. Problem I am facing is as soon as the contract matches with the second contract, it is skipping from there and moving always the amount of 2nd record.
result I am getting is:
Code: |
AAAA 20.5 1
BBBB 40.0 1
BBBB 00.0 2
BBBB 00.0 3
CCCC 20.0 1
|
Could anyone help me on this. Thanks. |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8700 Location: Dubuque, Iowa, USA
|
|
|
|
Quote: |
reading the file until the contract is equal to the previous one, getting the amount and then writing the amount in the record by opening another file. |
This is where your problem is -- you cannot write any output until the contract id is NOT equal to the previous one; only then do you know the last amount value. |
|
Back to top |
|
|
faizm
New User
Joined: 13 Apr 2012 Posts: 59 Location: India
|
|
|
|
Initially I gave like (Then it is not reading the file itself and going in loop).
Read input file
move contract id into contract id hold
PERFORM xxxx-READ THRU xxxx-EXIT
UNTIL contract id NOT EQUAL contract id hold
If matches
move contact id in contract id hold
xxxx-READ
Read input file into temp file.
xxxx-EXIT |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
Is this something you need to do to create the file, or is it a subsequent update?
I've manage to avoid ever having to close and re-open a file in the same program.
Store all the data relating to a contract in working storage (your payments and any other multiple records must be in tables). On change of key on input, do whatever is necessary. Write them all out. Set up for the new contact. Repeat until End. At End, don't forget to flush-out the last contract. |
|
Back to top |
|
|
faizm
New User
Joined: 13 Apr 2012 Posts: 59 Location: India
|
|
|
|
This is a subsequent update once the file has been created. I am reading this file in the working storage only (but not in table). I was thinking of reading record one by one until matches and then rewrite the file. |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
If you apply the method above, you'll get it done without any odd close/opens etc. Thing to watch is how many of the records you can have in the table(s). Usually the system design should have covered how this would happen.
One file in, remains unchanged throughout the process. Main output file will be input to following run. If you try to change the input file, you'll give yourself more "housekeeping" and mess as well as making the program more complex. If you try to close/open the output you'll get all sorts of mess with that.
Keep It Simple Studiously. |
|
Back to top |
|
|
faizm
New User
Joined: 13 Apr 2012 Posts: 59 Location: India
|
|
|
|
since, the file get changes daily on run, not sure what maximum limit of the occurs value should be defined. |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
You might not be, but it should be somewhere in the design...
If not, your system is just not going to fly anyway :-)
Ask boss/analsyst/spec-writer/designer/tea lady etc until someone can tell you.
If it is a somehow vast number of records (presuming that it is not often more than one payment will be made in a day, and rare that payments happen every day, that should put a limit of 365 per year of data held, which you'd be quite secure with. So call it 500 per year of data, it's only program storage). |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
why maintain the line no's for a contract that are larger than the first,
with no amount?
are line no's always contiguous and start at 1?
what is the significance of line no?
seems to me, a sort,
that would sum the amounts for a contract
and
either count or use the highest line no
thus outputting one record per account
would be a solution to your problem.
there is no need on earth to justify keeping the zero amount records. |
|
Back to top |
|
|
faizm
New User
Joined: 13 Apr 2012 Posts: 59 Location: India
|
|
|
|
right, if same contract is present multiple times, then each contract will be assigned with the line number sequntially increasing and the total amount of all these records should appear in the first record.
can you give me some idea (psuedo code) how I can use the line number to get the highest amount which is always present in the last record. Just need to get this amount and write in the first record. rest records to be updated with zeroes.
Thanks. |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
give me a good reason to output zero-amount records. |
|
Back to top |
|
|
Jose Mateo
Active User
Joined: 29 Oct 2010 Posts: 121 Location: Puerto Rico
|
|
|
|
Good afternoon to all!
Dick has a point. You could also sort the file by contract number in ascending order and the sequence number (the field after the amount) by descending order. Then process the file by taking the amount of the first record and save it. Zero the amount and on all of the following records with the same contract number. When there's a break on contract number write the previous record with the saved amount. Do the same logic with the rest of the contract numbers. After processing all the records you could then sort the file again to it's original order. |
|
Back to top |
|
|
faizm
New User
Joined: 13 Apr 2012 Posts: 59 Location: India
|
|
|
|
Hi Jose,
I have the sorted file now with amount at the top. Do I need to use the array concept here or I can get it without using it. I am directly using the If else logic and but not getting the desired result. The value in all of the records for same contract is getting zero except for the line one where the amount is as it is and not getting updated with the first amount. I don't want to use the array concept here as I am not very good at it.
Could you please help me out. Thanks. |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
why do you need to output zero-amount records? |
|
Back to top |
|
|
faizm
New User
Joined: 13 Apr 2012 Posts: 59 Location: India
|
|
|
|
Dick, this is the requirement in my project. |
|
Back to top |
|
|
Akatsukami
Global Moderator
Joined: 03 Oct 2009 Posts: 1787 Location: Bloomington, IL
|
|
|
|
faizm wrote: |
Dick, this is the requirement in my project. |
When you questioned this requirement, what response did the system analyst(s) on the project team give? |
|
Back to top |
|
|
faizm
New User
Joined: 13 Apr 2012 Posts: 59 Location: India
|
|
|
|
could any one help me on this.Please. |
|
Back to top |
|
|
Nic Clouston
Global Moderator
Joined: 10 May 2007 Posts: 2454 Location: Hampshire, UK
|
|
|
|
Array concept? In COBOL? Do you mean table as COBOL does not have arrays? If you do then you had better become familiar with it asap or give up programming. |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
You could sort on Contract, Ascending, Line, Descending.
In your program, save the first value for a contract in W-S. Set amount to zero, write the record. For the same contract, set all others line amounts to zero and write until you get Line number one. Put the saved amount on that record and write it.
Sort on Contract, Ascending, Line, Ascending.
Do you have other data on the records? Is that why you want to keep the zero values?
If you don't have to keep the zeros (with the data you have shown they have no meaning except the line number, and the highest/next line number could always be held "somewhere"), it is even more simple. Ignore all the lines except the last for a contract, and set that line number to 1 before writing it. You could add the values of those you are ignoring and confirm that the last is the correct value (I would).
Tables are nothing to be afraid of. If you are unsure about them, get some practice with them., enough until you are sure about them You are going to need them many, many times. |
|
Back to top |
|
|
faizm
New User
Joined: 13 Apr 2012 Posts: 59 Location: India
|
|
|
|
Bill, I used the way you told. Perfect, I am able to resolve the issue. Thanks.
Thank you all . |
|
Back to top |
|
|
|