COGNOiSe.com - The IBM Cognos Community

IBM Cognos 10 Platform => Cognos 10 BI => Report Studio => Topic started by: jeisma on 08 Dec 2017 01:05:53 PM

Title: How to Create a Function
Post by: jeisma on 08 Dec 2017 01:05:53 PM
Hi,

How do you create a function that you can call inside the Query Explorer's Data Items.

For example, I want to create a function (never mind the syntax just yet)


function validDate (invoicedate)
  var validDateFr, validDateTo

  if (inRange(..))
    return true

  return false.
end function


So a Data Item's expression definition, I could have something like this:

  if (validDate(current_date)) then
    "OK"
  else "NOT OK"


Possible to do?


TIA!
Title: Re: How to Create a Function
Post by: CognosPaul on 08 Dec 2017 02:47:43 PM
Most databases will allow you to create User Defined Functions (UDFs) that you can import into Cognos, and then use like any other function.

SQL Server:
https://docs.microsoft.com/en-us/sql/relational-databases/user-defined-functions/create-user-defined-functions-database-engine

Oracle:
https://docs.oracle.com/cd/B19306_01/server.102/b14200/functions231.htm

Once you create the function, you can use the import wizard in Framework Manager to import it. There should be an expandable functions list.
Title: Re: How to Create a Function
Post by: jeisma on 08 Dec 2017 02:56:10 PM

I see, so it's not as simple as I initially thought.  :(

Thank you for taking the time to respond. I'll explore this option.
Title: Re: How to Create a Function
Post by: dougp on 08 Dec 2017 05:14:42 PM
You may be able to do this with a Cognos macro, although the macro feature is pretty limited.
Title: Re: How to Create a Function
Post by: dougp on 08 Dec 2017 05:34:36 PM
Are you sure you need a function?  How about just a data item?


if ([invoicedate] between ?validDateFr? and ?validDateTo?)
then ('OK')
else ('Not OK')