View previous topic :: View next topic
|
Author |
Message |
baljinders
New User
Joined: 21 Aug 2006 Posts: 72
|
|
|
|
Hi All,
I need to know how this can be achieved using cobol program. The file has the following records. Record type 3 contains the invoice record
Record type date Amt
*Client 1
--------
2
3 20100511 10
4
*Client 2
--------
2
3 20100511 10
3 20100511 20
4
*Client 3
--------
2
3 20100511 10
3 20100511 10
3 20100514 20
4
*Client 4
--------
2
3 20100511 10
3 20100512 20
3 20100516 30
3 20100519 40
4
My requirement is that i need to write an invoice based on the combination of record type and date.
2 and 4 record denote one client. Record 3 contains invoices for the particular client. One invoice will be written when multiple 3 records within a client has same date. But if dates are different then different invoices will be written for the client.
In the above file, 1 invoice will be written for cleint 1, 1 invoice will be written for client 2 with accumulated amount and 2 invoices will be written for client 3. 3 invoice will be written for client 4.
I am able to write invoice for client 1 and 2 . but not for client 3 and 4. In my logic i use an evaluate statement for different record types. I write only when the combination of record type 3 and its date are different for a client. I comapre the date with the previous date and if they are equal i process record 3 , accumulate their amount and write only when i reach record 4. But my logic is not working for cases like client 3 and 4.
Can anyone give any idea about who to approach this.
The file lrecl is 200 bytes and is FB. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
Read the file and within the type 3 records and use the date to implement a control break. Also, keep track when the client changes.
Each time the client changes or the date changes, write an invoice for the previous "group". A group might only contain 1 entry, but that should not be a problem. Something that would make a difference is if the invoice is to be only a summary or if each line item is to be shown. . . |
|
Back to top |
|
|
baljinders
New User
Joined: 21 Aug 2006 Posts: 72
|
|
|
|
Dick,
I am doing something like this. Don't have the actual code right now.
Evaluate record-type
when 1
do something
when 2
do something
when 3
check if date = prev date
if equal , set date-match-switch = Y
add amt to out-amt
else
move amnt to out-amnt
move date to prev-date
process record 3
when 4
set date-match-switch = n
write record 3
write record 4
end evaluate
Here when there is only one record 3 , it gets written. when it has two record 3's with matching date they also get written. But porblem arises when their are multiple 3 record with different dates.
Say for example , in client -3, there are three record 3's. during the 1st record read, the record gets processed and is not written yet. for the second record since the date is equal, the amt get accumulated but not written yet. third record has a different date now. now i need to write the previous record with the accumulated amt and then write the third record. but my logic does not do as required. Here it will only write the 3rd record within the client.
Wht needs to be changed here ? |
|
Back to top |
|
|
Bharath Bhat
Active User
Joined: 20 Mar 2008 Posts: 283 Location: chennai
|
|
|
|
Code: |
when 3
if date = prev date
set date-match-switch = Y
add amt to out-amt
else
move amnt to out-amnt
move date to prev-date
write record 3
end-if |
|
|
Back to top |
|
|
baljinders
New User
Joined: 21 Aug 2006 Posts: 72
|
|
|
|
Bharat ,
This will not work in case where two records within a client has matching date.
Check tge below case, as per you code , it will write two invoices. whereas it should only write one invoice with the accumulated amount.
*Client 2
--------
2
3 20100511 10
3 20100511 20
4 |
|
Back to top |
|
|
Bharath Bhat
Active User
Joined: 20 Mar 2008 Posts: 283 Location: chennai
|
|
|
|
From what I can see, it will write only 1 record for the example given. Please note that the write is within the else statement. So if the date is matching, it will not write anything as it goes into the if statement. |
|
Back to top |
|
|
Kjeld
Active User
Joined: 15 Dec 2009 Posts: 365 Location: Denmark
|
|
|
|
You should add code if the date not = prev-date to write the invice lines already processed. The condition should not be raised for the first record of a new customer.
Code: |
Evaluate record-type
when 1
do something
when 2
do something
when 3
check if date = prev date
if equal , set date-match-switch = Y
add amt to out-amt
else
write record 3 <--- added
move amnt to out-amnt
move date to prev-date
process record 3
when 4
set date-match-switch = n
write record 3
write record 4
end evaluate
|
|
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
Quote: |
You should add code if the date not = prev-date to write the invice lines already processed. The condition should not be raised for the first record of a new customer. |
Yup - what Kjeld said. . .
Keep in mind that the "last output" needs to be written when end-of-file is detected. |
|
Back to top |
|
|
baljinders
New User
Joined: 21 Aug 2006 Posts: 72
|
|
|
|
Thanks Dick , Kjeld and Bharat
The code worked after inserting the write statement as stated above by Kjeld. Thanks a ton. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
You're welcome - thank you for letting us know it is working
d |
|
Back to top |
|
|
|