View previous topic :: View next topic
|
Author |
Message |
sm_2009
New User
Joined: 10 May 2009 Posts: 72 Location: bangalore
|
|
|
|
hi All,
i need a help reading a file using array and calculate the total cost.
Input file is like this :-
Code: |
01 ws-file-rec-in.
05 emp-name-in pic x(4) value spaces.
05 detail-in occurs 10 times.
10 description-in pic x(20) value spaces.
10 cost-in pic 9(5)v99 value zeroes.
10 type-in pic x value spaces. |
i need to find total cost.
Input file may be like this -
AAAAFEVER AND HOSPITALISED200.00MHIGH FEVER300.00MCOLD AND COUGH100.00MDENTAL PROBLEM50.00DDENTALPROB2100.00DSHORTSIGHTEDNESS300.00V
My requirement is to find out total-cost-medical, total-cost-dental and total-cost-vision
please help me write code for this
thanks |
|
Back to top |
|
|
sm_2009
New User
Joined: 10 May 2009 Posts: 72 Location: bangalore
|
|
|
|
forgot to add one more field in input file.
that is ws-count
it carries total no of occurence, here ws-count = 6 |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
if you would use code tags for your data layout, it could help you to visualize the table.
Code: |
01 ws-file-rec-in.
05 emp-name-in pic x(4) value spaces.
05 ws-count pic 99.
05 detail-in occurs 10 times.
10 description-in pic x(20) value spaces.
10 cost-in pic 9(5)v99 value zeroes.
10 type-in pic x value spaces. |
Since this structure will be populated by a READ,
it does not make much sense to use the VALUE clause.
Also, I would assign Level-88's to type-in.
Code: |
01 ws-file-rec-in.
05 emp-name-in pic x(4).
05 ws-count pic 99.
05 detail-in occurs 10 times
indexed by detail-in-idx.
10 description-in pic x(20).
10 cost-in pic 9(5)v99.
10 type-in pic x.
88 type-in-dental value 'D'.
88 type-in-vision value 'V'.
88 type-in-medical value 'M'.
88 valid-type-in values 'M', 'D', 'V'. |
1. use the indexed by clause for cobol internal tables.
2. the picture clause for the cost-in field does not jive with your example with regard to size or datatype. |
|
Back to top |
|
|
sm_2009
New User
Joined: 10 May 2009 Posts: 72 Location: bangalore
|
|
|
|
hey Thanks a lot
i know the simplest array code to read cost until sub = count
but how to write IF clause while redaing data or adding amounts; that i am not getting. can you pls suggest |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
you have to declare some working-storage fields to accumulate your 3 types of cost.
don't need an IF
Code: |
open
perform process & read until status <> '00'
print results
goback
process & read:
read
evaluate true
when status = '00'
perform varying detail-in-index
from 1
by 1
until detail-in-index > ws-count
evaluate true
when cost-medical
compute ws-total-medical = ws-total-medical + cost-in(detail-in-index) end-compute
when cost-dental
compute ws-total-dental = ws-total-dental + cost-in(detail-in-index) end-compute
when cost-vision
compute ws-total-vision = ws-total-vision + cost-in(detail-in-index) end-compute
when other
display 'cost-in-type invalid '
ws-file-rec-in
end-evaluate
when status = 10
continue
when other
display 'read status:' status
display 'last record read ' ws-file-rec-in
end-evaluate
Read & Process exit.
exit.
|
|
|
Back to top |
|
|
sm_2009
New User
Joined: 10 May 2009 Posts: 72 Location: bangalore
|
|
|
|
thanks a lot. it will suffice my req. |
|
Back to top |
|
|
Bill O'Boyle
CICS Moderator
Joined: 14 Jan 2008 Posts: 2501 Location: Atlanta, Georgia, USA
|
|
|
|
If your compiler is (at a minimum) COBOL/370 (early 1990's), review the INTRINSIC FUNCTION named SUM.
Regards, |
|
Back to top |
|
|
|