SET PATH *LIBL ; 

CREATE OR REPLACE FUNCTION SAILPOINT.ES_V2_GET_ALL_MAPICS_ROLES ( 
	ENVID CHAR(2) ) 
	RETURNS CLOB(2147483647)   
	LANGUAGE SQL 
	SPECIFIC SAILPOINT.V2_ESRTVMROLS 
	NOT DETERMINISTIC 
	MODIFIES SQL DATA 
	CALLED ON NULL INPUT 
	NOT FENCED 
	SET OPTION  ALWBLK = *ALLREAD , 
	ALWCPYDTA = *OPTIMIZE , 
	COMMIT = *NONE , 
	DECRESULT = (31, 31, 00) , 
	DLYPRP = *NO , 
	DYNDFTCOL = *NO , 
	DYNUSRPRF = *USER , 
	SRTSEQ = *HEX   
	BEGIN 
DECLARE LIBL VARCHAR ( 1024 ) DEFAULT '' ; 
SET CISTOOLS . LIBL = CISTOOLS . SET_LIBRARY_LIST ( ENVID ) ; 
RETURN 
( 
SELECT JSON_OBJECT ( 
'data' : 
JSON_OBJECTAGG ( RTRIM ( 
CAST ( EUROLE AS VARCHAR ( 10 ) CCSID 37 ) ) VALUE RTRIM ( 
CAST ( EUDESC AS VARCHAR ( 50 ) CCSID 37 ) ) ) , 
'errors' : JSON_ARRAY ( ) 
) 
FROM TABLE ( 
SELECT DISTINCT EUROLE , EUDESC 
FROM ESUSRP 
JOIN ESROLP 
USING ( EUROLE ) 
) ) ; 
END  ; 

GRANT ALTER , EXECUTE   
ON SPECIFIC FUNCTION SAILPOINT.V2_ESRTVMROLS 
TO AMAPICS WITH GRANT OPTION ; 

GRANT EXECUTE   
ON SPECIFIC FUNCTION SAILPOINT.V2_ESRTVMROLS 
TO PUBLIC ; 

