SET PATH *LIBL ; 

CREATE OR REPLACE FUNCTION CISTOOLS.HEX_TO_ASCII ( 
	IN_HEX VARCHAR(32000) ) 
	RETURNS VARCHAR(32000) CCSID 1208   
	LANGUAGE SQL 
	SPECIFIC CISTOOLS.HEX_TO_ASCII 
	NOT 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 
RETURN 
( 
SELECT 
LISTAGG ( 
TRIM ( HL . CHAR_VAL ) , '' ) WITHIN GROUP ( ORDER BY HP . POSITION ) 
AS DECODED_TEXT 
FROM TABLE ( 
SELECT N . RN AS POSITION , 
SUBSTR ( H . HEX_STRING , ( N . RN - 1 ) * 2 + 1 , 2 ) 
AS HEX_PAIR 
FROM TABLE ( 
CISTOOLS . ROWS_COUNTER ( 255 ) 
) N 
CROSS JOIN TABLE ( 
VALUES IN_HEX 
) H ( HEX_STRING ) 
WHERE ( N . RN - 1 ) * 2 + 1 <= LENGTH ( H . HEX_STRING ) 
AND ( N . RN - 1 ) * 2 + 2 <= LENGTH ( 
H . HEX_STRING ) 
) HP 
JOIN TABLE ( 
VALUES ( '00' , CHR ( 0 ) , 0 ) , ( '01' , CHR ( 1 ) , 1 ) , 
( '02' , CHR ( 2 ) , 2 ) , ( '03' , CHR ( 3 ) , 3 ) , 
( '04' , CHR ( 4 ) , 4 ) , ( '05' , CHR ( 5 ) , 5 ) , 
( '06' , CHR ( 6 ) , 6 ) , ( '07' , CHR ( 7 ) , 7 ) , 
( '08' , CHR ( 8 ) , 8 ) , ( '09' , CHR ( 9 ) , 9 ) , 
( '0A' , CHR ( 10 ) , 10 ) , ( '0B' , CHR ( 11 ) , 11 ) , 
( '0C' , CHR ( 12 ) , 12 ) , ( '0D' , CHR ( 13 ) , 13 ) , 
( '0E' , CHR ( 14 ) , 14 ) , ( '0F' , CHR ( 15 ) , 15 ) , 
( '10' , CHR ( 16 ) , 16 ) , ( '11' , CHR ( 17 ) , 17 ) , 
( '12' , CHR ( 18 ) , 18 ) , ( '13' , CHR ( 19 ) , 19 ) , 
( '14' , CHR ( 20 ) , 20 ) , ( '15' , CHR ( 21 ) , 21 ) , 
( '16' , CHR ( 22 ) , 22 ) , ( '17' , CHR ( 23 ) , 23 ) , 
( '18' , CHR ( 24 ) , 24 ) , ( '19' , CHR ( 25 ) , 25 ) , 
( '1A' , CHR ( 26 ) , 26 ) , ( '1B' , CHR ( 27 ) , 27 ) , 
( '1C' , CHR ( 28 ) , 28 ) , ( '1D' , CHR ( 29 ) , 29 ) , 
( '1E' , CHR ( 30 ) , 30 ) , ( '1F' , CHR ( 31 ) , 31 ) , 
( '20' , ' ' , 32 ) , ( '21' , '!' , 33 ) , ( '22' , 
'"' , 34 ) , ( '23' , '#' , 35 ) , ( '24' , '$' , 
36 ) , ( '25' , '%' , 37 ) , ( '26' , '&' , 38 ) , 
( '27' , '''' , 39 ) , ( '28' , '(' , 40 ) , ( '29' , 
')' , 41 ) , ( '2A' , '*' , 42 ) , ( '2B' , '+' , 
43 ) , ( '2C' , ',' , 44 ) , ( '2D' , '-' , 45 ) , 
( '2E' , '.' , 46 ) , ( '2F' , '/' , 47 ) , ( '30' , 
'0' , 48 ) , ( '31' , '1' , 49 ) , ( '32' , '2' , 
50 ) , ( '33' , '3' , 51 ) , ( '34' , '4' , 52 ) , 
( '35' , '5' , 53 ) , ( '36' , '6' , 54 ) , ( '37' , 
'7' , 55 ) , ( '38' , '8' , 56 ) , ( '39' , '9' , 
57 ) , ( '3A' , ':' , 58 ) , ( '3B' , ';' , 59 ) , 
( '3C' , '<' , 60 ) , ( '3D' , '=' , 61 ) , ( '3E' , 
'>' , 62 ) , ( '3F' , '?' , 63 ) , ( '40' , '@' , 
64 ) , ( '41' , 'A' , 65 ) , ( '42' , 'B' , 66 ) , 
( '43' , 'C' , 67 ) , ( '44' , 'D' , 68 ) , ( '45' , 
'E' , 69 ) , ( '46' , 'F' , 70 ) , ( '47' , 'G' , 
71 ) , ( '48' , 'H' , 72 ) , ( '49' , 'I' , 73 ) , 
( '4A' , 'J' , 74 ) , ( '4B' , 'K' , 75 ) , ( '4C' , 
'L' , 76 ) , ( '4D' , 'M' , 77 ) , ( '4E' , 'N' , 
78 ) , ( '4F' , 'O' , 79 ) , ( '50' , 'P' , 80 ) , 
( '51' , 'Q' , 81 ) , ( '52' , 'R' , 82 ) , ( '53' , 
'S' , 83 ) , ( '54' , 'T' , 84 ) , ( '55' , 'U' , 
85 ) , ( '56' , 'V' , 86 ) , ( '57' , 'W' , 87 ) , 
( '58' , 'X' , 88 ) , ( '59' , 'Y' , 89 ) , ( '5A' , 
'Z' , 90 ) , ( '5B' , '[' , 91 ) , ( '5C' , '\' , 
92 ) , ( '5D' , ']' , 93 ) , ( '5E' , '^' , 94 ) , 
( '5F' , '_' , 95 ) , ( '60' , '`' , 96 ) , ( '61' , 
'a' , 97 ) , ( '62' , 'b' , 98 ) , ( '63' , 'c' , 
99 ) , ( '64' , 'd' , 100 ) , ( '65' , 'e' , 101 ) , 
( '66' , 'f' , 102 ) , ( '67' , 'g' , 103 ) , ( '68' , 
'h' , 104 ) , ( '69' , 'i' , 105 ) , ( '6A' , 'j' , 
106 ) , ( '6B' , 'k' , 107 ) , ( '6C' , 
'l' , 108 ) , ( '6D' , 'm' , 109 ) , ( '6E' , 'n' , 
110 ) , ( '6F' , 'o' , 111 ) , ( '70' , 
'p' , 112 ) , ( '71' , 'q' , 113 ) , ( '72' , 'r' , 
114 ) , ( '73' , 's' , 115 ) , ( '74' , 
't' , 116 ) , ( '75' , 'u' , 117 ) , ( '76' , 'v' , 
118 ) , ( '77' , 'w' , 119 ) , ( '78' , 
'x' , 120 ) , ( '79' , 'y' , 121 ) , ( '7A' , 'z' , 
122 ) , ( '7B' , '{' , 123 ) , ( '7C' , 
'|' , 124 ) , ( '7D' , '}' , 125 ) , ( '7E' , '~' , 
126 ) , ( '7F' , CHR ( 127 ) , 127 ) , ( '80' , CHR ( 
128 ) , 128 ) , ( '81' , CHR ( 129 ) , 129 ) , 
( '82' , CHR ( 130 ) , 130 ) , ( '83' , CHR ( 131 ) , 
131 ) , ( '84' , CHR ( 132 ) , 132 ) , ( '85' , CHR ( 
133 ) , 133 ) , ( '86' , CHR ( 134 ) , 134 ) , 
( '87' , CHR ( 135 ) , 135 ) , ( '88' , CHR ( 136 ) , 
136 ) , ( '89' , CHR ( 137 ) , 137 ) , ( '8A' , CHR ( 
138 ) , 138 ) , ( '8B' , CHR ( 139 ) , 139 ) , 
( '8C' , CHR ( 140 ) , 140 ) , ( '8D' , CHR ( 141 ) , 
141 ) , ( '8E' , CHR ( 142 ) , 142 ) , ( '8F' , CHR ( 
143 ) , 143 ) , ( '90' , CHR ( 144 ) , 144 ) , 
( '91' , CHR ( 145 ) , 145 ) , ( '92' , CHR ( 146 ) , 
146 ) , ( '93' , CHR ( 147 ) , 147 ) , ( '94' , CHR ( 
148 ) , 148 ) , ( '95' , CHR ( 149 ) , 149 ) , 
( '96' , CHR ( 150 ) , 150 ) , ( '97' , CHR ( 151 ) , 
151 ) , ( '98' , CHR ( 152 ) , 152 ) , ( '99' , CHR ( 
153 ) , 153 ) , ( '9A' , CHR ( 154 ) , 154 ) , 
( '9B' , CHR ( 155 ) , 155 ) , ( '9C' , CHR ( 156 ) , 
156 ) , ( '9D' , CHR ( 157 ) , 157 ) , ( '9E' , CHR ( 
158 ) , 158 ) , ( '9F' , CHR ( 159 ) , 159 ) , 
( 'A0' , CHR ( 160 ) , 160 ) , ( 'A1' , CHR ( 161 ) , 
161 ) , ( 'A2' , CHR ( 162 ) , 162 ) , ( 'A3' , CHR ( 
163 ) , 163 ) , ( 'A4' , CHR ( 164 ) , 164 ) , 
( 'A5' , CHR ( 165 ) , 165 ) , ( 'A6' , CHR ( 166 ) , 
166 ) , ( 'A7' , CHR ( 167 ) , 167 ) , ( 'A8' , CHR ( 
168 ) , 168 ) , ( 'A9' , CHR ( 169 ) , 169 ) , 
( 'AA' , CHR ( 170 ) , 170 ) , ( 'AB' , CHR ( 171 ) , 
171 ) , ( 'AC' , CHR ( 172 ) , 172 ) , ( 'AD' , CHR ( 
173 ) , 173 ) , ( 'AE' , CHR ( 174 ) , 174 ) , 
( 'AF' , CHR ( 175 ) , 175 ) , ( 'B0' , CHR ( 176 ) , 
176 ) , ( 'B1' , CHR ( 177 ) , 177 ) , ( 'B2' , CHR ( 
178 ) , 178 ) , ( 'B3' , CHR ( 179 ) , 179 ) , 
( 'B4' , CHR ( 180 ) , 180 ) , ( 'B5' , CHR ( 181 ) , 
181 ) , ( 'B6' , CHR ( 182 ) , 182 ) , ( 'B7' , CHR ( 
183 ) , 183 ) , ( 'B8' , CHR ( 184 ) , 184 ) , 
( 'B9' , CHR ( 185 ) , 185 ) , ( 'BA' , CHR ( 186 ) , 
186 ) , ( 'BB' , CHR ( 187 ) , 187 ) , ( 'BC' , CHR ( 
188 ) , 188 ) , ( 'BD' , CHR ( 189 ) , 189 ) , 
( 'BE' , CHR ( 190 ) , 190 ) , ( 'BF' , CHR ( 191 ) , 
191 ) , ( 'C0' , CHR ( 192 ) , 192 ) , ( 'C1' , CHR ( 
193 ) , 193 ) , ( 'C2' , CHR ( 194 ) , 194 ) , 
( 'C3' , CHR ( 195 ) , 195 ) , ( 'C4' , CHR ( 196 ) , 
196 ) , ( 'C5' , CHR ( 197 ) , 197 ) , ( 'C6' , CHR ( 
198 ) , 198 ) , ( 'C7' , CHR ( 199 ) , 199 ) , 
( 'C8' , CHR ( 200 ) , 200 ) , ( 'C9' , CHR ( 201 ) , 
201 ) , ( 'CA' , CHR ( 202 ) , 202 ) , ( 'CB' , CHR ( 
203 ) , 203 ) , ( 'CC' , CHR ( 204 ) , 204 ) , 
( 'CD' , CHR ( 205 ) , 205 ) , ( 'CE' , CHR ( 206 ) , 
206 ) , ( 'CF' , CHR ( 207 ) , 207 ) , ( 'D0' , CHR ( 
208 ) , 208 ) , ( 'D1' , CHR ( 209 ) , 209 ) , 
( 'D2' , CHR ( 210 ) , 210 ) , ( 'D3' , CHR ( 211 ) , 
211 ) , ( 'D4' , CHR ( 212 ) , 212 ) , ( 'D5' , CHR ( 
213 ) , 213 ) , ( 'D6' , CHR ( 214 ) , 214 ) , 
( 'D7' , CHR ( 215 ) , 215 ) , ( 'D8' , CHR ( 216 ) , 
216 ) , ( 'D9' , CHR ( 217 ) , 217 ) , ( 'DA' , CHR ( 
218 ) , 218 ) , ( 'DB' , CHR ( 219 ) , 219 ) , 
( 'DC' , CHR ( 220 ) , 220 ) , ( 'DD' , CHR ( 221 ) , 
221 ) , ( 'DE' , CHR ( 222 ) , 222 ) , ( 'DF' , CHR ( 
223 ) , 223 ) , ( 'E0' , CHR ( 224 ) , 224 ) , 
( 'E1' , CHR ( 225 ) , 225 ) , ( 'E2' , CHR ( 226 ) , 
226 ) , ( 'E3' , CHR ( 227 ) , 227 ) , ( 'E4' , CHR ( 
228 ) , 228 ) , ( 'E5' , CHR ( 229 ) , 229 ) , 
( 'E6' , CHR ( 230 ) , 230 ) , ( 'E7' , CHR ( 231 ) , 
231 ) , ( 'E8' , CHR ( 232 ) , 232 ) , ( 'E9' , CHR ( 
233 ) , 233 ) , ( 'EA' , CHR ( 234 ) , 234 ) , 
( 'EB' , CHR ( 235 ) , 235 ) , ( 'EC' , CHR ( 236 ) , 
236 ) , ( 'ED' , CHR ( 237 ) , 237 ) , ( 'EE' , CHR ( 
238 ) , 238 ) , ( 'EF' , CHR ( 239 ) , 239 ) , 
( 'F0' , CHR ( 240 ) , 240 ) , ( 'F1' , CHR ( 241 ) , 
241 ) , ( 'F2' , CHR ( 242 ) , 242 ) , ( 'F3' , CHR ( 
243 ) , 243 ) , ( 'F4' , CHR ( 244 ) , 244 ) , 
( 'F5' , CHR ( 245 ) , 245 ) , ( 'F6' , CHR ( 246 ) , 
246 ) , ( 'F7' , CHR ( 247 ) , 247 ) , ( 'F8' , CHR ( 
248 ) , 248 ) , ( 'F9' , CHR ( 249 ) , 249 ) , 
( 'FA' , CHR ( 250 ) , 250 ) , ( 'FB' , CHR ( 251 ) , 
251 ) , ( 'FC' , CHR ( 252 ) , 252 ) , ( 'FD' , CHR ( 
253 ) , 253 ) , ( 'FE' , CHR ( 254 ) , 254 ) , 
( 'FF' , CHR ( 255 ) , 255 ) 
) HL ( HEX_VAL , CHAR_VAL , DEC_VAL ) 
ON HL . HEX_VAL = UPPER ( HP . HEX_PAIR ) ) ; 
END  ; 

COMMENT ON PARAMETER SPECIFIC FUNCTION CISTOOLS.HEX_TO_ASCII 
( IN_HEX IS 'Input Hexadecimal' ) ; 

LABEL ON SPECIFIC FUNCTION CISTOOLS.HEX_TO_ASCII 
	IS 'Hex To Ascii' ; 

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

GRANT EXECUTE   
ON SPECIFIC FUNCTION CISTOOLS.HEX_TO_ASCII 
TO PUBLIC ; 

