Page 1 of 1

Compute in a procedure

Posted: Mon Aug 25, 2014 1:38 pm
by mboldin
Why does the following program produce errors ?
The problem is with the FX2 proc that produces an error at
compute fend= fstart + steps - 1
## SX15. Trying to Store into Constant or Expression. Called Parameter by Value?

Code: Select all

PROC fx1 
   option integer fstart
   option integer steps  1

	local integer fend
  	compute fend= fstart + steps - 1

	disp "FX1: " %datelabel(fstart) %datelabel(fend) steps

END

PROC fx2 
   option integer fstart
   option integer steps  1
   option integer fend 

	if %defined(fend) .eq. 0  
  		{ compute fend= fstart + steps - 1  }

	disp "FX2: "  %datelabel(fstart) %datelabel(fend) steps

END



cal 2000 1 4
all 0 2015:4
compute end2 = 2014:2
compute start = end2 + 1
compute fperiods= 6

@fx1(fstart=start,steps=fperiods)

@fx2(fstart=start,steps=fperiods)
FX1() works but I wanted to define FEND based on other options if not defined at the call
I get the error even if the @FX2(_) command is removed and the proc is not called

FYI in some runs I get these errors too
## CP17. PROCEDURE/FUNCTION Must be Initial Statement in a Compiled Section
## CP24. PROCEDURE/FUNCTION FX2 compiled with errors. Please correct

Re: Compute in a procedure

Posted: Mon Aug 25, 2014 2:20 pm
by TomDoan
In the second procedure, FEND is passed by value, so it's (effectively) a constant as far as the procedure is concerned (hence the message). To do what you want, you need to use a local variable for the working value, such as

local integer fendl

if %defined(fend).eq.0
compute fendl = fstart+steps-1
else
compute fendl = fend

disp "FX2: " %datelabel(fstart) %datelabel(fendl) steps