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

How to update the sequential file having same records.


IBM Mainframe Forums -> COBOL Programming
Post new topic   This topic is locked: you cannot edit posts or make replies.
View previous topic :: View next topic  
Author Message
faizm

New User


Joined: 13 Apr 2012
Posts: 59
Location: India

PostPosted: Fri Apr 13, 2012 5:56 pm
Reply with quote

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

Global Moderator


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

PostPosted: Fri Apr 13, 2012 6:07 pm
Reply with quote

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

New User


Joined: 13 Apr 2012
Posts: 59
Location: India

PostPosted: Fri Apr 13, 2012 6:19 pm
Reply with quote

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

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Fri Apr 13, 2012 6:21 pm
Reply with quote

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

New User


Joined: 13 Apr 2012
Posts: 59
Location: India

PostPosted: Fri Apr 13, 2012 7:09 pm
Reply with quote

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

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Fri Apr 13, 2012 7:19 pm
Reply with quote

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

New User


Joined: 13 Apr 2012
Posts: 59
Location: India

PostPosted: Fri Apr 13, 2012 7:27 pm
Reply with quote

since, the file get changes daily on run, not sure what maximum limit of the occurs value should be defined.
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Fri Apr 13, 2012 7:33 pm
Reply with quote

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

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Fri Apr 13, 2012 7:57 pm
Reply with quote

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

New User


Joined: 13 Apr 2012
Posts: 59
Location: India

PostPosted: Fri Apr 13, 2012 8:05 pm
Reply with quote

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

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Fri Apr 13, 2012 9:25 pm
Reply with quote

give me a good reason to output zero-amount records.
Back to top
View user's profile Send private message
Jose Mateo

Active User


Joined: 29 Oct 2010
Posts: 121
Location: Puerto Rico

PostPosted: Sat Apr 14, 2012 12:12 am
Reply with quote

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

New User


Joined: 13 Apr 2012
Posts: 59
Location: India

PostPosted: Sat Apr 14, 2012 7:15 pm
Reply with quote

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

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Sat Apr 14, 2012 7:38 pm
Reply with quote

why do you need to output zero-amount records?
Back to top
View user's profile Send private message
faizm

New User


Joined: 13 Apr 2012
Posts: 59
Location: India

PostPosted: Sat Apr 14, 2012 7:46 pm
Reply with quote

Dick, this is the requirement in my project.
Back to top
View user's profile Send private message
Akatsukami

Global Moderator


Joined: 03 Oct 2009
Posts: 1788
Location: Bloomington, IL

PostPosted: Sat Apr 14, 2012 8:05 pm
Reply with quote

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

New User


Joined: 13 Apr 2012
Posts: 59
Location: India

PostPosted: Sat Apr 14, 2012 8:29 pm
Reply with quote

could any one help me on this.Please.
Back to top
View user's profile Send private message
Nic Clouston

Global Moderator


Joined: 10 May 2007
Posts: 2455
Location: Hampshire, UK

PostPosted: Sat Apr 14, 2012 10:55 pm
Reply with quote

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

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Sun Apr 15, 2012 2:30 am
Reply with quote

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

New User


Joined: 13 Apr 2012
Posts: 59
Location: India

PostPosted: Sun Apr 15, 2012 4:20 pm
Reply with quote

Bill, I used the way you told. Perfect, I am able to resolve the issue. Thanks.

Thank you all icon_smile.gif.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   This topic is locked: you cannot edit posts or make replies. 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 10
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 Compare only first records of the fil... SYNCSORT 7
Search our Forums:

Back to Top