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

Need help with logic


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
baljinders

New User


Joined: 21 Aug 2006
Posts: 72

PostPosted: Thu Aug 26, 2010 8:58 am
Reply with quote

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

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Thu Aug 26, 2010 9:16 am
Reply with quote

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

New User


Joined: 21 Aug 2006
Posts: 72

PostPosted: Thu Aug 26, 2010 10:26 am
Reply with quote

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

Active User


Joined: 20 Mar 2008
Posts: 283
Location: chennai

PostPosted: Thu Aug 26, 2010 10:42 am
Reply with quote

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

New User


Joined: 21 Aug 2006
Posts: 72

PostPosted: Thu Aug 26, 2010 11:19 am
Reply with quote

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

Active User


Joined: 20 Mar 2008
Posts: 283
Location: chennai

PostPosted: Thu Aug 26, 2010 12:52 pm
Reply with quote

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

Active User


Joined: 15 Dec 2009
Posts: 365
Location: Denmark

PostPosted: Thu Aug 26, 2010 5:01 pm
Reply with 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.
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
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Thu Aug 26, 2010 7:33 pm
Reply with quote

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

New User


Joined: 21 Aug 2006
Posts: 72

PostPosted: Fri Aug 27, 2010 8:05 am
Reply with quote

Thanks Dick , Kjeld and Bharat

The code worked after inserting the write statement as stated above by Kjeld. Thanks a ton.
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Fri Aug 27, 2010 8:31 am
Reply with quote

You're welcome - thank you for letting us know it is working icon_smile.gif

d
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts Finding faulty logic Subscript out of... COBOL Programming 5
This topic is locked: you cannot edit posts or make replies. Need assistance in job scheduling logic. Mainframe Interview Questions 2
No new posts Rexx Logic error while adding seperat... CLIST & REXX 3
No new posts PL/1 Callback address logic in z/OS C... PL/I & Assembler 1
No new posts Sync logic between VSAM files and DB2... COBOL Programming 9
Search our Forums:

Back to Top