SET PATH *LIBL ; 

CREATE OR REPLACE FUNCTION CISTOOLS.TO_TIME ( 
	INNUM NUMERIC(6, 0) ) 
	RETURNS TIME   
	LANGUAGE SQL 
	SPECIFIC CISTOOLS.TO_TIME 
	DETERMINISTIC 
	READS SQL DATA 
	CALLED ON NULL INPUT 
	CONCURRENT ACCESS RESOLUTION DEFAULT 
	SET OPTION  ALWBLK = *ALLREAD , 
	ALWCPYDTA = *OPTIMIZE , 
	COMMIT = *NONE , 
	DBGVIEW = *SOURCE , 
	DECRESULT = (31, 31, 00) , 
	DFTRDBCOL = *NONE , 
	DYNDFTCOL = *NO , 
	DYNUSRPRF = *OWNER , 
	SRTSEQ = *HEX   
	BEGIN 
DECLARE WKNUM CHAR ( 6 ) ; 
DECLARE RETURN_TIME TIME ; 
DECLARE CONTINUE HANDLER FOR SQLEXCEPTION 
BEGIN 
SET RETURN_TIME = TIME ( '01.01.01' ) ; 
END ; 
SET WKNUM = LPAD ( INNUM , 6 , '0' ) ; 
SET RETURN_TIME = CAST ( 
LEFT ( WKNUM , 2 ) || '.' || SUBSTR ( WKNUM , 3 , 2 ) || '.' || 
CASE 
WHEN RIGHT ( WKNUM , 2 ) > 59 THEN '59' 
ELSE RIGHT ( WKNUM , 2 ) 
END AS TIME ) ; 
RETURN RETURN_TIME ; 
END  ; 

COMMENT ON PARAMETER SPECIFIC FUNCTION CISTOOLS.TO_TIME 
( INNUM IS 'Input Number' ) ; 

LABEL ON SPECIFIC FUNCTION CISTOOLS.TO_TIME 
	IS 'To Time' ; 

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

GRANT EXECUTE   
ON SPECIFIC FUNCTION CISTOOLS.TO_TIME 
TO PUBLIC ; 

