SET PATH *LIBL ; 

CREATE OR REPLACE FUNCTION CISTOOLS.TO_CYMD ( 
	INDATE DATE DEFAULT  NULL  ) 
	RETURNS DECIMAL(7, 0)   
	LANGUAGE SQL 
	SPECIFIC CISTOOLS.TO_CYMD 
	DETERMINISTIC 
	READS SQL DATA 
	CALLED ON NULL INPUT 
	SET OPTION  ALWBLK = *ALLREAD , 
	ALWCPYDTA = *OPTIMIZE , 
	COMMIT = *NONE , 
	DECRESULT = (31, 31, 00) , 
	DYNDFTCOL = *NO , 
	DYNUSRPRF = *USER , 
	SRTSEQ = *HEX   
	BEGIN 
DECLARE D DATE ; 
SET D = CURRENT_DATE ; 
IF INDATE IS NOT NULL THEN 
SET D = INDATE ; 
END IF ; 
RETURN 
( 
CASE 
WHEN YEAR ( D ) >= 2000 THEN 1 
ELSE 0 
END ) * 1000000 + MOD ( YEAR ( D ) , 100 ) * 10000 + MONTH ( D ) * 100 + 
DAY ( D ) ; 
END  ; 

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

GRANT EXECUTE   
ON SPECIFIC FUNCTION CISTOOLS.TO_CYMD 
TO PUBLIC ; 

