COGNOiSe.com - The IBM Cognos Community

IBM Cognos 10 Platform => Cognos 10 BI => Report Studio => Topic started by: PallaviPoojari on 18 Sep 2014 03:39:31 AM

Title: How to convert Amount in Words in cognos report studio
Post by: PallaviPoojari on 18 Sep 2014 03:39:31 AM
Hi,

I want to convert Amount field in Word.

For Eg.

1245.00 --- One Thousand Two Hundred and Forty Five Only

Type of Amount field is decimal.

Cognos Version - 10.2.1
Database - DB2

Thanks in advance.

Regards,
Pallavi

Title: Re: How to convert Amount in Words in cognos report studio
Post by: BigChris on 18 Sep 2014 04:29:55 AM
I don't think there's anything in native Cognos, but you might be able to do something with javascript. A quick look on the web revealed this:
http://javascript.about.com/library/bltoword.htm

I'm afraid I'm about as conversant in javascript as I am in quantum mechanics so I can't offer any further help...but others might be able to.
Title: Re: How to convert Amount in Words in cognos report studio
Post by: CognosAnalytics on 18 Sep 2014 02:28:28 PM
Hello Pallavi,
As BigChris suggested, you can go the Javascript route but that will be limited to HTML output only.
Ideally, your DB2 admins should be able to provide you with a function/stored procedure to achieve the same.

Thanks,
Cognos810
Title: Re: How to convert Amount in Words in cognos report studio
Post by: PallaviPoojari on 19 Sep 2014 01:51:06 AM
Hi

Thank you for your response.

They have function in DB2 for converting amt field in word But the field which i need to convert in word that i am calculating in report studio that's why i need this solution.

Title: Re: How to convert Amount in Words in cognos report studio
Post by: Lynn on 30 Sep 2014 04:07:22 AM
You can convert numbers to words using a big ol' ugly SQL expression that is chock full of case statements. I had a requirement to do this and then the Muppet (aka MFGF) improved it so there are only Cognos functions used which should make it database vendor independent.

The attached shows the expression and includes comments to help you understand what it is doing and also how to modify it to use your query item.

HINT: YourQueryItemHere should stand out as the likely place where you want to reference (you guessed it) your query item.
Title: Re: How to convert Amount in Words in cognos report studio
Post by: barrysaab on 04 Oct 2014 04:56:58 AM
Great stuff,Thanks.
Title: Re: How to convert Amount in Words in cognos report studio
Post by: Raghuvir on 20 Aug 2015 06:16:33 AM
Quote from: Lynn on 30 Sep 2014 04:07:22 AM
You can convert numbers to words using a big ol' ugly SQL expression that is chock full of case statements. I had a requirement to do this and then the Muppet (aka MFGF) improved it so there are only Cognos functions used which should make it database vendor independent.

The attached shows the expression and includes comments to help you understand what it is doing and also how to modify it to use your query item.

HINT: YourQueryItemHere should stand out as the likely place where you want to reference (you guessed it) your query item.

Thanks Lynn for sharing such greeat information. MFGF is the best :)

i used the attached code and got the below output

494,961,122.07 Four Hundred Ninety Four Million Nine Hundred Sixty One Thousand One Hundred Twenty Two AND 7/100

this wont work for decimal values ?

Regards

Title: Re: How to convert Amount in Words in cognos report studio
Post by: BigChris on 20 Aug 2015 06:51:27 AM
What would you want to see for the decimal part?

The part of the code that deals with the decimals is the last part...you might be able to alter it to what you need.
Title: Re: How to convert Amount in Words in cognos report studio
Post by: MFGF on 20 Aug 2015 08:04:13 AM
Quote from: BigChris on 20 Aug 2015 06:51:27 AM
What would you want to see for the decimal part?

The part of the code that deals with the decimals is the last part...you might be able to alter it to what you need.

Did you look at the expression? The very last part is:

+ '/100'

Couldn't you just change it to + ' cents' ???

Lynn has already done all the heavy lifting here. Her expression has saved you potentially days of work in figuring out how to get the result you require. You're not really going to ask her how to make a trivial change like '/100' to ' cents', are you?? :)

Edit. I see - you want the 7 as 'seven'? In that case, just extend the expression using Lynn's approach for the section before. You're only going to have to accommodate numbers 0 to 99 so it will be even easier.

MF.
Title: Re: How to convert Amount in Words in cognos report studio
Post by: bnlmeyer on 09 Aug 2021 03:32:12 PM
Greetings! I just had this same requirement emerge today - but alas I can't download the very old txt file 'CognosNumbersToWords MF.txt' anymore to kick that report studio code around . . .  anybody have any thoughts? Or the file :)
Title: Re: How to convert Amount in Words in cognos report studio
Post by: Lynn on 09 Aug 2021 03:42:16 PM
Quote from: bnlmeyer on 09 Aug 2021 03:32:12 PM
Greetings! I just had this same requirement emerge today - but alas I can't download the very old txt file 'CognosNumbersToWords MF.txt' anymore to kick that report studio code around . . .  anybody have any thoughts? Or the file :)

Ah, you are in luck! I have been out of the Cognos world for a few years now but I asked the Muppet and he still has the file. He will post it tomorrow.
Title: Re: How to convert Amount in Words in cognos report studio
Post by: MFGF on 10 Aug 2021 07:22:29 AM
Quote from: Lynn on 09 Aug 2021 03:42:16 PM
Ah, you are in luck! I have been out of the Cognos world for a few years now but I asked the Muppet and he still has the file. He will post it tomorrow.

The forum doesn't allow attachments these days, so I have emailed you a copy to the address you used when you signed up as a Cognoise user.

Cheers!

MF.
Title: Re: How to convert Amount in Words in cognos report studio
Post by: bnlmeyer on 10 Aug 2021 07:40:23 AM
Ah, I am truly very lucky - I received the file - thank you both for responding and have a great rest of your week!