I am trying to write a SQL script that will gather records from a table, based on a select, and use some of the information from the result set to inset records to the same table. Then I need it to delete records from that table based on a more general result.

I have a script that works with Oracle but not with DB2. Here it is
DECLARE
CURSOR IMPREC IS
SELECT * FROM REGISTRY
WHERE PAGEID = 'BA01' AND
PROMPTID = 'IMP' AND
EXISTS
(SELECT DISTINCT(CLAIMKEY)
FROM REGISTRY WHERE PAGEID = 'IMP2' AND
(PROMPTID <>'I246'AND
PROMPTID <> 'I850' AND
PROMPTID <> 'I854'));
IMPREC_VAL IMPREC%ROWTYPE;
BEGIN
OPEN IMPREC;
LOOP
FETCH IMPREC INTO IMPREC_VAL;
EXIT WHEN IMPREC%NOTFOUND;
INSERT INTO REGISTRYSAMPLE
VALUES (IMPREC_VAL.CLAIMKEY,'SERVER','IMP2','I246','I246' ,'-','01',IMPREC_VAL.ANSWER,
'1','UPD',NULL,'SYSTEM',SYSDATE);
END LOOP;
CLOSE IMPREC;
DELETE FROM REGISTRY WHERE
pageid = 'IMP2' AND
(PROMPTID <> 'I246' AND
PROMPTID <> 'I850' AND
PROMPTID <> 'I854');
COMMIT;
END;
/