Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Need help with logic

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
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    Post subject: Need help with logic
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

Site Director


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

PostPosted: Thu Aug 26, 2010 9:16 am    Post subject:
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    Post subject:
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    Post subject:
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    Post subject:
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    Post subject:
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    Post subject:
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

Site Director


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

PostPosted: Thu Aug 26, 2010 7:33 pm    Post subject:
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    Post subject:
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

Site Director


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

PostPosted: Fri Aug 27, 2010 8:31 am    Post subject: Reply to: Need help with logic
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    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Wildcard logic in COBOL dudenithy COBOL Programming 13 Thu Sep 01, 2016 7:36 pm
No new posts Sort Logic to extract data scorp_rahul23 DFSORT/ICETOOL 13 Tue Mar 01, 2016 1:22 am
No new posts Need a logic to validate the data in ... sandeep kumar302 COBOL Programming 17 Mon Feb 01, 2016 3:30 pm
No new posts Tricky sort logic required pgopi92 DFSORT/ICETOOL 3 Mon Jan 25, 2016 3:29 pm
No new posts DB2 - CURRENT DATE + 2 YRS logic balaji81_k DB2 3 Thu Nov 26, 2015 3:07 am


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us