Q:

Can WHENEVER NOT FOUND Handler be used in a FOR loop

Can a WHENEVER NOT FOUND Handler be used when there are no rows in a FOR loop?
I'm writing a template stored procedure generator as part of a 2E model transformation.  I have thousands of 2E functions that I will need a stored procedure format and I'm trying to find the best and most efficient general case template for each type of 2E function.
This is my template proceedure
CREATE PROCEDURE SP_M3_000TSG (
    IN HONB DECIMAL(9, 0) 
    , OUT ABCD CHAR(3) DEFAULT ' ' 
    , OUT EECD CHAR(6) DEFAULT ' ' 
    , OUT RTN CHAR(7) DEFAULT NULL 
    )

    LANGUAGE SQL
    PROGRAM TYPE SUB

    -- #######################################################################
    -- # SP_M3_000TSG
    -- #######################################################################
BEGIN
    DECLARE SQLCODE INTEGER DEFAULT 0;
    DECLARE SQLSTATE CHAR(5) DEFAULT '00000';

    M3_INIT:BEGIN
      -- do some init stuff
    END M3_INIT;

    FOR M3_000TSG 
        **declare WHENEVER NOT FOUND **
        AS CUR_ECDQREL1 CURSOR
        FOR
            SELECT * FROM ECDQREL1 WHERE DQHONB = HONB
            DO 
                do some stuff;
    END FOR;

    GO TO M3_EXIT;

    M3_NO_ROWS: BEGIN
        do some stuff for no rows;
    END M3_NO_ROWS;

    M3_EXIT: BEGIN
        do some stuff;
        RETURN;
    END M3_EXIT;
END

A:

With current versions of Db2, you cannot use WHENEVER NOT FOUND syntax inside SQL-PL procedures.
Instead, you can use this syntax only in embedded-SQL programs where the pre-compiler acts on it.
In SQL-PL procedures, you can either declare a handler for NOT FOUND, or you can code checks for SQLCODE 100 or SQLSTATE '02000' .

