SET PATH *LIBL ; 

CREATE OR REPLACE FUNCTION CISTOOLS.GET_FILE_DEPENDENCIES ( 
	"FILE" VARCHAR(10) , 
	LIBRARY VARCHAR(10) ) 
	RETURNS TABLE ( 
	DOTTED_LEVEL VARCHAR(32000) , 
	LEVEL INTEGER , 
	"FILE" VARCHAR(10) , 
	LIBRARY VARCHAR(10) )   
	LANGUAGE SQL 
	SPECIFIC CISTOOLS.GET_FILE_DEPENDENCIES 
	DETERMINISTIC 
	READS SQL DATA 
	RETURNS NULL ON NULL INPUT 
	NO EXTERNAL ACTION 
	SET OPTION  ALWBLK = *ALLREAD , 
	ALWCPYDTA = *OPTIMIZE , 
	COMMIT = *CHG , 
	DBGVIEW = *SOURCE , 
	DECRESULT = (31, 31, 00) , 
	DYNDFTCOL = *NO , 
	DYNUSRPRF = *USER , 
	SRTSEQ = *HEX   
	BEGIN ATOMIC 
RETURN 
WITH BASE AS ( 
SELECT DBFFIL , DBFLIB , DBFFDP , DBFLDP , DBFTDP 
FROM QADBFDEP 
GROUP BY DBFFIL , DBFLIB , DBFFDP , DBFLDP , DBFTDP 
) , 
DEPENDENTS ( CALLLEVEL , DBFFIL , DBFLIB , DBFFDP , DBFLDP ) AS ( 
SELECT 1 AS CALLLEVEL , DBFFIL , DBFLIB , DBFFDP , DBFLDP 
FROM BASE 
WHERE DBFFIL = FILE 
AND DBFLIB = LIBRARY 
UNION ALL 
SELECT CALLLEVEL + 1 AS CALLLEVEL , B . DBFFIL , B . DBFLIB , 
B . DBFFDP , B . DBFLDP 
FROM DEPENDENTS A 
JOIN BASE B 
ON ( A . DBFFDP , A . DBFLDP ) = ( B . DBFFIL , B . DBFLIB ) 
) , 
DEPENDENCIES AS ( 
SELECT REPEAT ( '. . ' , CALLLEVEL ) , CALLLEVEL , DBFFDP , DBFLDP 
FROM DEPENDENTS 
GROUP BY CALLLEVEL , DBFFDP , DBFLDP 
) SELECT * 
FROM DEPENDENCIES 
ORDER BY CALLLEVEL , DBFFDP ASC ; 
END  ; 

COMMENT ON PARAMETER SPECIFIC FUNCTION CISTOOLS.GET_FILE_DEPENDENCIES 
( "FILE" IS 'Dependent File' , 
	LIBRARY IS 'Dependent Library' ) ; 

LABEL ON SPECIFIC FUNCTION CISTOOLS.GET_FILE_DEPENDENCIES 
	IS 'Get File Dependencies' ; 

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

GRANT EXECUTE   
ON SPECIFIC FUNCTION CISTOOLS.GET_FILE_DEPENDENCIES 
TO PUBLIC ; 

