7.81.2 RETURN Examples
In this example, a subroutine uses the RETURN command rather than a complex IF-ELSE structure:
SUBROUTINE NAME(MATHS) PARMS(#F1 #OP #F2 #RS)
DEFINE FIELD(#F1) TYPE(*DEC) LENGTH(7) DECIMALS(0)
DEFINE FIELD(#OP) TYPE(*CHAR) LENGTH(1)
DEFINE FIELD(#F2) TYPE(*DEC) LENGTH(7) DECIMALS(0)
DEFINE FIELD(#RS) TYPE(*DEC) LENGTH(15) DECIMALS(5)
IF COND('#OP = ''+''')
CHANGE FIELD(#RS) TO('#F1 + #F2')
RETURN
ENDIF
IF COND('#OP = ''-''')
CHANGE FIELD(#RS) TO('#F1 - #F2')
RETURN
ENDIF
IF COND('#OP = ''*''')
CHANGE FIELD(#RS) TO('#F1 * #F2')
RETURN
ENDIF
IF COND('#OP = ''/''')
CHANGE FIELD(#RS) TO('#F1 / #F2')
RETURN
ENDIF
MESSAGE MSGTXT('Operation specified is not +,-,* or /')
ENDROUTINE