I had a situation recently where I wanted to multiply an unknown number of percents within a procedure and then multiply that result by a price and put the result into a variable and then when it was all finished, a field in a row would be set = to the variable. The idea being that depending on the situation there could be 3 numbers, 5 numbers, or 20 numbers. Let's say the situation is that I have a bunch of items, and I also have a bunch of coupons for a % off of the items. You can combine the coupons, so to compute the price you need the total effect of the coupons multiplied by the price. There are probably many ways to do this, and this is hardly the best way, but the answer I am after is specifically how to get the out variable from the multiply function into the parent compute function. Here is the table of items.
Here is the table of coupons.
Here is the Multiply Procedure
Here is the Compute Procedure
So I want to use the EFac variable in Compute as the Out variable for Multiply. When I run it I get "Function multiply has invalid parameter 'Res1'('OUT') Please explain how to use the Out variable correctly.
asked
Siger Matt |

[ What version and build do you use? Your As you basically want to use a simple mathematical function, I would recommend to use a function like:
Using a function will additionally make the use inside a second procedure easier (and more comprehensible). I still don't get the exact requirements (as said, treat this as mere remarks), but usually you can use a (The situation is different when the calls of the procedure/function are independent of each other. Then you could simply embed a function call in a select list of a query or use the procedure with a so-called So inside your procedure Compute (again turned into a function) you might use a FOR statement as a very convenient cursor loop:
Note: All statements are untested but should give you a hint.
answered
Volker Barth Absolutely, This gives many hints for the future. If the example was more complicated, say with multiple return values so a function would not work anymore, what is the correct way to bring the OUT variable from the one procedure into the parent procedure? 1
A procedure which returns a result set can be called just like a table in the FROM clause, and thus you can reference multiple columns from the (single?) returned row in the SELECT list etcetera. SELECT * FROM proc_name ( in_parameters ) is EXTREMELY powerful and valuable. @Breck: Whereas Siger explicitly asked for several out parameters (and so I tried to answer @Breck: That is indeed helpful and I had not considered using it that way. I will use that construction for something in the future for sure. Thank you. |

Additional answer for Say, you need to compute an integer division and would like to get both the quotient and the remainder in one call. That cannot be done with a function, and so you might use something like the following:
You would call that procedure in another procedure similar to the following block (note: the declare with initialization is new in a V12). Obviously, you have to declare variables in the outer procedure to use them as arguments for the out parameters ("Call by reference" in PL terms).
answered
Volker Barth |

(Not an answer, just needed the code formatting) That makes absolute sense and it was how I thought it should work. But even when I strip down my example to match yours to the following:
//==========================================================
I still get the error when I run compute... I really appreciate the help.
answered
Siger Matt It was asked before and I did not answer -- I am using SQL Anywhere version 11.0.1.2472 1
In SQL Anywhere, procedures are called by "CALL ...", not EXECUTE (as in Transact-SQL). EXECUTE is for dynamic SQL execution. Beautiful. That was the problem. Thank you again! |

First of all, multiply should be created as a FUNCTION because that is how it is used. Second, functions have "RETURNS" values, not OUT parameters: Create function multiply (in mult1 int, in mult2 int) returns int begin... Third, there may be other issues, like the interesting use of COUNT, but you wanted a specific answer to the OUT error.

Yes that makes sense. If the example was more complicated and returned multiple things to OUT Parameters, what would be the correct way to have them come out of the one procedure to be used in the parent procedure?