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
 

 

calculate total cost using ARRAY

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
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    Post subject: calculate total cost using ARRAY
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    Post subject: Reply to: calculate total cost using ARRAY
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    Post subject:
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    Post subject: Reply to: calculate total cost using ARRAY
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    Post subject:
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    Post subject: Reply to: calculate total cost using ARRAY
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: 2502
Location: Atlanta, Georgia, USA

PostPosted: Thu May 21, 2009 7:40 pm    Post subject: Reply to: calculate total cost using ARRAY
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    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 Dynamic array request/response contai... Suja.Sai CICS 2 Tue Jan 24, 2017 11:37 am
No new posts How to calculate an specific transact... lind sh CICS 2 Tue Sep 13, 2016 9:20 pm
No new posts Unstring list of values into an array. Roshnii COBOL Programming 8 Mon Jun 27, 2016 6:25 pm
No new posts Calculate a timeframe with DFsort Gerd Hofmans DFSORT/ICETOOL 6 Thu Jan 14, 2016 5:30 pm
No new posts COBOL Program to Read Array data raj4neo COBOL Programming 8 Sat Aug 15, 2015 12:28 am


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