Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

clearing up something

Status
Not open for further replies.

lostso

Technical User
Oct 22, 2002
13
US
Ok I am doing a calc routine with Gross sales, discount, and net sales. Now I know I got to move them in the calc routine which is like my 200 process, but would I move them again in my 300 process when I move everything else.
 
Hi lostso,

Moving variables around is warranted by your logic. What are you trying to accomplish?

Dimandja
 
Well I have to calculate totals of individual thins in my program. Now I declared all of the things in a data record even Gross sales, Discount, and Net Sales. Now I move all these records from the Data record in my 300 process. My question would be since Gross sales, Discount, and Net Sales are in that Data Record. Do I move them again since I moved them in my calc routine.
 
Whether you move something or not is a function of your program design or algorithm. In most cases, it is desirable to minimize the number of moves you do, but not at the expense of repeated calculations or unclear coding.

I try to put the result of a calculation where I need it. If I only need to print it, I store the calculation result directly in the print line. However, if I am likely to need the result later, I'll put it in a WORKING-STORAGE field:
Code:
COMPUTE WS-EARNINGS = RATE * HOURS
MOVE WS-EARNINGS      TO PR-EARNINGS
COMPUTE PR-TAXES    = WS-EARNINGS * TAX-RATE
[\CODE]
Note WS- fields are in WORKING-STORAGE and PR- fields are in the record I will print.

Of course, you also have to pay attention to data type.  In the case of total fields, they should be a COMPUTATIONAL type because you're doing lots of arithmetic with them.  Since you generally can't directly print COMPUTATIONAL fields in a pleasing way, you generally MOVE the total field to a print record field when it's time to print totals. E.G.:

Open files
Read first record
Perform until EOF
  add record totals to working storage totals
  Read next record
end perform
move working storage totals to print line totals
print the totals
close the files
stop run

Glenn
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top