SET PATH *LIBL ; 

CREATE OR REPLACE FUNCTION SAILPOINT.ES_V2_GET_ALL_IBM_I_USERS ( ) 
	RETURNS CLOB(2147483647)   
	LANGUAGE SQL 
	SPECIFIC SAILPOINT.V2_ESRTVIUSRS 
	NOT DETERMINISTIC 
	MODIFIES SQL DATA 
	CALLED ON NULL INPUT 
	NOT FENCED 
	SET OPTION  ALWBLK = *ALLREAD , 
	ALWCPYDTA = *OPTIMIZE , 
	COMMIT = *NONE , 
	DBGVIEW = *SOURCE , 
	DECRESULT = (31, 31, 00) , 
	DLYPRP = *NO , 
	DYNDFTCOL = *NO , 
	DYNUSRPRF = *OWNER , 
	SRTSEQ = *HEX   
	BEGIN 
RETURN 
( 
SELECT JSON_OBJECT ( 
'data' : 
JSON_ARRAYAGG ( 
JSON_OBJECT ( 
'userId' VALUE AUTHORIZATION_NAME , 
'status' VALUE STATUS , 
'previousSignOn' VALUE PREVIOUS_SIGNON , 
'signonInvalidAttempts' VALUE 
SIGN_ON_ATTEMPTS_NOT_VALID , 
'userClass' VALUE USER_CLASS_NAME , 
'specialAuths' VALUE JSON_ARRAY ( SELECT NULLIF ( 
TRIM ( FRAGMENT ) , '' ) 
FROM TABLE ( 
CISTOOLS . SPLIT_STRING ( 
A . SPECIAL_AUTHORITIES , ' ' ) 
) ABSENT ON NULL ) , 
'groupProfile' VALUE GROUP_PROFILE_NAME , 
'daysUntilPwExpires' VALUE DAYS_UNTIL_PASSWORD_EXPIRES , 
'text' VALUE TEXT_DESCRIPTION , 
'homeDir' VALUE HOME_DIRECTORY , 
'locale' VALUE LOCALE_PATH_NAME , 
'localPwMgmt' VALUE LOCAL_PASSWORD_MANAGEMENT 
) 
) , 
'errors' : JSON_ARRAY ( ) 
) 
FROM QSYS2 . USER_INFO_BASIC A ) ; 
END  ; 

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

GRANT EXECUTE   
ON SPECIFIC FUNCTION SAILPOINT.V2_ESRTVIUSRS 
TO PUBLIC ; 

