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

calculate total cost using ARRAY


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

New User


Joined: 10 May 2009
Posts: 72
Location: bangalore

PostPosted: Thu May 21, 2009 6:51 pm
Reply with quote

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

New User


Joined: 10 May 2009
Posts: 72
Location: bangalore

PostPosted: Thu May 21, 2009 6:55 pm
Reply with quote

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

Global Moderator


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

PostPosted: Thu May 21, 2009 7:05 pm
Reply with quote

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

New User


Joined: 10 May 2009
Posts: 72
Location: bangalore

PostPosted: Thu May 21, 2009 7:16 pm
Reply with quote

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

Global Moderator


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

PostPosted: Thu May 21, 2009 7:33 pm
Reply with quote

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

New User


Joined: 10 May 2009
Posts: 72
Location: bangalore

PostPosted: Thu May 21, 2009 7:39 pm
Reply with quote

thanks a lot. it will suffice my req.
Back to top
View user's profile Send private message
Bill O'Boyle

CICS Moderator


Joined: 14 Jan 2008
Posts: 2501
Location: Atlanta, Georgia, USA

PostPosted: Thu May 21, 2009 7:40 pm
Reply with quote

If your compiler is (at a minimum) COBOL/370 (early 1990's), review the INTRINSIC FUNCTION named SUM.

Regards,
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 how to calculate SUM value for VB fil... DFSORT/ICETOOL 1
No new posts how to calculate SUM for VB file usin... JCL & VSAM 1
No new posts Null values are considered in Total c... DFSORT/ICETOOL 6
No new posts RACF cost vs. ACF2 cost IBM Tools 2
No new posts COBOL Ascending and descending sort n... COBOL Programming 5
Search our Forums:

Back to Top