# CTL function example

**URL:** <https://forum.cloverdx.com/t/ctl-function-example/1922>\
**Category:** CloverDX Platform\
**Created:** [December 14, 2017, 12:00am UTC](https://forum.cloverdx.com/t/ctl-function-example/1922 "2017-12-14T00:00:00Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![hewills](https://avatars.discourse-cdn.com/v4/letter/h/839c29/32.png) [@hewills](https://forum.cloverdx.com/u/hewills)\
**Post date:** [December 14, 2017, 12:00am UTC](https://forum.cloverdx.com/t/ctl-function-example/1922/1 "2017-12-14T00:00:00Z")

</div>

Hi,  
I’m wanting to create my own simple function. I believe I can use CTL to do it, and don’t need Java. Basically I’m hoping to wrap some CTL code into a function, so we can use it in many jobs easily.

Example :  
function handle\_null(record)  
is record a string?  
return ‘-’  
is record a number?  
return 0  
is record a date?  
return 1900-01-01  
end

The documentation talks about extending Java, but that feels like overkill for what I need.

I was hoping I could just create a .ctl file, that I could import into transforms/reformats. Is this no longer recommended or possible in newer versions? (\> 4.3)

If it is possible, does someone have an example of a .ctl function, that takes in parameters, and returns a value?  
Thanks!

---

<div class="post-metadata">

**Author:** ![PedroVazquezRosario](https://avatars.discourse-cdn.com/v4/letter/p/ed8c4c/32.png) [@PedroVazquezRosario](https://forum.cloverdx.com/u/PedroVazquezRosario)\
**Post date:** [December 15, 2017, 5:14pm UTC](https://forum.cloverdx.com/t/ctl-function-example/1922/2 "2017-12-15T17:14:18Z")

</div>

Hi hewills,

Creating a .ctl file and importing into transforms/reformats is still possible in newer versions of CloverETL Designer. That being said I have created a simple .ctl function that takes parameters and returns a value:

```auto

//#CTL2
function string handle_null(string data)
{
	return data==null ? "-":data;

}

function integer handle_null(integer data)
{
	return data==null ? 0:data;

}

function date handle_null(date data)
{
	return data==null ? createDate(1990,01,01):data;

}

```

Regards,

---

<div class="post-metadata">

**Author:** ![hewills](https://avatars.discourse-cdn.com/v4/letter/h/839c29/32.png) [@hewills](https://forum.cloverdx.com/u/hewills)\
**Post date:** [December 15, 2017, 9:30pm UTC](https://forum.cloverdx.com/t/ctl-function-example/1922/3 "2017-12-15T21:30:20Z")

</div>

That makes sense. This is working just as I needed it, thanks!
