I don't agree that you need a loop contruct.
Just hand over the table.
create type tt_prd_cst_dscnt as table (customer_id int, product_id int, sales_amt integer, discount int);
drop procedure proc_A;
CREATE PROCEDURE proc_a ()
LANGUAGE SQLSCRIPT READS SQL DATA
AS
BEGIN
/* note how the column names are used to match the table type */
bIn = SELECT customer_id, product_id, sales_amount as SALES_AMT, NULL as discount
FROM product_sales;
call proc_B(:bIN, bOUT);
select * from :bOUT;
END;
drop procedure proc_b;
CREATE PROCEDURE proc_b (IN tabIN tt_prd_cst_dscnt, OUT tabOUT tt_prd_cst_dscnt)
LANGUAGE SQLSCRIPT READS SQL DATA
AS
BEGIN
/* just some garbage action to add the "discount" to the output tabe
select * from :tabIN;
tabOUT = select customer_id, product_id, sales_amt, mod (customer_id + product_id, 3)*10 + 2 as discount
from :tabIN;
END;
After these two procedure are in place we can call proc_a to get the resultsets of the unbound selects...
call proc_A;
-> first result set is coming from proc_B: SELECT * from :tabIN;
CUSTOMER_ID | PRODUCT_ID | SALES_AMT | DISCOUNT |
2 | 1 | 50 | NULL |
3 | 2 | 5 | NULL |
-> second result set (with DISCOUNT) is coming from proc_A: SELECT * FROM :bOUT;
CUSTOMER_ID | PRODUCT_ID | SALES_AMT | DISCOUNT |
2 | 1 | 50 | 2 |
3 | 2 | 5 | 22 |
Works for me...
- Lars