Hi,
I'm trying to write a recursive databasa procedure like this:
CREATE DBPROC read_komp_ids_rec (IN parentID FIXED(20,0), IN serialID
FIXED(20,0), IN rec_level FIXED(20,0)) AS
VAR komponente_child fixed(20,0);
zeilennummer fixed(20,0);
tmp fixed(20,0);
TRY
DECLARE c1 CURSOR FOR
SELECT komponente_child,
zeilennummer,
FROM dba.komponente_childs
WHERE komponente_parent = :parentID;
WHILE $rc<>100 DO BEGIN
FETCH NEXT c1 INTO :komponente_child,
:zeilennummer;
INSERT INTO dba.serial_read_table( serial_id,
komponente_child,
zeilennummer )
VALUES( :serialID,
:komponente_child,
:zeilennummer);
SET tmp=rec_level+1;
CALL read_komp_ids_rec (:komponente_child, :serialID, :tmp);
END;
CLOSE c1;
CATCH
IF $rc <> 100 THEN STOP ($rc, 'Unexpected error');
It seems like the recursion works up to the point where the select
returns an empty result set. Then it don't step back to the previous
recursion level, it just stops the procedure.
The maximum recursion depth in my testcase is 3.
I tried to remove the TRY/CATCH block but then the procedure never
returns and there is no cpu load on the server but I had to stop and
restart the database to make it working again.
Tanks in advance.
MfG
Alexander Schulz
_______________________________________________
sapdb.general mailing list
[EMAIL PROTECTED]
http://listserv.sap.com/mailman/listinfo/sapdb.general