SET PATH *LIBL ; 

CREATE OR REPLACE FUNCTION CISTOOLS.ROWS_COUNTER ( 
	ENDROW INTEGER ) 
	RETURNS TABLE ( 
	RN INTEGER )   
	LANGUAGE SQL 
	SPECIFIC CISTOOLS.ROWS_COUNTER 
	DETERMINISTIC 
	READS SQL DATA 
	CALLED ON NULL INPUT 
	SET OPTION  ALWBLK = *ALLREAD , 
	ALWCPYDTA = *OPTIMIZE , 
	COMMIT = *NONE , 
	DECRESULT = (31, 31, 00) , 
	DYNDFTCOL = *NO , 
	DYNUSRPRF = *USER , 
	SQLCURRULE = *STD , 
	SRTSEQ = *HEX   
	BEGIN 
RETURN WITH RECURSIVE COUNTER ( RN ) AS ( 
SELECT * 
FROM TABLE ( 
VALUES 1 
) X ( RN ) 
UNION ALL 
-- Recursive member, unioned with the result of the previous step. 
SELECT RN + 1 
FROM COUNTER 
WHERE RN < ENDROW 
) SELECT RN 
FROM COUNTER ; 
END  ; 

COMMENT ON PARAMETER SPECIFIC FUNCTION CISTOOLS.ROWS_COUNTER 
( ENDROW IS 'End Row' ) ; 

LABEL ON SPECIFIC FUNCTION CISTOOLS.ROWS_COUNTER 
	IS 'Rows Counter' ; 

GRANT ALTER , EXECUTE   
ON SPECIFIC FUNCTION CISTOOLS.ROWS_COUNTER 
TO AMAPICS WITH GRANT OPTION ; 

GRANT EXECUTE   
ON SPECIFIC FUNCTION CISTOOLS.ROWS_COUNTER 
TO PUBLIC ; 

