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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

need loop code to add numbers in a column

Status
Not open for further replies.

rexxjunior

Programmer
Sep 8, 2007
2
US
Help ! I need to add up numbers in a mainframe PS file.
I get the value of the last number + the same last number (40 +40 = 80) instead of the total of all the numbers.
can anyone show me how to do this the correct way?

here is my code and the sample of the file I am reading

"EXECIO 0 DISKR INDD (OPEN"
EOF = 'NO'
DO WHILE EOF = 'NO'
"EXECIO 1 DISKR INDD (STEM LINE."
IF RC = 2 THEN
EOF = 'YES'
ELSE
DO
AMT = LINE.1
SAY AMT
IF AMT ¬= 0 THEN
DO
LINESUM = AMT + AMT
SAY LINESUM
END
END
END
"EXECIO 0 DISKR INDD (FINIS"

***********************************************

SAMPLE DATASET

15
805
1260
20
40



 
First, don't issue an EXECIO to OPEN, one for each record, and another to CLOSE. Write it as:
Code:
   "EXECIO * DISKR INDD (STEM LINE. FINIS"
The OPEN happens automatically, the entire file is read into "stem.", and the FINIS closes the file at EOF.

Why? Because TSO fetches the EXECIO code each time you invoke the function. This takes time.

Then, you can avoid using "AMT" for two things... which is the source of your error:
Code:
total = 0 
do zz = 1 to stem.0
   parse var line.zz amt . 
   total = total + amt 
end


Frank Clarke
Tampa Area REXX Programmers' Alliance
REXX Language Assn Listmaster
 
Thanks rexxhead!

I had to make an adjustment in the code
I was getting 'bad arithmetic conversion' on
do zz= 1 to stem.0
I changed stem.0 to line.0 and it worked ok

thank you very much

rexxjunior

total = 0
do zz = 1 to stem.0 <<< changed to line.0
parse var line.zz amt .
total = total + amt
end
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top