The procedure you've created is designed to loop through the rows and call the sub program. If you want to return a result set you need to design it differently:
- use DYNAMIC RESULT SETS
- define a cursor
- open a cursor
- return
Have a look at the procedure definition in
Example 1: Calling a stored procedure that returns a single result set[
^]
ADDITION
What comes to the question if the query is correct or not I really can't say since I know nothing about the tables nor the logic.
If it would have syntactical problems they would show as errors but if it has logical errors and returns wrong rows or no rows at all, that's up to the statement logic.
Since you need to return the result to the calling side, have a test run with the following. That's part of your original query so it should return something meaningful.
One thing I noticed is that you were missing the keyword CURSOR...
CREATE PROCEDURE ResultTest () LANGUAGE SQL
DYNAMIC RESULT SETS 1
BEGIN
DECLARE v_row CURSOR FOR
SELECT A.BACMP,
A.BALOC,
A.BAITEM,
A.BABLOC,
A.BAQOH,
A.BAQCM
FROM TESTDATA.VINBINI A
WHERE A.BALOC = '13'
AND 1 = A.BACMP
AND A.BAQOH - A.BAQCM > 0;
OPEN v_row;
RETURN;
END