[EMAIL PROTECTED] schrieb am 14.02.02: > I have a stored procedure to calculate total cost. It goes through customer's > shopping cart and add total cost for each item in the shopping cart: > > CREATE DBPROC getSCSubTotal (IN sc_id fixed(10,0), OUT sub_total fixed(17,2)) > AS > VAR cost fixed(17,2); qty fixed(3,0); > BEGIN > set sub_total=0; > SELECT scl_cost,scl_qty from tpcw.shopping_cart_line where scl_sc_id=1; > while $rc=0 do begin > fetch into :cost, :qty; > set sub_total=sub_total+cost*qty; > end; > END; > > The strange thing is when it executes, it always add 1 more cost. For example, > there are 3 items in shopping cart, > item1 cost1 qty1 > item2 cost2 qty2 > item3 cost3 qty3 > after execution, sub_total=cost1*qty1+cost2*qty2+cost3*qty3++cost3*qty3 > > I think I copyed the sample from reference manual on page 149, except for > using BEGIN/END instead of TRY/CATCH. > > Aslo, is there a message explaination manual for SQL return code? > > Thanks, > Jenny > _______________________________________________ > sapdb.general mailing list > [EMAIL PROTECTED] > http://listserv.sap.com/mailman/listinfo/sapdb.general
Hi Jenny, you seemed to have missed a small detail. The next to last time you check $rc you did not have yet a successful fetch and so no error is indicated though the fetch will not be successful. Exceptions are kind of asynchronous wrt. to the command flow (the failing fetch will be forwarded to the catch ). So you might need to add another check that leaves the loop (ugly) or stick with the TRY/CATCH mechanism. As I am still quite ignorant regarding the procedure language and could not find the documentation yet (hints where appreciated) I regret that I cannot give you a correction for your example. kind regards Wolf N�cker (who at 3 am is looking at the assembler output of his work assignment :-) ______________________________________________________________________________ Geben Sie Ihren Lottotipp gerne auf den letzten Dr�cker ab?Beim WEB.DE Lottoservice gibt's keine Warteschlangen. http://tippen2.web.de/?x=9 _______________________________________________ sapdb.general mailing list [EMAIL PROTECTED] http://listserv.sap.com/mailman/listinfo/sapdb.general
