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

IF ELSE HELP

Status
Not open for further replies.

gmupatsfan

Technical User
Feb 18, 2001
4
0
0
US
Here's my code -- I'm getting too many errors to list.

400-TYPE-RTN.
IF IR-MILES <=300 MULTIPLY IR-MILES BY .12 GIVING WS-MILECHRG
MULTIPLY 15 BY CR-DAYS GIVING WS-TOTALCHRG
ELSE
SUBTRACT 300 FROM CR-MILES GIVING WS-DIFFERENCE
MULTIPLY WS-DIFFERENCE BY .10 GIVING WS-TYPEAMT1
MULTIPLY 300 BY .12 GIVING WS-TYPE3AMT
ADD WS-TYPE3AMT TO WS-TYPE3BAMT GIVING WS-MILECHRG

(if it's below 300 then the person is charged x amt of $; if its over 300 the person gets charged y amt of $ for everything over 300.

Basically, my question is are all of those statements legal in COBOL? Can you have multiple statements like that in an IF ELSE

Thank you for any help!
 
Hi G,

You can have multiple statements in an IF/ELSE as you show.
But, you must end it with a period (.) or END-IF.

It's also good form to limit a line to 1 statement. Indent-
tation is a good idea too, e.g.:
Code:
if sonso
   dothis
else
   dothat
   dotheotherthing
end-if

Hope this helps. Jack.
 
400-TYPE-RTN.

IF IR-MILES <= 300
MULTIPLY IR-MILES BY .12 GIVING WS-MILECHRG
MULTIPLY 15 BY CR-DAYS GIVING WS-TOTALCHRG
ELSE
SUBTRACT 300 FROM CR-MILES GIVING WS-DIFFERENCE
MULTIPLY WS-DIFFERENCE BY .10 GIVING WS-TYPEAMT1
MULTIPLY 300 BY .12 GIVING WS-TYPE3AMT
ADD WS-TYPE3AMT TO WS-TYPE3BAMT GIVING WS-MILECHRG
SHOULD THIS LINE BE LIKE BELOW????
ADD WS-TYPE3AMT TO WS-TYPEAMT1 GIVING WS-MILECHRG
END-IF.


Assuming all fields have correct format (numeric) it seens the 'IF' should work as above. Make sure for all your WS- fields that you either initialize them or have &quot;VALUE ZERO&quot; on the field definition line.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top