Amount in words in SAP 8.8
Hello expert,
I want to convert the document amount in words in Indian standard and I am using the below Functions which I got from sdn and its working fine in SAP 2007 but it is giving error in SAP 8.8 and patch level is 5.........please give the feasible solution.....
1. Function to Convert one Digit Number to words.
CREATE Function dbo.fConvertDigit(@decNumber decimal)
returns varchar(6)
as
Begin
declare
@strWords varchar(6)
Select @strWords = Case @decNumber
When '1' then 'One'
When '2' then 'Two'
When '3' then 'Three'
When '4' then 'Four'
When '5' then 'Five'
When '6' then 'Six'
When '7' then 'Seven'
When '8' then 'Eight'
When '9' then 'Nine'
Else ''
end
return @strWords
end
2. Function to convert 2 digit number to words.
CREATE Function dbo.fConvertTens(@decNumber varchar(2))
returns varchar(30)
as
Begin
declare @strWords varchar(30)
--Is value between 10 and 19?
If Left(@decNumber, 1) = 1
begin
Select @strWords = Case @decNumber
When '10' then 'Ten'
When '11' then 'Eleven'
When '12' then 'Twelve'
When '13' then 'Thirteen'
When '14' then 'Fourteen'
When '15' then 'Fifteen'
When '16' then 'Sixteen'
When '17' then 'Seventeen'
When '18' then 'Eighteen'
When '19' then 'Nineteen'
end
end
else -- otherwise it's between 20 and 99.
begin
Select @strWords = Case Left(@decNumber, 1)
When '0' then ''
When '2' then 'Twenty '
When '3' then 'Thirty '
When '4' then 'Forty '
When '5' then 'Fifty '
When '6' then 'Sixty '
When '7' then 'Seventy '
When '8' then 'Eighty '
When '9' then 'Ninety '
end
Select @strWords = @strWords + dbo.fConvertDigit(Right(@decNumber, 1))
end
--Convert ones place digit.
return @strWords
end
3. Function to convert amt in numbers to words. (Built with the help of above 2 functions)
CREATE function dbo.fNumToWords (@decNumber decimal(12, 2))
returns varchar(300)
As
Begin
Declare
@strNumber varchar(100),
@strRupees varchar(200),
@strPaise varchar(100),
@strWords varchar(300),
@intIndex integer,
@intAndFlag integer
Select @strNumber = Cast(@decNumber as varchar(100))
Select @intIndex = CharIndex('.', @strNumber)
if(@decNumber>99999999.99)
BEGIN
RETURN ''
END
If @intIndex > 0
begin
Select @strPaise = dbo.fConvertTens(Right(@strNumber, Len(@strNumber) - @intIndex))
Select @strNumber = SubString(@strNumber, 1, Len(@strNumber) - 3)
If Len(@strPaise) > 0 Select @strPaise = @strPaise + ' paise'
end
Select @strRupees = ''
Select @intIndex=len(@strNumber)
Select @intAndFlag=2
while(@intIndex>0)
begin
if(@intIndex=8)
begin
Select @[email protected](left(@decNumber,1))' Crore '
Select @strNumber=substring(@strNumber,2,len(@strNumber))
Select @intIndex=@intIndex-1
end
else if(@intIndex=7)
begin
if(substring(@strNumber,1,1)='0')
begin
if substring(@strNumber,2,1)<>'0'
begin
if (@strRupees<>NULL and substring(@strNumber,3,1)='0' and substring(@strNumber,4,1)='0' and substring(@strNumber,5,1)='0' and substring(@strNumber,6,1)='0' and substring(@strNumber,7,1)='0' and @intAndFlag=2 and @strPaise=NULL)
begin
Select @strRupees=@strRupees+' and ' dbo.fConvertDigit(substring(@strNumber,2,1))' Lakh '
Select @intAndFlag=1
end
else
begin
Select @[email protected](substring(@strNumber,2,1))' Lakh '
end
Select @strNumber=substring(@strNumber,3,len(@strNumber))
Select @intIndex=@intIndex-2
end
else
begin
Select @strNumber=substring(@strNumber,3,len(@strNumber))
Select @intIndex=@intIndex-2
end
end
else
begin
if(substring(@strNumber,3,1)='0' and substring(@strNumber,4,1)='0' and substring(@strNumber,5,1)='0' and substring(@strNumber,6,1)='0' and substring(@strNumber,7,1)='0' and @intAndFlag=2 and @strPaise='')
begin
Select @strRupees=@strRupees+' and ' + dbo.fConvertTens(substring(@strNumber,1,2))+' Lakhs '
Select @intAndFlag=1
end
else
begin
Select @[email protected](substring(@strNumber,1,2))' Lakhs '
end
Select @strNumber=substring(@strNumber,3,len(@strNumber))
Select @intIndex=@intIndex-2
end
end
else if(@intIndex=6)
begin
if(substring(@strNumber,2,1)<>'0' or substring(@strNumber,3,1)<>'0' and substring(@strNumber,4,1)='0' and substring(@strNumber,5,1)='0' and substring(@strNumber,6,1)='0' and @intAndFlag=2 and @strPaise='')
begin
if len(@strRupees) <= 0
begin
if convert(int,substring(@strNumber,1,1)) = 1
begin
Select @strRupees=@strRupees+'' + dbo.fConvertDigit(substring(@strNumber,1,1))+' Lakh '
Select @intAndFlag=2
end
else
begin
Select @strRupees=@strRupees+'' + dbo.fConvertDigit(substring(@strNumber,1,1))+' Lakhs '
Select @intAndFlag=2
end
end
else
begin
if convert(int,substring(@strNumber,1,1)) = 1
begin
Select @strRupees=@strRupees+' and' + dbo.fConvertDigit(substring(@strNumber,1,1))+' Lakh '
Select @intAndFlag=1
end
else
begin
Select @strRupees=@strRupees+' and' + dbo.fConvertDigit(substring(@strNumber,1,1))+' Lakhs '
Select @intAndFlag=1
end
end
end
else
begin
if convert(int,substring(@strNumber,1,1)) = 1
begin
Select @[email protected](substring(@strNumber,1,1))' Lakh '
end
else
begin
Select @[email protected](substring(@strNumber,1,1))' Lakhs '
end
end
Select @strNumber=substring(@strNumber,2,len(@strNumber))
Select @intIndex=@intIndex-1
end
else if(@intIndex=5)
begin
if(substring(@strNumber,1,1)='0')
begin
if substring(@strNumber,2,1)<>'0'
begin
if(substring(@strNumber,3,1)='0' and substring(@strNumber,4,1)='0' and substring(@strNumber,5,1)='0' and @intAndFlag=2 and @strPaise='')
begin
Select @strRupees=@strRupees+' and ' dbo.fConvertDigit(substring(@strNumber,2,1))' Thousand '
Select @intAndFlag=1
end
else
begin
Select @[email protected](substring(@strNumber,2,1))' Thousand '
end
Select @strNumber=substring(@strNumber,3,len(@strNumber))
Select @intIndex=@intIndex-2
end
else
begin
Select @strNumber=substring(@strNumber,3,len(@strNumber))
Select @intIndex=@intIndex-2
end
end
else
begin
if(substring(@strNumber,3,1)='0' and substring(@strNumber,4,1)='0' and substring(@strNumber,5,1)='0' and @intAndFlag=2 and @strPaise='')
begin
Select @strRupees=@strRupees' and 'dbo.fConvertTens(substring(@strNumber,1,2))+' Thousand '
Select @intAndFlag=1
end
else
begin
Select @[email protected](substring(@strNumber,1,2))' Thousand '
end
Select @strNumber=substring(@strNumber,3,len(@strNumber))
Select @intIndex=@intIndex-2
end
end
else if(@intIndex=4)
begin
if ( (substring(@strNumber,3,1)<>'0' or substring(@strNumber,4,1)<>'0') and substring(@strNumber,2,1)='0' and @intAndFlag=2 and @strPaise='')
begin
Select @strRupees=@strRupees+' and' + dbo.fConvertDigit(substring(@strNumber,1,1))+' Thousand '
Select @intAndFlag=1
end
else
begin
Select @[email protected](substring(@strNumber,1,1))' Thousand '
end
Select @strNumber=substring(@strNumber,2,len(@strNumber))
Select @intIndex=@intIndex-1
end
else if(@intIndex=3)
begin
if substring(@strNumber,1,1)<>'0'
begin
Select @[email protected](substring(@strNumber,1,1))' Hundred '
Select @strNumber=substring(@strNumber,2,len(@strNumber))
if( (substring(@strNumber,1,1)<>'0' or substring(@strNumber,2,1)<>'0') and @intAndFlag=2 )
begin
Select @strRupees=@strRupees+' and '
Select @intAndFlag=1
end
Select @intIndex=@intIndex-1
end
else
begin
Select @strNumber=substring(@strNumber,2,len(@strNumber))
Select @intIndex=@intIndex-1
end
end
else if(@intIndex=2)
begin
if substring(@strNumber,1,1)<>'0'
begin
Select @strRupees=@strRupees+dbo.fConvertTens(substring(@strNumber,1,2))
Select @intIndex=@intIndex-2
end
else
begin
Select @intIndex=@intIndex-1
end
end
else if(@intIndex=1)
begin
if(@strNumber<>'0')
begin
Select @strRupees=@strRupees+dbo.fConvertDigit(@strNumber)
end
Select @intIndex=@intIndex-1
end
continue
end
if len(@strRupees)>0 Select @strRupees=@strRupees+ ' rupees '
IF(len(@strPaise)<>0)
BEGIN
if len(@strRupees)>0 Select @strRupees=@strRupees + ' and '
END
Select @strWords = IsNull(@strRupees, '') + IsNull(@strPaise, '')
select @strWords = @strWords + ' only'
Return @strWords
End
->> Create 1 UDF in Header on Requrie Documents (ex. Marketing Documents).
->> Create 3 Function in MSSQL Server Management.
->> Create 1 FMS in Query Generator and save as Query Manager then Assign to UDF for Amount in Words.
for example:
Create UDF in Header on Marketing Documents.
->> Choose Tools on Top menu.
->> User - Defined Fields. -> User Manage Fields.
->> Open the User Manage Fields Widnow.
->> Marketing Documents. -> Title.
->> Select Title and Click Add button in Bottom on User Manage Fields Window.
->> Create Amount in Words UDF(Code, Discription and Type - Character) and Add the UDF.
Create Function in MSSQL Server Management.
Check this Link, (have 3 Functions in Link).
http://techcreeze.blogspot.com/2008/11/convert-amount-into-words-according-to_15.html
1st Funciton - to Convert one Digit Number to words
2nd Funciton - to convert 2 digit number to words.
3rd Funciton - to convert amt in numbers to words.
->> Open the MSSQL Server Management Window.
->> Choose your Company database and Create NEW Query.
->> Create 3 Function Queries one by one.
->> Create 3 NEW Query Tab and 1st one put the 1st Function then Run the Function. and
2nd New Query tab put the 2nd Function then Run the Function.
3rd New Query tab put the 3rd Function then Run the Function.
Create FMS in Query Generator and Save as Query Manager.
->> Adminstration.
->> Reports. -> Query Generator.
->> Open the Query Generator and put the below FMS query.
for example : Purchase Order Doc. Toal(in wrods).
declare @Doc_total numeric (19,6)
set @Doc_total=$[OPOR.DocTotal]
select dbo.fNumToWords (@Doc_total)
->> Assign the FMS in UDF on Purchase Order.
->> Auto Refresh of Document Total.
Ex.
1. Goto the UDF and Clcik ShiftAltF2.
2. Select the SEARCH BY SAVED QUERY.
3. Assign the FMS Query.
4. Select the AUTO REFRESH WHEN FIELD CHENGES.
5. Select Document Total.
6. Check the Display Saved Values.
Hi Neetu,
its not converting decimal values in paisa...
Regards
Deepak tyagi
Similar Messages
-
SAP Script ~ Put Amount in words & amounts
HI guys: Please help me... I have a requirement where the client wants to put the amount in words on a check sap script as follows:
If the amount is 27,150.95 USD
they want "27,150 DOLLARS AND 95 CENTS"
this is a combination of amounts and words in the "amounts in words" window of the sap script
please help
thanks
BrianHi,
In the window where the amount is displayed in words,
add the following code:
Script:
Say you have the amt in &amt&
/: DEFINE &DOLLARS& = SPACE
/: DEFINE &CENTS& = SPACE
/: PERFORM split_amount USING &AMT(T)&
/: CHANGING &DOLLARS&
/: CHANGING &CENTS&
P &DOLLARS& Dollars &CENTS& Cents Only
( P can be any paragraph format you want to use.
(T) in the AMT while passing will get your amount rid of thousand seperators)
Code should be put as follows in the Routine program:
DATA: amt(10) TYPE C, (Length specified should correspond to the total length of the amount field including the decimal)
p_dollar(7) TYPE c,
p_cents(2) TYPE c.
FORM split_amount USING in_tab STRUCTURE itcsy
CHANGING out_tab1 STRUCTURE itcsy
CHANGING out_tab2 STRUCTURE itcsy.
READ TABLE in_tab INDEX 1.
MOVE in_tab-value TO amt.
CHECK sy-subrc EQ 0.
SPLIT amt AT '.' INTO p_dollar p_cents.
IF sy-subrc NE 0.
SPLIT amt AT ',' INTO p_dollar p_cents.
ENDIF. (We have two SPLIT cos we may either have dot OR comma for decimal notation. This will cover both the cases)
READ TABLE out_tab1 INDEX 1.
CHECK sy-subrc EQ 0.
MOVE p_dollars INTO out_tab1-value.
MODIFY out_tab INDEX sy-tabix.
READ TABLE out_tab2 INDEX 1.
CHECK sy-subrc EQ 0.
MOVE p_cents INTO out_tab1-value.
MODIFY out_tab INDEX sy-tabix.
Plz let me know if you have questions.
Thanks
Geetha -
SAP Script : Amount in Words
Dear All,
I am working on bank Check, I need to print the amount value in Words. Amount field ®UD-SWNES&, I need to print this amount in words.
I mean to say that, regud-swnes = 1000.69, I have to print this as One Thousand and 69/100. please advice me, how Can I do that.
Thanking you.
with kind Regards
Venkat.hi venkat,
split the command at decimal and u can design ur code for 69/1000.for displaying 1000 u can use the fm 'SPELL_AMOUNT'.
sample:
TABLES SPELL.
DATA : T_SPELL LIKE SPELL OCCURS 0 WITH HEADER LINE.
DATA : PAMOUNT LIKE SPELL-NUMBER VALUE '1234510'.
SY-TITLE = 'SPELLING NUMBER'.
PERFORM SPELL_AMOUNT USING PAMOUNT 'USD'.
WRITE: 'NUMBERS', T_SPELL-WORD, 'DECIMALS ', T_SPELL-DECWORD.
FORM SPELL_AMOUNT USING PWRBTR PWAERS.
CALL FUNCTION 'SPELL_AMOUNT'
EXPORTING
AMOUNT = PAMOUNT
CURRENCY = PWAERS
FILLER = SPACE
LANGUAGE = 'E'
IMPORTING
IN_WORDS = T_SPELL
EXCEPTIONS
NOT_FOUND = 1
TOO_LARGE = 2
OTHERS = 3.
ENDFORM.
reward if helpful.
regards,
keerthi. -
hi all,
i have one issue,
in script the total amount in word is not comming complet
ex. 18880
In words-
Eighten thousand eight hundred eight
but in script it is printing --- Eighten thousand eight it is not piinting remaning text.
suggest what to do,
plz its urgent.
Regards,
Amit.Amit,
There's no sapscript command to covert number to word, you've to do it in print program.
In the sapscript form
use
/:PERFORM GET_DATA IN PROGRAM Ztest
/:USING &amt&
/:CHANGING &word&
/:ENDPERFORM
and in the Print Program
CALL FUNCTION 'SPELL_AMOUNT'
EXPORTING
AMOUNT = amount
CURRENCY = 'HKD'
FILLER = ' '
LANGUAGE = 'E'
IMPORTING
IN_WORDS = word
EXCEPTIONS
NOT_FOUND = 1
TOO_LARGE = 2
OTHERS = 3.
Hope this helps
VB -
SAP Script(calling FM to spell the amount in words)
Hi Friends,
I am getting error in calling a function module(HR_IN_CHG_INR_WRDS : To spell the amount in words) to a script form.It is giving a dump message : "Conversion type error".
Could you guide me with small example ?
I will reward for usefull responses.
Pls. treat it as urgent.
Thx in Adv.
BobbyHi
execute this code .
REPORT ZCOVERTION.
TABLES SPELL.
DATA : T_SPELL LIKE SPELL OCCURS 0 WITH HEADER LINE.
DATA : PAMOUNT LIKE SPELL-NUMBER VALUE '23.45'.
SY-TITLE = 'SPELLING NUMBER'.
PERFORM SPELL_AMOUNT USING PAMOUNT 'USD'.
WRITE: 'NUMBERS', T_SPELL-WORD ,'and', T_SPELL-DECWORD.
FORM SPELL_AMOUNT USING PWRBTR PWAERS.
CALL FUNCTION 'SPELL_AMOUNT'
EXPORTING
AMOUNT = PAMOUNT
CURRENCY = PWAERS
FILLER = SPACE
LANGUAGE = 'E'
IMPORTING
IN_WORDS = T_SPELL
EXCEPTIONS
NOT_FOUND = 1
TOO_LARGE = 2
OTHERS = 3.
ENDFORM. " SPELL_AMOUNT
Hope this will solve ur problem
Thanks
sreelakshmi -
Wrong Conversion of Amount in Words in Purchase Order print out
Hi,
Please help me with the problem in printing of Purchase Order, there is an error in amount in words. For example the total amount in numbers is 93,311.30 however the amount in words will be nine million three hundred thirty-one thousand one hundred thirty.As per my understanding the amount in number was multiply by 100. Please help what i should check.
Thanks,
RichardDear,
Take the help of the ABAPER guy and check what he written in the program of the PO layout & printout.
http://help.sap.com/printdocu/core/print46c/en/data/pdf/BCSRVSCRSF/BCSRVSCRSF.pdf
This will solve your problem
Thanks & regards.
Varun Bisaria
Edited by: Varun Bisaria on Oct 21, 2011 2:10 PM -
hi all,
I have a requirement where in i have to print amount in words. The user enters the amount in table rows, and the total in amount gets printed in another text field. I have put the code for sum in the exit event of the rows(cell) this is done through formcalc.
Now i have requirement to print the amount in words
1. Is there any function like SPELL in form calc? (i doubt there would be one...!!)
2. If there is no such funcrion, then how to implement this functionality? Can i some how call the FM SPELL in the interactive form or may be generate a event that would call FM SPELL in my WD componentand then print the result back in my interactive form?
All help will be appreciated.Hey Runal,
I haven't had much experience with Interactive forms inside WDJ, but I think this will work...
In the Submit To SAP button, this code exists...
// DO NOT MODIFY THE CODE BEYOND THIS POINT - 710.20060821084622.325745.280724 - SubmitToSAP.xfo
ContainerFoundation_JS.SendMessageToContainer(event.target, "submit", "", "", "", "");
// END OF DO NOT MODIFY
This code triggers an event call to the backend.
What I would do is have a variable in your form that you set just before you click the button so you know what "event" you want to trigger, then of course, set it to null inside the method... when it goes back into the method in your web dynpro, you could then take the number, call the function module, and return the value to the screen.
In theory, this should work.
Hope this helps...
Cheers,
Kevin -
Function Module to convert amount to amount in words
Dear Guru ,
I want to know is there any sap standard Function Module to convert amount value to amount in words
Thanks & RegardsHi..
Use FM SPELL_AMOUNT.
This function module converts an amount or number into words. It can be used as follows:
Convert a number into words
To do this, the transfer parameters LANGUAGE and AMOUNT have to be entered.
Convert an amount into words
To do this, the fields LANGUAGE, CURRENCY, and AMOUNT have to be entered.
Program RF_SPELL contains a sample call of the function module. You can use it for test purposes.
REPORT ZSPELL.
TABLES SPELL.
DATA : T_SPELL LIKE SPELL OCCURS 0 WITH HEADER LINE.
DATA : PAMOUNT LIKE SPELL-NUMBER VALUE '1234510'.
SY-TITLE = 'SPELLING NUMBER'.
PERFORM SPELL_AMOUNT USING PAMOUNT 'USD'.
WRITE: 'NUMBERS', T_SPELL-WORD, 'DECIMALS ', T_SPELL-DECWORD.
FORM SPELL_AMOUNT USING PWRBTR PWAERS.
CALL FUNCTION 'SPELL_AMOUNT'
EXPORTING
AMOUNT = PAMOUNT
CURRENCY = PWAERS
FILLER = SPACE
LANGUAGE = 'E'
IMPORTING
IN_WORDS = T_SPELL
EXCEPTIONS
NOT_FOUND = 1
TOO_LARGE = 2
OTHERS = 3.
ENDFORM. " SPELL_AMOUNT
I hope it helps.
Reward pts if helpful
Regards
- Rishika Bawa -
Amount in words with 'AND' in between.
Hi All,
I have a requiremnt where in i neeed to convert my amount to words and display in SAP script.
I can use the FM SPELL_AMOUNT.This will give the result in words.I need to have the AND in b/w these.
eg:123456789
result:ONE HUNDRED TWENTY-THREE MILLION FOUR HUNDRED FIFTY-SIX THOUSAND SEVEN HUNDRED EIGHTY-NINE.
My requirement:ONE HUNDRED AND TWENTY-THREE MILLION FOUR HUNDRED AND FIFTY-SIX THOUSAND SEVEN HUNDRED AND EIGHTY-NINE.
Any pointers would be appreciated.Hi,
DATA: w_words(200).
After calling FM USe: Concatenate IN_WORDS-WORD 'AND' IN_WORDS-DECWORD into W_WORDS. Now W_Words Will contain the string you required.
Regards
Raju Chitale -
Reg Currency Description and Amount in words
Hi
Can anybody help me out in finding Function Module for Currency Descripton and Amount in words.
For Example, if currency type is <b>USD</b> and the amount is <b>29,012.50</b>
then it should display the currency description as <b>The sum of US Dollars</b> and the amount in words as <b>Twenty Nine Thousand Twelve and Cents Fifty</b> and it should work for any currency type.
Thanks in Advance.
SwathiHi swathi,
Cents are not known in SAP only USD with decimal places in known.
however check if this can solve teh problem...
for indian currency inr use the below function module....
HR_IN_CHG_INR_WRDS
for usd currency use the following code as an example..
data: amt_in type pc207-betrg value '29012.50'.
data: words type spell.
data: result type string.
call function 'SPELL_AMOUNT'
exporting
amount = amt_in
currency = 'USD'
FILLER = ' '
LANGUAGE = SY-LANGU
importing
in_words = words
EXCEPTIONS
NOT_FOUND = 1
TOO_LARGE = 2
OTHERS = 3
if sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
endif.
concatenate 'USD' words-word 'AND' words-decword 'CENTS'
into result separated by space.
write:/ result.
hope this helps,
all the best,
sampath
award helpful answers -
Amounts in words will be in Chinese
Hi All,
I need to print Amount in words in Chinese language. I used Function Module "SPELL AMOUNT". By using this FM i can able to print the words in english. Eventhough i used language (sy-langu='zh') is China but i cant able to print in chinse letters. Please guide me on this.
Regards,
JayakumarHi,
the language is ZH and the currency is CNY, those are the values that u need to pass to the FM.
It should work fine, otherwise, check this notes 1401367 - Spell Amount:
Note 152520 - T015Z - Digits and numbers in words in Asian lang.
What is the SAP version that u r working on?
Regards -
Hi All,
Please help me to get Amount in words in Indian standards
i.e
if amount is 125000 then it should print
"One Lakh Twenty-five thousand rupees only"
All these I need in a Check Print layout
here i can see amount but how will i get Amount in words there.
I have made a query CheckPrint
which contains follwing fields from OPCH (A/P Invoice table)
DocNum , DocDate, CardName, DocTotal.
I just want DocTotal in words so that i can display it on the layout and get the print on Cheque.
I am using SAP 2005 B version.
Please help I am not a trained professional in SAP Business One
Kindly do the needful.
Thanks and Regards,
Murtaza PiyersoapHi Murtaza,
I had a similar issue, and I addressed it by:
1. Creating a UDF in the Payments>Title called AmountInWord of Type AlphaNumeric Structure Text (i.e. in OVPM Table)
2. Created a Function called I_ConvertN2W in the database, which converts any number into Words as per Indian Style i.e. Lakh, Crore
3. In the SBO_SP_TransactionNotification, I am filling the Value in the UDF on every Add of Outgoing Payment
4. In the PLD for the printing of the cheque, I am using the UDF, instead of the SAPB1 Amount (which is non Indian Style)
Step 1:
Create the UDF as mentioned above, I guess no further explanation required
Step 2:
Creating the Function I_ConvertN2W, but first you will have to create all the support functions, I am listing the function in the order of creation
CREATE FUNCTION I_Modulus (@INPUT INT, @DIVIDER INT)
RETURNS INT AS
BEGIN
DECLARE @RETVAL AS INT, @MODULUS AS INT
IF @INPUT = @DIVIDER
BEGIN
SET @RETVAL = 0
END
IF @INPUT < @DIVIDER
BEGIN
SET @RETVAL = @INPUT
END
SET @MODULUS = @INPUT
WHILE @MODULUS >= @DIVIDER
BEGIN
SET @MODULUS = @MODULUS - @DIVIDER
END
SET @RETVAL = @MODULUS
RETURN (@RETVAL)
END
CREATE FUNCTION I_Mid (@sInput VARCHAR(8000), @iStart INT, @iLen INT)
RETURNS VARCHAR(8000) AS
BEGIN
--Adapted from the Mid function of Visual Basic
DECLARE @sRetVal AS VARCHAR(8000)
IF @iLen = 0
BEGIN
SET @iLen = LEN(@sInput)-(@iStart-1)
END
SET @sRetVal = RIGHT(@sInput,LEN(@sInput) - (@iStart-1))
SET @sRetVal = LEFT(@sRetVal,@iLen)
RETURN (@sRetVal)
END
CREATE FUNCTION I_CN2W_GetWord (@cValue INT)
RETURNS nvarchar(10)
AS
BEGIN
DECLARE @sRetVal AS NVARCHAR(10)
SET @sRetVal =
CASE
WHEN @cValue = 0 THEN ''
WHEN @cValue = 1 THEN 'One'
WHEN @cValue = 2 THEN 'Two'
WHEN @cValue = 3 THEN 'Three'
WHEN @cValue = 4 THEN 'Four'
WHEN @cValue = 5 THEN 'Five'
WHEN @cValue = 6 THEN 'Six'
WHEN @cValue = 7 THEN 'Seven'
WHEN @cValue = 8 THEN 'Eight'
WHEN @cValue = 9 THEN 'Nine'
WHEN @cValue = 10 THEN 'Ten'
WHEN @cValue = 11 THEN 'Eleven'
WHEN @cValue = 12 THEN 'Twelve'
WHEN @cValue = 13 THEN 'Thirteen'
WHEN @cValue = 14 THEN 'Fourteen'
WHEN @cValue = 15 THEN 'Fifteen'
WHEN @cValue = 16 THEN 'Sixteen'
WHEN @cValue = 17 THEN 'Seventeen'
WHEN @cValue = 18 THEN 'Eighteen'
WHEN @cValue = 19 THEN 'Ninteen'
WHEN @cValue = 20 THEN 'Twenty'
WHEN @cValue = 30 THEN 'Thirty'
WHEN @cValue = 40 THEN 'Forty'
WHEN @cValue = 50 THEN 'Fifty'
WHEN @cValue = 60 THEN 'Sixty'
WHEN @cValue = 70 THEN 'Seventy'
WHEN @cValue = 80 THEN 'Eighty'
WHEN @cValue = 90 THEN 'Ninty'
END
RETURN (@sRetVal)
END
CREATE FUNCTION I_CN2W_GetTens (@sValue as NVARCHAR(100))
RETURNS NVARCHAR(100) AS
BEGIN
DECLARE @sTens AS NVARCHAR(100), @iNum AS INT, @cnt AS INT, @iDigit AS INT, @sRetVal AS NVARCHAR(100)
SET @iNum = CAST(@sValue AS INT)
SET @sTens = ''
IF @iNum <= 20
BEGIN
SET @sRetVal = dbo.I_CN2W_GetWord(@iNum)
END
ELSE
BEGIN
SET @cnt = 1
WHILE @iNum > 0
BEGIN
SET @iDigit = dbo.I_Modulus(@iNum, 10)
IF @cnt = 1
SET @sTens = dbo.I_CN2W_GetWord(@iDigit)
ELSE
BEGIN
SET @iDigit = @iDigit * 10
SET @sTens = dbo.I_CN2W_GetWord(@iDigit) + ' ' + @sTens
END
SET @cnt = (@cnt + 1)
SET @iNum = (@iNum / 10)
END
SET @sRetVal = @sTens
END
RETURN (@sRetVal)
END
CREATE FUNCTION I_CN2W_GetHundreds (@sValue NVARCHAR(100))
RETURNS NVARCHAR(100) AS
BEGIN
DECLARE @rstHun as NVARCHAR(100), @sHun as NVARCHAR(100), @sTens AS NVARCHAR(100), @sRetVal as NVARCHAR(100)
IF RTRIM(LTRIM(@sValue)) = '000'
BEGIN
SET @sRetVal = ''
END
ELSE
BEGIN
SET @sHun = SUBSTRING(RTRIM(LTRIM(@sValue)),1,1)
SET @sTens = dbo.I_CN2W_GetTens(SUBSTRING(RTRIM(LTRIM(@sValue)),2,2))
IF (LEN(RTRIM(LTRIM(@sTens))) > 0)
BEGIN
SET @rstHun = dbo.I_CN2W_GetWord(CONVERT(INT, @sHun))
IF (LEN(RTRIM(LTRIM(@rstHun))) > 0)
BEGIN
SET @rstHun = @rstHun + ' Hundred and ' + @sTens
END
ELSE
BEGIN
SET @rstHun = @sTens
END
END
ELSE
BEGIN
SET @rstHun = dbo.I_CN2W_GetWord(CONVERT(INT, @sHun)) + ' Hundred'
END
SET @sRetVal = @rstHun
END
RETURN (@sRetVal)
END
CREATE FUNCTION I_CN2W_GetThousands (@sValue NVARCHAR(100))
RETURNS NVARCHAR(100) AS
BEGIN
DECLARE @rstHun as NVARCHAR(100), @rstThou AS NVARCHAR(100), @strHun as NVARCHAR(100), @strNum AS NVARCHAR(100), @strThou AS NVARCHAR(100)
DECLARE @sRetVal as NVARCHAR(100)
IF @sValue = '00000'
BEGIN
SET @sRetVal = ''
END
ELSE
BEGIN
SET @strNum = RTRIM(LTRIM(@sValue))
SET @strHun =
CASE
WHEN LEN(@strNum) = 4 THEN SUBSTRING(@strNum,2,3)
ELSE SUBSTRING(@strNum,3,3)
END
SET @strThou = SUBSTRING(@strNum,1,LEN(@strNum)-3)
SET @rstHun = dbo.I_CN2W_GetHundreds(@strHun)
SET @rstThou =
CASE
WHEN CAST(@strThou AS INT) <= 20 THEN dbo.I_CN2W_GetWord(CONVERT(INT, @strThou))
ELSE dbo.I_CN2W_GetTens(@strThou)
END
IF (LEN(@rstThou)>0)
BEGIN
SET @rstThou = @rstThou + ' Thousand ' + @rstHun
END
ELSE
BEGIN
SET @rstThou = @rstHun
END
SET @sRetVal = @rstThou
END
RETURN (@sRetVal)
END
CREATE FUNCTION I_CN2W_GetLakhs (@sValue NVARCHAR(100))
RETURNS NVARCHAR(100) AS
BEGIN
DECLARE @rstThou as NVARCHAR(100), @rstLakhs AS NVARCHAR(100), @strLakhs as NVARCHAR(100), @strNum AS NVARCHAR(100), @strThou AS NVARCHAR(100)
DECLARE @sRetVal as NVARCHAR(100)
IF @sValue = '0000000'
BEGIN
SET @sRetVal = ''
END
ELSE
BEGIN
SET @strNum = RTRIM(LTRIM(@sValue))
SET @strThou =
CASE
WHEN LEN(@strNum) = 6 THEN SUBSTRING(@strNum,2,5)
ELSE SUBSTRING(@strNum,3,5)
END
SET @strLakhs = SUBSTRING(@strNum,1,LEN(@strNum)-5)
SET @rstThou = dbo.I_CN2W_GetThousands(@strThou)
SET @rstLakhs =
CASE
WHEN CAST(@strLakhs AS INT) <= 20 THEN dbo.I_CN2W_GetWord(CONVERT(INT, @strLakhs))
ELSE dbo.I_CN2W_GetTens(@strLakhs)
END
IF (LEN(@rstLakhs)>0)
BEGIN
SET @rstLakhs = @rstLakhs + ' Lakh ' + @rstThou
END
ELSE
BEGIN
SET @rstLakhs = @rstThou
END
SET @sRetVal = @rstLakhs
END
RETURN (@sRetVal)
END
CREATE FUNCTION I_CN2W_GetCrores (@sValue NVARCHAR(255))
RETURNS NVARCHAR(255) AS
BEGIN
DECLARE @rstCro as NVARCHAR(255), @rstLakhs AS NVARCHAR(255), @strNum as NVARCHAR(100), @strLakhs AS NVARCHAR(255), @strCro AS NVARCHAR(255)
DECLARE @sRetVal as NVARCHAR(255)
IF @sValue = '000000000'
BEGIN
SET @sRetVal = ''
END
ELSE
BEGIN
SET @strNum = RTRIM(LTRIM(@sValue))
SET @strLakhs =
CASE
WHEN LEN(@strNum) = 8 THEN SUBSTRING(@strNum,2,7)
ELSE SUBSTRING(@strNum,3,7)
END
SET @strCro = SUBSTRING(@strNum,1,LEN(@strNum)-7)
SET @rstLakhs = dbo.I_CN2W_GetLakhs(@strLakhs)
SET @rstCro =
CASE
WHEN CAST(@strCro AS INT) <= 20 THEN dbo.I_CN2W_GetWord(CONVERT(INT, @strCro))
ELSE dbo.I_CN2W_GetTens(@strCro)
END
IF LEN(@rstCro)>0
BEGIN
SET @rstCro = @rstCro + ' Crore ' + @rstLakhs
END
ELSE
BEGIN
SET @rstCro = @rstLakhs
END
SET @sRetVal = @rstCro
END
RETURN (@sRetVal)
END
CREATE FUNCTION I_CN2W_GetArabs (@sValue NVARCHAR(255))
RETURNS NVARCHAR(255) AS
BEGIN
DECLARE @rstArab as NVARCHAR(255), @rstCro AS NVARCHAR(255), @strNum as NVARCHAR(255), @strCro AS NVARCHAR(255), @strArab AS NVARCHAR(255)
DECLARE @sRetVal as NVARCHAR(255)
IF @sValue = '00000000000'
BEGIN
SET @sRetVal = ''
END
ELSE
BEGIN
SET @strNum = RTRIM(LTRIM(@sValue))
SET @strCro =
CASE
WHEN LEN(@strNum) = 10 THEN SUBSTRING(@strNum,2,9)
ELSE SUBSTRING(@strNum,3,9)
END
SET @strArab = SUBSTRING(@strNum,1,LEN(@strNum)-9)
SET @rstCro = dbo.I_CN2W_GetCrores(@strCro)
SET @rstArab =
CASE
WHEN CAST(@strArab AS INT) <= 20 THEN dbo.I_CN2W_GetWord(CONVERT(INT, @strArab))
ELSE dbo.I_CN2W_GetTens(@strArab)
END
IF LEN(@rstArab)>0
BEGIN
SET @rstArab = @rstArab + ' Arab ' + @rstCro
END
ELSE
BEGIN
SET @rstArab = @rstCro
END
SET @sRetVal = @rstArab
END
RETURN (@sRetVal)
END
CREATE FUNCTION I_CN2W_GetKharabs (@sValue NVARCHAR(255))
RETURNS NVARCHAR(255) AS
BEGIN
DECLARE @rstArab as NVARCHAR(255), @rstKharab AS NVARCHAR(255), @strNum as NVARCHAR(255), @strKharab AS NVARCHAR(255), @strArab AS NVARCHAR(255)
DECLARE @sRetVal as NVARCHAR(255)
IF @sValue = '10000000000000'
BEGIN
SET @sRetVal = 'Hundred Kharab '
END
ELSE
BEGIN
SET @strNum = RTRIM(LTRIM(@sValue))
SET @strArab =
CASE
WHEN LEN(@strNum) = 12 THEN SUBSTRING(@strNum,2,11)
ELSE SUBSTRING(@strNum,3,11)
END
SET @strKharab = SUBSTRING(@strNum,1,LEN(@strNum)-11)
SET @rstArab = dbo.I_CN2W_GetArabs(@strArab)
SET @rstKharab =
CASE
WHEN CAST(@strKharab AS INT) <= 20 THEN dbo.I_CN2W_GetWord(CONVERT(INT, @strKharab))
ELSE dbo.I_CN2W_GetTens(@strKharab)
END
IF @rstKharab IS NOT NULL
BEGIN
SET @rstKharab = @rstKharab + ' Kharab ' + @rstArab
END
ELSE
BEGIN
SET @rstKharab = @rstArab
END
SET @sRetVal = @rstKharab
END
RETURN (@sRetVal)
END
CREATE FUNCTION I_CN2W_GetAbvKharab (@sValue NVARCHAR(255))
RETURNS NVARCHAR(255) AS
BEGIN
DECLARE @rstArab as NVARCHAR(255), @rstAbvKharab AS NVARCHAR(255), @strNum as NVARCHAR(255), @strArab AS NVARCHAR(255), @strAbvKharab AS NVARCHAR(255)
DECLARE @sRetVal as NVARCHAR(255), @ONLY AS NVARCHAR(10)
SET @ONLY = 'Only'
SET @strNum = RTRIM(LTRIM(@sValue))
SET @strArab = SUBSTRING(@strNum, ((LEN(@strNum)-11)+1),11)
SET @strAbvKharab = SUBSTRING(@strNum,1,LEN(@strNum)-11)
SET @rstArab = dbo.I_CN2W_GetArabs(@strArab)
SET @rstAbvKharab = REPLACE(dbo.I_ConvertN2W(CONVERT(MONEY, @strAbvKharab),0),@ONLY,'')
SET @rstAbvKharab = @rstAbvKharab + ' Kharab ' + @rstArab
SET @sRetVal = @rstAbvKharab
RETURN (@sRetVal)
END
CREATE FUNCTION I_ConvertN2W (@curNumber MONEY, @bPrefixCurrencyName BIT)
RETURNS VARCHAR(400) AS
BEGIN
---This Function is an Adapted (Scaled Down) version of ConvertN2W from the ITCCF32.dll Custom Functions Library by Infinite Technologies
---Original and Adapted (SQL) both Versions authored by Murtaza R.E. This function is provided on AS IS WHERE IS BASIS
---This peice of code can be freely used for all puposes, however please Do Not Forget to mention the source
---Suggestions and Bugs can be send to me at murtaza1972 at gmail dot com, I do not assure an immediate fix, but will try as time permits
---If you find this peice of code helpful, please do drop me a mail, this will encourage me to do something more creative
DECLARE @sRetVal AS VARCHAR(400), @RUP AS NVARCHAR(10), @PAISE AS NVARCHAR(10), @ONLY AS NVARCHAR(10)
DECLARE @curr AS MONEY, @strFirst AS VARCHAR(100), @lngDeciLen AS INT, @strDeci AS VARCHAR(100)
DECLARE @i AS INT, @rstDeci AS VARCHAR(100), @strNum as VARCHAR(400), @lngNum AS INT, @rstNum AS VARCHAR(400)
DECLARE @rstWord AS VARCHAR(400)
SET @RUP =
CASE
WHEN (@bPrefixCurrencyName = 1) THEN 'Rupees'
ELSE ''
END
SET @PAISE = 'Paise'
SET @ONLY = 'Only'
SET @curr = @curNumber
IF @curr < 0
BEGIN
SET @sRetVal = NULL
END
IF @curr = 0
BEGIN
SET @sRetVal = @RUP + ' Zero ' + @ONLY
END
SET @strFirst = LTRIM(STR(@curNumber,30,2))
SET @lngDeciLen =
CASE
WHEN PATINDEX('%.%',@strFirst) > 0 THEN (LEN(@strFirst)-PATINDEX('%.%',@strFirst))
ELSE 0
END
IF @lngDeciLen <> 0
BEGIN
SET @i = CASE
WHEN PATINDEX('%.%',@strFirst) > 0 THEN (PATINDEX('%.%',@strFirst) + 1)
ELSE 0
END
SET @strDeci = dbo.I_Mid(@strFirst, @i, @lngDeciLen)
END
ELSE
BEGIN
SET @strDeci = '0'
END
SET @strDeci =
CASE
WHEN LEN(@strDeci) = 1 THEN (@strDeci + '0')
ELSE @strDeci
END
SET @rstDeci = dbo.I_CN2W_GetTens(@strDeci)
SET @i =
CASE
WHEN PATINDEX('%.%', @strFirst)>0 THEN (PATINDEX('%.%',@strFirst)-1)
ELSE LEN(@strFirst)
END
SET @strNum = dbo.I_Mid(@strFirst,1,@i)
IF (@strNum IS NULL) OR (LEN(@strNum)=0)
BEGIN
SET @strNum = '0'
END
IF CONVERT(MONEY,@strNum) <= 99999
BEGIN
SET @lngNum = CONVERT(INT,@strNum)
SET @rstNum =
CASE
WHEN (@lngNum <= 20) THEN dbo.I_CN2W_GetWord(@lngNum)
WHEN ((@lngNum > 21) AND (@lngNum <= 99)) THEN dbo.I_CN2W_GetTens(@strNum)
WHEN ((@lngNum > 99) AND (@lngNum <= 999)) THEN dbo.I_CN2W_GetHundreds(@strNum)
WHEN ((@lngNum > 999) AND (@lngNum <= 99999)) THEN dbo.I_CN2W_GetThousands(@strNum)
END
END
IF CONVERT(MONEY,@strNum) > 99999
BEGIN
SET @rstNum =
CASE
WHEN ((CONVERT(MONEY,@strNum) > 99999) AND (CONVERT(MONEY,@strNum) <= 9999999)) THEN dbo.I_CN2W_GetLakhs(@strNum)
WHEN ((CONVERT(MONEY,@strNum) > 9999999) AND (CONVERT(MONEY,@strNum) <= 999999999)) THEN dbo.I_CN2W_GetCrores(@strNum)
WHEN ((CONVERT(MONEY,@strNum) > 999999999) AND (CONVERT(MONEY,@strNum) <= 99999999999)) THEN dbo.I_CN2W_GetArabs(@strNum)
WHEN (CONVERT(MONEY,@strNum) <= 10000000000000) THEN dbo.I_CN2W_GetKharabs(@strNum)
WHEN (CONVERT(MONEY,@strNum) > 10000000000000) THEN dbo.I_CN2W_GetAbvKharab(@strNum)
END
END
IF (LEN(RTRIM(LTRIM(@rstDeci))) = 0) OR (@rstDeci IS NULL)
BEGIN
SET @rstWord = @RUP + ' ' + @rstNum + ' ' + @ONLY
END
ELSE
BEGIN
IF (LEN(RTRIM(LTRIM(@rstNum))) > 0) OR (@rstNum IS NOT NULL)
BEGIN
SET @rstWord = @RUP + ' ' + @rstNum + ' and ' + @rstDeci + ' ' + @PAISE + ' ' + @ONLY
END
ELSE
BEGIN
SET @rstWord = @rstDeci + ' ' + @PAISE + ' ' + @ONLY
END
END
SET @sRetVal =
CASE
WHEN ((LEN(RTRIM(LTRIM(@rstWord)))=0) OR (@rstWord IS NULL)) THEN 'Zero'
ELSE REPLACE(RTRIM(LTRIM(@rstWord)),' ',' ')
END
RETURN (@sRetVal)
END
Step 3:
Code in SBO_SP_TransactionNotification
IF ((@object_type = '46') AND (@transaction_type = 'A')) -- Outgoing PAYMENT
BEGIN
DECLARE @sWords AS VARCHAR(400), @iValue AS MONEY
SET @error = 46
SET @iValue = (SELECT [CheckSum] FROM dbo.OVPM WHERE DocEntry = @list_of_cols_val_tab_del)
SET @sWords =
CASE
WHEN @iValue > 0 THEN dbo.I_ConvertN2W(@iValue,0) --call the function only when the value is more than 0
END
UPDATE dbo.OVPM
SET U_AmountInWord = @sWords
WHERE ((DocEntry = @list_of_cols_val_tab_del) AND ([CheckSum]>0)) --we want to update only when the means of payment is by cheque
SET @error = 0 --success
END
xxxxxxxxxxxxxxxENDxxxxxxxxxxxxxxxxxx---
This is being currently used by me, and works fine for me, I hope this will be useful to you and others
Regards,
Murtaza R.E. -
Amount in Words (Indian Rupees)
Dear All,
I am using SAP 2007B PL 18.I have found out the below mentioned function for converting the amount to words in SDN only. But when i try and create the function it gives error "Incorrect Syntax near 00' . I think there is an incomplete syntax near the SubString function. Can someone please help me on the same and give the correct function.
Create function [dbo].[AmountToWords] ( @InNumber Numeric(18,2) )
--Returns the number as words.
returns VARCHAR(2000)
as
BEGIN
SET NoCount ON
Declare @Num Varchar(20)
Declare @Dec Varchar(3)
Declare @Return Varchar(2000)
Set @Dec = SubString(Convert(Varchar(20),@Innumber),Len(Convert(Varchar(20),@Innumber))-2,3)
Set @Num = SubString(Convert(Varchar(20),@Innumber),1, Len(Convert(Varchar(20),@Innumber))-3)
Declare @Hundred Char(8) Declare @HundredAnd Char(12) Declare @Thousand Char(9)
Declare @Lakh Char(5)
Declare @Lakhs Char(6)
Declare @Crore Char(6)
Declare @Crores Char(7)
Set @Hundred = 'Hundred '
Set @Thousand = 'Thousand '
Set @Lakh = 'Lakh '
Set @Lakhs = 'Lakhs '
Set @Crore = 'Crore '
Set @Crores = 'Crores '
Set @HundredAnd = 'Hundred and '
if Len(@Num) = 1
-- One
Begin
Set @Return = dbo.GetTextValue(@Num)
End
Else if Len(@Num) = 2
-- Ten
Begin
Set @Return = dbo.GetTextValue(@Num)
End
Else if Len(@Num) = 3
-- Hundred
Begin
Set @Return = dbo.GetTextValue(SubString(@Num,1,1)) + @Hundred
IF SubString(@num,2,2) '00'
Set @Return = @Return + 'And '
Set @Return = @Return + dbo.GetTextValue(SubString(@Num,2,2))
End
Else if Len(@Num) = 4
-- thousand
Begin
Set @Return = dbo.GetTextValue(SubString(@Num,1,1)) + @Thousand
If SubString(@Num,2,1) '0'
Set @Return = @Return + dbo.GetTextValue(SubString(@Num,2,1)) + @Hundred
IF SubString(@num,3,2) '00'
Set @Return = @Return + 'And '
Set @Return = @Return + dbo.GetTextValue(SubString(@Num,3,2))
End
Else if Len(@Num) = 5
-- Ten Thousand
Begin
Set @Return = dbo.GetTextValue(SubString(@Num,1,2)) + @Thousand
If SubString(@Num,3,1) '0'
Set @Return = @Return + dbo.GetTextValue(SubString(@Num,3,1)) + @Hundred
IF SubString(@num,4,2) '00'
Set @Return = @Return + 'And '
Set @Return = @Return + dbo.GetTextValue(SubString(@Num,4,2))
End
Else if Len(@Num) = 6
-- Lakh
Begin
If SubString(@Num,1,1) = '1'
Set @Return = dbo.GetTextValue(SubString(@Num,1,1)) + @Lakh
Else
Set @Return = dbo.GetTextValue(SubString(@Num,1,1)) + @Lakhs
If SubString(@Num,2,2) '00'
Set @Return = @Return + dbo.GetTextValue(SubString(@Num,2,2)) + @Thousand
If SubString(@Num,4,1) '0'
Set @Return = @Return + dbo.GetTextValue(SubString(@Num,4,1)) + @Hundred
IF SubString(@num,5,2) '00'
Set @Return = @Return + 'And '
Set @Return = @Return + dbo.GetTextValue(SubString(@Num,5,2))
End
Else if Len(@Num) = 7
-- Ten Lakhs
Begin
Set @Return = dbo.GetTextValue(SubString(@Num,1,2)) + @Lakhs
If SubString(@Num,3,2) '00'
Set @Return = @Return + dbo.GetTextValue(SubString(@Num,3,2)) + @Thousand
If SubString(@Num,6,1) '0'
Set @Return = @Return + dbo.GetTextValue(SubString(@Num,5,1)) + @Hundred
IF SubString(@num,6,2) '00'
Set @Return = @Return + 'And '
Set @Return = @Return + dbo.GetTextValue(SubString(@Num,6,2))
End
Else if Len(@Num) = 8
-- Crore
Begin
Set @Return = dbo.GetTextValue(SubString(@Num,1,1)) + @Crore
If SubString(@Num,2,2) '00'
Set @Return = @Return + dbo.GetTextValue(SubString(@Num,2,2)) + @Lakhs
If SubString(@Num,4,2) '00'
Set @Return = @Return + dbo.GetTextValue(SubString(@Num,4,2)) + @Thousand
If SubString(@Num,6,1) '0'
Set @Return = @Return + dbo.GetTextValue(SubString(@Num,6,1)) + @Hundred
IF SubString(@num,7,2) '00'
Set @Return = @Return + 'And '
Set @Return = @Return + dbo.GetTextValue(SubString(@Num,7,2))
End
Else if Len(@Num) = 9
-- Ten Crore
Begin
Set @Return = dbo.GetTextValue(SubString(@Num,1,2)) + @Crores
If SubString(@Num,3,2) '00'
Set @Return = @Return + dbo.GetTextValue(SubString(@Num,3,2)) + @Lakhs
If SubString(@Num,5,2) '00'
Set @Return = @Return + dbo.GetTextValue(SubString(@Num,5,2)) + @Thousand
If SubString(@Num,7,1) '0'
Set @Return = @Return + dbo.GetTextValue(SubString(@Num,7,1)) + @Hundred
IF SubString(@num,8,2) '00'
Set @Return = @Return + 'And '
Set @Return = @Return + dbo.GetTextValue(SubString(@Num,8,2))
End
Else if Len(@Num) = 10
-- Hundred Crore
Begin
Set @Return = dbo.GetTextValue(Substring(@Num,1,1)) + @Hundred
IF Substring(@Num,2,2) '00'
Set @Return = @Return + dbo.GetTextValue(SubString(@Num,2,2))
Set @Return = @Return + @Crores
If SubString(@Num,4,2) '00'
Set @Return = @Return + dbo.GetTextValue(SubString(@Num,4,2)) + @Lakhs
If SubString(@Num,6,2) '00'
Set @Return = @Return + dbo.GetTextValue(SubString(@Num,6,2)) + @Thousand
If SubString(@Num,8,1) '0'
Set @Return = @Return + dbo.GetTextValue(SubString(@Num,8,1)) + @Hundred
IF SubString(@num,9,2) '00'
Set @Return = @Return + 'And '
Set @Return = @Return + dbo.GetTextValue(SubString(@Num,9,2))
End
Else if Len(@Num) = 11
-- Thousand Crore
Begin Set @Return = dbo.GetTextValue(Substring(@Num,1,1)) + @Thousand
IF SubString(@Num,2,1) '0'
Set @Return = @Return + dbo.GetTextValue(Substring(@Num,2,1)) + @Hundred
IF Substring(@Num,3,2) '00'
Set @Return = @Return + dbo.GetTextValue(SubString(@Num,3,2))
Set @Return = @Return + @Crores If SubString(@Num,5,2) '00'
Set @Return = @Return + dbo.GetTextValue(SubString(@Num,5,2)) + @Lakhs
If SubString(@Num,7,2) '00'
Set @Return = @Return + dbo.GetTextValue(SubString(@Num,7,2)) + @Thousand
If SubString(@Num,9,1) '0'
Set @Return = @Return + dbo.GetTextValue(SubString(@Num,9,1)) + @Hundred
IF SubString(@num,10,2) '00'
Set @Return = @Return + 'And '
Set @Return = @Return + dbo.GetTextValue(SubString(@Num,10,2))
End
Else if Len(@Num) = 12
-- Ten thousand Crore
Begin Set @Return = dbo.GetTextValue(Substring(@Num,1,2)) + @Thousand
IF SubString(@Num,3,1) '0'
Set @Return = @Return + dbo.GetTextValue(Substring(@Num,3,1)) + @Hundred
IF Substring(@Num,4,2) '00'
Set @Return = @Return + dbo.GetTextValue(SubString(@Num,4,2))
Set @Return = @Return + @Crores If SubString(@Num,6,2) '00'
Set @Return = @Return + dbo.GetTextValue(SubString(@Num,6,2)) + @Lakhs
If SubString(@Num,8,2) '00'
Set @Return = @Return + dbo.GetTextValue(SubString(@Num,8,2)) + @Thousand
If SubString(@Num,10,1) '0'
Set @Return = @Return + dbo.GetTextValue(SubString(@Num,10,1)) + @Hundred
IF SubString(@num,11,2) '00'
Set @Return = @Return + 'And '
Set @Return = @Return + dbo.GetTextValue(SubString(@Num,11,2))
End
Else if Len(@Num) = 13
-- Lakh Crore
Begin Set @Return = dbo.GetTextValue(Substring(@Num,1,1)) + @Lakh
If Substring(@Num,2,2) '00'
Set @Return = @Return + dbo.GetTextValue(Substring(@Num,2,2)) + @Thousand
IF SubString(@Num,4,1) '0'
Set @Return = @Return + dbo.GetTextValue(Substring(@Num,4,1)) + @Hundred
IF Substring(@Num,5,2) '00'
Set @Return = @Return + dbo.GetTextValue(SubString(@Num,5,2))
Set @Return = @Return + @Crores
If SubString(@Num,7,2) '00'
Set @Return = @Return + dbo.GetTextValue(SubString(@Num,7,2)) + @Lakhs
If SubString(@Num,9,2) '00'
Set @Return = @Return + dbo.GetTextValue(SubString(@Num,9,2)) + @Thousand
If SubString(@Num,11,1) '0'
Set @Return = @Return + dbo.GetTextValue(SubString(@Num,11,1)) + @Hundred
IF SubString(@num,12,2) '00'
Set @Return = @Return + 'And '
Set @Return = @Return + dbo.GetTextValue(SubString(@Num,12,2))
End
Else if Len(@Num) = 14
-- Ten Lakh Crore
Begin Set @Return = dbo.GetTextValue(Substring(@Num,1,2)) + @Lakhs
If Substring(@Num,3,2) '00'
Set @Return = @Return + dbo.GetTextValue(Substring(@Num,3,2)) + @Thousand
IF SubString(@Num,5,1) '0'
Set @Return = @Return + dbo.GetTextValue(Substring(@Num,5,1)) + @Hundred
IF Substring(@Num,6,2) '00'
Set @Return = @Return + dbo.GetTextValue(SubString(@Num,6,2))
Set @Return = @Return + @Crores If SubString(@Num,8,2) '00'
Set @Return = @Return + dbo.GetTextValue(SubString(@Num,8,2)) + @Lakhs
If SubString(@Num,10,2) '00'
Set @Return = @Return + dbo.GetTextValue(SubString(@Num,10,2)) + @Thousand
If SubString(@Num,12,1) '0'
Set @Return = @Return + dbo.GetTextValue(SubString(@Num,12,1)) + @Hundred
IF SubString(@num,13,2) '00'
Set @Return = @Return + 'And '
Set @Return = @Return + dbo.GetTextValue(SubString(@Num,13,2))
End
If @Dec '.00'
Set @Return = @Return + 'Rupees And ' + dbo.GetTextValue(SubString(@Dec,2,2)) + 'Paise Only'
ELSE
Set @Return =@Return+'Zero Rupees Only'
Return @return
End
CREATE Function [dbo].[GetTextValue] ( @dblNumber Numeric )
Returns Varchar(1000)
As
Begin
Declare @StrWord Varchar(400)
SET @strWord = Case @dblNumber
When 1 Then 'One '
When 2 Then 'Two '
When 3 Then 'Three '
When 4 Then 'Four '
When 5 Then 'Five '
When 6 Then 'Six '
When 7 Then 'Seven '
When 8 Then 'Eight '
When 9 Then 'Nine '
When 10 Then 'Ten '
When 11 Then 'Eleven '
When 12 Then 'Twelve '
When 13 Then 'Thirteen '
When 14 Then 'Fourteen '
When 15 Then 'Fifteen '
When 16 Then 'Sixteen '
When 17 Then 'Seventeen '
When 18 Then 'Eighteen '
When 19 Then 'Nineteen '
When 20 Then 'Twenty '
When 21 Then 'Twenty One '
When 22 Then 'Twenty Two '
When 23 Then 'Twenty Three '
When 24 Then 'Twenty Four '
When 25 Then 'Twenty Five '
When 26 Then 'Twenty Six '
When 27 Then 'Twenty Seven '
When 28 Then 'Twenty Eight '
When 29 Then 'Twenty Nine '
When 30 Then 'Thirty '
When 31 Then 'Thirty One '
When 32 Then 'Thirty Two '
When 33 Then 'Thirty Three '
When 34 Then 'Thirty Four '
When 35 Then 'Thirty Five '
When 36 Then 'Thirty Six '
When 37 Then 'Thirty Seven '
When 38 Then 'Thirty Eight '
When 39 Then 'Thirty Nine '
When 40 Then 'Fourty '
When 41 Then 'Fourty One '
When 42 Then 'Fourty Two '
When 43 Then 'Fourty Three '
When 44 Then 'Fourty Four '
When 45 Then 'Fourty Five '
When 46 Then 'Fourty Six '
When 47 Then 'Fourty Seven '
When 48 Then 'Fourty Eight '
When 49 Then 'Fourty Nine '
When 50 Then 'Fifty '
When 51 Then 'Fifty One '
When 52 Then 'Fifty Two '
When 53 Then 'Fifty Three '
When 54 Then 'Fifty Four '
When 55 Then 'Fifty Five '
When 56 Then 'Fifty Six '
When 57 Then 'Fifty Seven '
When 58 Then 'Fifty Eight '
When 59 Then 'Fifty Nine '
When 60 Then 'Sixty '
When 61 Then 'Sixty One '
When 62 Then 'Sixty Two '
When 63 Then 'Sixty Three '
When 64 Then 'Sixty Four '
When 65 Then 'Sixty Five '
When 66 Then 'Sixty Six '
When 67 Then 'Sixty Seven '
When 68 Then 'Sixty Eight '
When 69 Then 'Sixty Nine '
When 70 Then 'Seventy '
When 71 Then 'Seventy One '
When 72 Then 'Seventy Two '
When 73 Then 'Seventy Three '
When 74 Then 'Seventy Four '
When 75 Then 'Seventy Five '
When 76 Then 'Seventy Six '
When 77 Then 'Seventy Seven '
When 78 Then 'Seventy Eight '
When 79 Then 'Seventy Nine '
When 80 Then 'Eighty '
When 81 Then 'Eighty One '
When 82 Then 'Eighty Two '
When 83 Then 'Eighty Three '
When 84 Then 'Eighty Four '
When 85 Then 'Eighty Five '
When 86 Then 'Eighty Six '
When 87 Then 'Eighty Seven '
When 88 Then 'Eighty Eight '
When 89 Then 'Eighty Nine '
When 90 Then 'Ninety '
When 91 Then 'Ninety One '
When 92 Then 'Ninety Two '
When 93 Then 'Ninety Three '
When 94 Then 'Ninety Four '
When 95 Then 'Ninety Five '
When 96 Then 'Ninety Six '
When 97 Then 'Ninety Seven '
When 98 Then 'Ninety Eight '
When 99 Then 'Ninety Nine '
When 100 Then 'One hundred '
else ' '
End
Return @strWord
End
Regards,
RahulDear Rahul,
Try this,
->> Create 1 UDF in Header on Requrie Documents (ex. Marketing Documents).
->> Create 3 Function in MSSQL Server Management.
->> Create 1 FMS in Query Generator and save as Query Manager then Assign to UDF for Amount in Words.
for example:
Create UDF in Header on Marketing Documents.
->> Choose Tools on Top menu.
->> User - Defined Fields. -> User Manage Fields.
->> Open the User Manage Fields Widnow.
->> Marketing Documents. -> Title.
->> Select Title and Click Add button in Bottom on User Manage Fields Window.
->> Create Amount in Words UDF(Code, Discription and Type - Character) and Add the UDF.
Create Function in MSSQL Server Management.
Check this Link, (have 3 Functions in Link).
http://techcreeze.blogspot.com/2008/11/convert-amount-into-words-according-to_15.html
1st Funciton - to Convert one Digit Number to words
2nd Funciton - to convert 2 digit number to words.
3rd Funciton - to convert amt in numbers to words.
->> Open the MSSQL Server Management Window.
->> Choose your Company database and Create NEW Query.
->> Create 3 Function Queries one by one.
->> Create 3 NEW Query Tab and 1st one put the 1st Function then Run the Function. and
2nd New Query tab put the 2nd Function then Run the Function.
3rd New Query tab put the 3rd Function then Run the Function.
Create FMS in Query Generator and Save as Query Manager.
->> Adminstration.
->> Reports. -> Query Generator.
->> Open the Query Generator and put the below FMS query.
for example : Purchase Order Doc. Toal(in wrods).
declare @Doc_total numeric (19,6)
set @Doc_total=$[OPOR.DocTotal]
select dbo.fNumToWords (@Doc_total)
->> Assign the FMS in UDF on Purchase Order.
->> Auto Refresh of Document Total.
Ex.
1. Goto the UDF and Clcik ShiftAltF2.
2. Select the SEARCH BY SAVED QUERY.
3. Assign the FMS Query.
4. Select the AUTO REFRESH WHEN FIELD CHENGES.
5. Select Document Total.
6. Check the Display Saved Values. -
Amount in words in indian format
Dear All,
I have refer this link to get amount in words in indian format.but it is showing me error.what i copied in sql is -
*if exists (select * from dbo.sysobjects where id = object_id(N'dbo.AmountToWords') and xtype in (N'FN', N'IF', N'TF')) drop function dbo.AmountToWords GO if exists (select * from dbo.sysobjects where id = object_id(N'dbo.GetTextValue') and xtype in (N'FN', N'IF', N'TF')) drop function dbo.GetTextValue GO SET QUOTED_IDENTIFIER OFF GO SET ANSI_NULLS ON GO CREATE function AmountToWords ( @InNumber Numeric(18,2) ) --Returns the number as words. returns VARCHAR(2000) as BEGIN --SEt NoCount ON Declare @Num Varchar(20) Declare @Dec Varchar(3) Declare @Return Varchar(2000) Set @Dec = SubString(Convert(Varchar(20),@Innumber),Len(Convert(Varchar(20),@Innumber))-2,3) Set @Num = SubString(Convert(Varchar(20),@Innumber),1, Len(Convert(Varchar(20),@Innumber))-3) Declare @Hundred Char(8) Declare @HundredAnd Char(12) Declare @Thousand Char(9) Declare @Lakh Char(5) Declare @Lakhs Char(6) Declare @Crore Char(6) Declare @Crores Char(7) Set @Hundred = 'Hundred ' Set @Thousand = 'Thousand ' Set @Lakh = 'Lakh ' Set @Lakhs = 'Lakhs ' Set @Crore = 'Crore ' Set @Crores = 'Crores ' Set @HundredAnd = 'Hundred and ' if Len(@Num) = 1 -- One Begin Set @Return = dbo.GetTextValue(@Num) End Else if Len(@Num) = 2 -- Ten Begin Set @Return = dbo.GetTextValue(@Num) End Else if Len(@Num) = 3 -- Hundred Begin Set @Return = dbo.GetTextValue(SubString(@Num,1,1)) + @Hundred IF SubString(@num,2,2) '00' Set @Return = @Return + 'And ' Set @Return = @Return + dbo.GetTextValue(SubString(@Num,2,2)) End Else if Len(@Num) = 4 -- thousand Begin Set @Return = dbo.GetTextValue(SubString(@Num,1,1)) + @Thousand If SubString(@Num,2,1) '0' Set @Return = @Return + dbo.GetTextValue(SubString(@Num,2,1)) + @Hundred IF SubString(@num,3,2) '00' Set @Return = @Return + 'And ' Set @Return = @Return + dbo.GetTextValue(SubString(@Num,3,2)) End Else if Len(@Num) = 5 -- Ten Thousand Begin Set @Return = dbo.GetTextValue(SubString(@Num,1,2)) + @Thousand If SubString(@Num,3,1) '0' Set @Return = @Return + dbo.GetTextValue(SubString(@Num,3,1)) + @Hundred IF SubString(@num,4,2) '00' Set @Return = @Return + 'And ' Set @Return = @Return + dbo.GetTextValue(SubString(@Num,4,2)) End Else if Len(@Num) = 6 -- Lakh Begin If SubString(@Num,1,1) = '1' Set @Return = dbo.GetTextValue(SubString(@Num,1,1)) + @Lakh Else Set @Return = dbo.GetTextValue(SubString(@Num,1,1)) + @Lakhs If SubString(@Num,2,2) '00' Set @Return = @Return + dbo.GetTextValue(SubString(@Num,2,2)) + @Thousand If SubString(@Num,4,1) '0' Set @Return = @Return + dbo.GetTextValue(SubString(@Num,4,1)) + @Hundred IF SubString(@num,5,2) '00' Set @Return = @Return + 'And ' Set @Return = @Return + dbo.GetTextValue(SubString(@Num,5,2)) End Else if Len(@Num) = 7 -- Ten Lakhs Begin Set @Return = dbo.GetTextValue(SubString(@Num,1,2)) + @Lakhs If SubString(@Num,3,2) '00' Set @Return = @Return + dbo.GetTextValue(SubString(@Num,3,2)) + @Thousand If SubString(@Num,6,1) '0' Set @Return = @Return + dbo.GetTextValue(SubString(@Num,5,1)) + @Hundred IF SubString(@num,6,2) '00' Set @Return = @Return + 'And ' Set @Return = @Return + dbo.GetTextValue(SubString(@Num,6,2)) End Else if Len(@Num) = 8 -- Crore Begin Set @Return = dbo.GetTextValue(SubString(@Num,1,1)) + @Crore If SubString(@Num,2,2) '00' Set @Return = @Return + dbo.GetTextValue(SubString(@Num,2,2)) + @Lakhs If SubString(@Num,4,2) '00' Set @Return = @Return + dbo.GetTextValue(SubString(@Num,4,2)) + @Thousand If SubString(@Num,6,1) '0' Set @Return = @Return + dbo.GetTextValue(SubString(@Num,6,1)) + @Hundred IF SubString(@num,7,2) '00' Set @Return = @Return + 'And ' Set @Return = @Return + dbo.GetTextValue(SubString(@Num,7,2)) End Else if Len(@Num) = 9 -- Ten Crore Begin Set @Return = dbo.GetTextValue(SubString(@Num,1,2)) + @Crores If SubString(@Num,3,2) '00' Set @Return = @Return + dbo.GetTextValue(SubString(@Num,3,2)) + @Lakhs If SubString(@Num,5,2) '00' Set @Return = @Return + dbo.GetTextValue(SubString(@Num,5,2)) + @Thousand If SubString(@Num,7,1) '0' Set @Return = @Return + dbo.GetTextValue(SubString(@Num,7,1)) + @Hundred IF SubString(@num,8,2) '00' Set @Return = @Return + 'And ' Set @Return = @Return + dbo.GetTextValue(SubString(@Num,8,2)) End Else if Len(@Num) = 10 -- Hundred Crore Begin Set @Return = dbo.GetTextValue(Substring(@Num,1,1)) + @Hundred IF Substring(@Num,2,2) '00' Set @Return = @Return + dbo.GetTextValue(SubString(@Num,2,2)) Set @Return = @Return + @Crores If SubString(@Num,4,2) '00' Set @Return = @Return + dbo.GetTextValue(SubString(@Num,4,2)) + @Lakhs If SubString(@Num,6,2) '00' Set @Return = @Return + dbo.GetTextValue(SubString(@Num,6,2)) + @Thousand If SubString(@Num,8,1) '0' Set @Return = @Return + dbo.GetTextValue(SubString(@Num,8,1)) + @Hundred IF SubString(@num,9,2) '00' Set @Return = @Return + 'And ' Set @Return = @Return + dbo.GetTextValue(SubString(@Num,9,2)) End Else if Len(@Num) = 11 -- Thousand Crore Begin Set @Return = dbo.GetTextValue(Substring(@Num,1,1)) + @Thousand IF SubString(@Num,2,1) '0' Set @Return = @Return + dbo.GetTextValue(Substring(@Num,2,1)) + @Hundred IF Substring(@Num,3,2) '00' Set @Return = @Return + dbo.GetTextValue(SubString(@Num,3,2)) Set @Return = @Return + @Crores If SubString(@Num,5,2) '00' Set @Return = @Return + dbo.GetTextValue(SubString(@Num,5,2)) + @Lakhs If SubString(@Num,7,2) '00' Set @Return = @Return + dbo.GetTextValue(SubString(@Num,7,2)) + @Thousand If SubString(@Num,9,1) '0' Set @Return = @Return + dbo.GetTextValue(SubString(@Num,9,1)) + @Hundred IF SubString(@num,10,2) '00' Set @Return = @Return + 'And ' Set @Return = @Return + dbo.GetTextValue(SubString(@Num,10,2)) End Else if Len(@Num) = 12 -- Ten thousand Crore Begin Set @Return = dbo.GetTextValue(Substring(@Num,1,2)) + @Thousand IF SubString(@Num,3,1) '0' Set @Return = @Return + dbo.GetTextValue(Substring(@Num,3,1)) + @Hundred IF Substring(@Num,4,2) '00' Set @Return = @Return + dbo.GetTextValue(SubString(@Num,4,2)) Set @Return = @Return + @Crores If SubString(@Num,6,2) '00' Set @Return = @Return + dbo.GetTextValue(SubString(@Num,6,2)) + @Lakhs If SubString(@Num,8,2) '00' Set @Return = @Return + dbo.GetTextValue(SubString(@Num,8,2)) + @Thousand If SubString(@Num,10,1) '0' Set @Return = @Return + dbo.GetTextValue(SubString(@Num,10,1)) + @Hundred IF SubString(@num,11,2) '00' Set @Return = @Return + 'And ' Set @Return = @Return + dbo.GetTextValue(SubString(@Num,11,2)) End Else if Len(@Num) = 13 -- Lakh Crore Begin Set @Return = dbo.GetTextValue(Substring(@Num,1,1)) + @Lakh If Substring(@Num,2,2) '00' Set @Return = @Return + dbo.GetTextValue(Substring(@Num,2,2)) + @Thousand IF SubString(@Num,4,1) '0' Set @Return = @Return + dbo.GetTextValue(Substring(@Num,4,1)) + @Hundred IF Substring(@Num,5,2) '00' Set @Return = @Return + dbo.GetTextValue(SubString(@Num,5,2)) Set @Return = @Return + @Crores If SubString(@Num,7,2) '00' Set @Return = @Return + dbo.GetTextValue(SubString(@Num,7,2)) + @Lakhs If SubString(@Num,9,2) '00' Set @Return = @Return + dbo.GetTextValue(SubString(@Num,9,2)) + @Thousand If SubString(@Num,11,1) '0' Set @Return = @Return + dbo.GetTextValue(SubString(@Num,11,1)) + @Hundred IF SubString(@num,12,2) '00' Set @Return = @Return + 'And ' Set @Return = @Return + dbo.GetTextValue(SubString(@Num,12,2)) End Else if Len(@Num) = 14 -- Ten Lakh Crore Begin Set @Return = dbo.GetTextValue(Substring(@Num,1,2)) + @Lakhs If Substring(@Num,3,2) '00' Set @Return = @Return + dbo.GetTextValue(Substring(@Num,3,2)) + @Thousand IF SubString(@Num,5,1) '0' Set @Return = @Return + dbo.GetTextValue(Substring(@Num,5,1)) + @Hundred IF Substring(@Num,6,2) '00' Set @Return = @Return + dbo.GetTextValue(SubString(@Num,6,2)) Set @Return = @Return + @Crores If SubString(@Num,8,2) '00' Set @Return = @Return + dbo.GetTextValue(SubString(@Num,8,2)) + @Lakhs If SubString(@Num,10,2) '00' Set @Return = @Return + dbo.GetTextValue(SubString(@Num,10,2)) + @Thousand If SubString(@Num,12,1) '0' Set @Return = @Return + dbo.GetTextValue(SubString(@Num,12,1)) + @Hundred IF SubString(@num,13,2) '00' Set @Return = @Return + 'And ' Set @Return = @Return + dbo.GetTextValue(SubString(@Num,13,2)) End If @Dec '.00' Set @Return = @Return + 'Rupees And ' + dbo.GetTextValue(SubString(@Dec,2,2)) + 'Paise' ELSE Set @Return =@Return +'Rupees' Return @return End GO SET QUOTED_IDENTIFIER OFF GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO SET ANSI_NULLS ON GO CREATE Function dbo.GetTextValue ( @dblNumber Numeric ) Returns Varchar(1000) As Begin Declare @StrWord Varchar(400) SEt @strWord = Case @dblNumber When 1 Then 'One ' When 2 Then 'Two ' When 3 Then 'Three ' When 4 Then 'Four ' When 5 Then 'Five ' When 6 Then 'Six ' When 7 Then 'Seven ' When 8 Then 'Eight ' When 9 Then 'Nine ' When 10 Then 'Ten ' When 11 Then 'Eleven ' When 12 Then 'Twelve ' When 13 Then 'Thirteen ' When 14 Then 'Fourteen ' When 15 Then 'Fifteen ' When 16 Then 'Sixteen ' When 17 Then 'Seventeen ' When 18 Then 'Eighteen ' When 19 Then 'Nineteen ' When 20 Then 'Twenty ' When 21 Then 'Twenty One ' When 22 Then 'Twenty Two ' When 23 Then 'Twenty Three ' When 24 Then 'Twenty Four ' When 25 Then 'Twenty Five ' When 26 Then 'Twenty Six ' When 27 Then 'Twenty Seven ' When 28 Then 'Twenty Eight ' When 29 Then 'Twenty Nine ' When 30 Then 'Thirty ' When 31 Then 'Thirty One ' When 32 Then 'Thirty Two ' When 33 Then 'Thirty Three ' When 34 Then 'Thirty Four ' When 35 Then 'Thirty Five ' When 36 Then 'Thirty Six ' When 37 Then 'Thirty Seven ' When 38 Then 'Thirty Eight ' When 39 Then 'Thirty Nine ' When 40 Then 'Fourty ' When 41 Then 'Fourty One ' When 42 Then 'Fourty Two ' When 43 Then 'Fourty Three ' When 44 Then 'Fourty Four ' When 45 Then 'Fourty Five ' When 46 Then 'Fourty Six ' When 47 Then 'Fourty Seven ' When 48 Then 'Fourty Eight ' When 49 Then 'Fourty Nine ' When 50 Then 'Fifty ' When 51 Then 'Fifty One ' When 52 Then 'Fifty Two ' When 53 Then 'Fifty Three ' When 54 Then 'Fifty Four ' When 55 Then 'Fifty Five ' When 56 Then 'Fifty Six ' When 57 Then 'Fifty Seven ' When 58 Then 'Fifty Eight ' When 59 Then 'Fifty Nine ' When 60 Then 'Sixty ' When 61 Then 'Sixty One ' When 62 Then 'Sixty Two ' When 63 Then 'Sixty Three ' When 64 Then 'Sixty Four ' When 65 Then 'Sixty Five ' When 66 Then 'Sixty Six ' When 67 Then 'Sixty Seven ' When 68 Then 'Sixty Eight ' When 69 Then 'Sixty Nine ' When 70 Then 'Seventy ' When 71 Then 'Seventy One ' When 72 Then 'Seventy Two ' When 73 Then 'Seventy Three ' When 74 Then 'Seventy Four ' When 75 Then 'Seventy Five ' When 76 Then 'Seventy Six ' When 77 Then 'Seventy Seven ' When 78 Then 'Seventy Eight ' When 79 Then 'Seventy Nine ' When 80 Then 'Eighty ' When 81 Then 'Eighty One ' When 82 Then 'Eighty Two ' When 83 Then 'Eighty Three ' When 84 Then 'Eighty Four ' When 85 Then 'Eighty Five ' When 86 Then 'Eighty Six ' When 87 Then 'Eighty Seven ' When 88 Then 'Eighty Eight ' When 89 Then 'Eighty Nine ' When 90 Then 'Ninety ' When 91 Then 'Ninety One ' When 92 Then 'Ninety Two ' When 93 Then 'Ninety Three ' When 94 Then 'Ninety Four ' When 95 Then 'Ninety Five ' When 96 Then 'Ninety Six ' When 97 Then 'Ninety Seven ' When 98 Then 'Ninety Eight ' When 99 Then 'Ninety Nine ' When 100 Then 'One hundred ' else ' ' End Return @strWord End GO SET QUOTED_IDENTIFIER OFF GO SET ANSI_NULLS ON GO*
but it showed me error.Let me know where i am getting wrong.
I also created 1 UDF on the document where you want the amount in words as per indian format. run the query generateor,paste the below query... and save it. declare @Doc_total numeric (19,6) set @Doc_total=$[OINV.DocTotal] select dbo.AmountToWords (@Doc_total) now apply formated search on the UDF you created(For e.g. i created on SALes Invoice) refresh regularly on doctotal. now choose that UDF on pld. Hope this will help u. Regards, Neetu
Regards-
Mona.Dear,,
Run the below functions in your database:
Create function [dbo].[AmountToWords]
@InNumber Numeric(18,2)
--Returns the number as words.
returns VARCHAR(2000)
as
BEGIN
--SEt NoCount ON
Declare @Num Varchar(20)
Declare @Dec Varchar(3)
Declare @Return Varchar(2000)
Set @Dec = SubString(Convert(Varchar(20),@Innumber),Len(Convert(Varchar(20),@Innumber))-2,3)
Set @Num = SubString(Convert(Varchar(20),@Innumber),1, Len(Convert(Varchar(20),@Innumber))-3)
Declare @Hundred Char(8)
Declare @HundredAnd Char(12)
Declare @Thousand Char(9)
Declare @Lakh Char(5)
Declare @Lakhs Char(6)
Declare @Crore Char(6)
Declare @Crores Char(7)
Set @Hundred = 'Hundred '
Set @Thousand = 'Thousand '
Set @Lakh = 'Lakh '
Set @Lakhs = 'Lakhs '
Set @Crore = 'Crore '
Set @Crores = 'Crores '
Set @HundredAnd = 'Hundred and '
if Len(@Num) = 1 -- One
Begin
Set @Return = dbo.GetTextValue(@Num)
End
Else if Len(@Num) = 2 -- Ten
Begin
Set @Return = dbo.GetTextValue(@Num)
End
Else if Len(@Num) = 3 -- Hundred
Begin
Set @Return = dbo.GetTextValue(SubString(@Num,1,1)) + @Hundred
IF SubString(@num,2,2) <> '00'
Set @Return = @Return + 'And '
Set @Return = @Return + dbo.GetTextValue(SubString(@Num,2,2))
End
Else if Len(@Num) = 4 -- thousand
Begin
Set @Return = dbo.GetTextValue(SubString(@Num,1,1)) + @Thousand
If SubString(@Num,2,1) <> '0'
Set @Return = @Return + dbo.GetTextValue(SubString(@Num,2,1)) + @Hundred
IF SubString(@num,3,2) <> '00'
Set @Return = @Return + 'And '
Set @Return = @Return + dbo.GetTextValue(SubString(@Num,3,2))
End
Else if Len(@Num) = 5 -- Ten Thousand
Begin
Set @Return = dbo.GetTextValue(SubString(@Num,1,2)) + @Thousand
If SubString(@Num,3,1) <> '0'
Set @Return = @Return + dbo.GetTextValue(SubString(@Num,3,1)) + @Hundred
IF SubString(@num,4,2) <> '00'
Set @Return = @Return + 'And '
Set @Return = @Return + dbo.GetTextValue(SubString(@Num,4,2))
End
Else if Len(@Num) = 6 -- Lakh
Begin
If SubString(@Num,1,1) = '1'
Set @Return = dbo.GetTextValue(SubString(@Num,1,1)) + @Lakh
Else
Set @Return = dbo.GetTextValue(SubString(@Num,1,1)) + @Lakhs
If SubString(@Num,2,2) <> '00'
Set @Return = @Return + dbo.GetTextValue(SubString(@Num,2,2)) + @Thousand
If SubString(@Num,4,1) <> '0'
Set @Return = @Return + dbo.GetTextValue(SubString(@Num,4,1)) + @Hundred
IF SubString(@num,5,2) <> '00'
Set @Return = @Return + 'And '
Set @Return = @Return + dbo.GetTextValue(SubString(@Num,5,2))
End
Else if Len(@Num) = 7 -- Ten Lakhs
Begin
Set @Return = dbo.GetTextValue(SubString(@Num,1,2)) + @Lakhs
If SubString(@Num,3,2) <> '00'
Set @Return = @Return + dbo.GetTextValue(SubString(@Num,3,2)) + @Thousand
If SubString(@Num,6,1) <> '0'
Set @Return = @Return + dbo.GetTextValue(SubString(@Num,5,1)) + @Hundred
IF SubString(@num,6,2) <> '00'
Set @Return = @Return + 'And '
Set @Return = @Return + dbo.GetTextValue(SubString(@Num,6,2))
End
Else if Len(@Num) = 8 -- Crore
Begin
Set @Return = dbo.GetTextValue(SubString(@Num,1,1)) + @Crore
If SubString(@Num,2,2) <> '00'
Set @Return = @Return + dbo.GetTextValue(SubString(@Num,2,2)) + @Lakhs
If SubString(@Num,4,2) <> '00'
Set @Return = @Return + dbo.GetTextValue(SubString(@Num,4,2)) + @Thousand
If SubString(@Num,6,1) <> '0'
Set @Return = @Return + dbo.GetTextValue(SubString(@Num,6,1)) + @Hundred
IF SubString(@num,7,2) <> '00'
Set @Return = @Return + 'And '
Set @Return = @Return + dbo.GetTextValue(SubString(@Num,7,2))
End
Else if Len(@Num) = 9 -- Ten Crore
Begin
Set @Return = dbo.GetTextValue(SubString(@Num,1,2)) + @Crores
If SubString(@Num,3,2) <> '00'
Set @Return = @Return + dbo.GetTextValue(SubString(@Num,3,2)) + @Lakhs
If SubString(@Num,5,2) <> '00'
Set @Return = @Return + dbo.GetTextValue(SubString(@Num,5,2)) + @Thousand
If SubString(@Num,7,1) <> '0'
Set @Return = @Return + dbo.GetTextValue(SubString(@Num,7,1)) + @Hundred
IF SubString(@num,8,2) <> '00'
Set @Return = @Return + 'And '
Set @Return = @Return + dbo.GetTextValue(SubString(@Num,8,2))
End
Else if Len(@Num) = 10 -- Hundred Crore
Begin
Set @Return = dbo.GetTextValue(Substring(@Num,1,1)) + @Hundred
IF Substring(@Num,2,2) <> '00'
Set @Return = @Return + dbo.GetTextValue(SubString(@Num,2,2))
Set @Return = @Return + @Crores
If SubString(@Num,4,2) <> '00'
Set @Return = @Return + dbo.GetTextValue(SubString(@Num,4,2)) + @Lakhs
If SubString(@Num,6,2) <> '00'
Set @Return = @Return + dbo.GetTextValue(SubString(@Num,6,2)) + @Thousand
If SubString(@Num,8,1) <> '0'
Set @Return = @Return + dbo.GetTextValue(SubString(@Num,8,1)) + @Hundred
IF SubString(@num,9,2) <> '00'
Set @Return = @Return + 'And '
Set @Return = @Return + dbo.GetTextValue(SubString(@Num,9,2))
End
Else if Len(@Num) = 11 -- Thousand Crore
Begin
Set @Return = dbo.GetTextValue(Substring(@Num,1,1)) + @Thousand
IF SubString(@Num,2,1) <> '0'
Set @Return = @Return + dbo.GetTextValue(Substring(@Num,2,1)) + @Hundred
IF Substring(@Num,3,2) <> '00'
Set @Return = @Return + dbo.GetTextValue(SubString(@Num,3,2))
Set @Return = @Return + @Crores
If SubString(@Num,5,2) <>'00'
Set @Return = @Return + dbo.GetTextValue(SubString(@Num,5,2)) + @Lakhs
If SubString(@Num,7,2) <> '00'
Set @Return = @Return + dbo.GetTextValue(SubString(@Num,7,2)) + @Thousand
If SubString(@Num,9,1) <> '0'
Set @Return = @Return + dbo.GetTextValue(SubString(@Num,9,1)) + @Hundred
IF SubString(@num,10,2) <> '00'
Set @Return = @Return + 'And '
Set @Return = @Return + dbo.GetTextValue(SubString(@Num,10,2))
End
Else if Len(@Num) = 12 -- Ten thousand Crore
Begin
Set @Return = dbo.GetTextValue(Substring(@Num,1,2)) + @Thousand
IF SubString(@Num,3,1) <> '0'
Set @Return = @Return + dbo.GetTextValue(Substring(@Num,3,1)) + @Hundred
IF Substring(@Num,4,2) <> '00'
Set @Return = @Return + dbo.GetTextValue(SubString(@Num,4,2))
Set @Return = @Return + @Crores
If SubString(@Num,6,2) <> '00'
Set @Return = @Return + dbo.GetTextValue(SubString(@Num,6,2)) + @Lakhs
If SubString(@Num,8,2) <> '00'
Set @Return = @Return + dbo.GetTextValue(SubString(@Num,8,2)) + @Thousand
If SubString(@Num,10,1) <> '0'
Set @Return = @Return + dbo.GetTextValue(SubString(@Num,10,1)) + @Hundred
IF SubString(@num,11,2) <> '00'
Set @Return = @Return + 'And '
Set @Return = @Return + dbo.GetTextValue(SubString(@Num,11,2))
End
Else if Len(@Num) = 13 -- Lakh Crore
Begin
Set @Return = dbo.GetTextValue(Substring(@Num,1,1)) + @Lakh
If Substring(@Num,2,2) <> '00'
Set @Return = @Return + dbo.GetTextValue(Substring(@Num,2,2)) + @Thousand
IF SubString(@Num,4,1) <> '0'
Set @Return = @Return + dbo.GetTextValue(Substring(@Num,4,1)) + @Hundred
IF Substring(@Num,5,2) <> '00'
Set @Return = @Return + dbo.GetTextValue(SubString(@Num,5,2))
Set @Return = @Return + @Crores
If SubString(@Num,7,2) <> '00'
Set @Return = @Return + dbo.GetTextValue(SubString(@Num,7,2)) + @Lakhs
If SubString(@Num,9,2) <> '00'
Set @Return = @Return + dbo.GetTextValue(SubString(@Num,9,2)) + @Thousand
If SubString(@Num,11,1) <> '0'
Set @Return = @Return + dbo.GetTextValue(SubString(@Num,11,1)) + @Hundred
IF SubString(@num,12,2) <> '00'
Set @Return = @Return + 'And '
Set @Return = @Return + dbo.GetTextValue(SubString(@Num,12,2))
End
Else if Len(@Num) = 14 -- Ten Lakh Crore
Begin
Set @Return = dbo.GetTextValue(Substring(@Num,1,2)) + @Lakhs
If Substring(@Num,3,2) <> '00'
Set @Return = @Return + dbo.GetTextValue(Substring(@Num,3,2)) + @Thousand
IF SubString(@Num,5,1) <> '0'
Set @Return = @Return + dbo.GetTextValue(Substring(@Num,5,1)) + @Hundred
IF Substring(@Num,6,2) <> '00'
Set @Return = @Return + dbo.GetTextValue(SubString(@Num,6,2))
Set @Return = @Return + @Crores
If SubString(@Num,8,2) <> '00'
Set @Return = @Return + dbo.GetTextValue(SubString(@Num,8,2)) + @Lakhs
If SubString(@Num,10,2) <> '00'
Set @Return = @Return + dbo.GetTextValue(SubString(@Num,10,2)) + @Thousand
If SubString(@Num,12,1) <> '0'
Set @Return = @Return + dbo.GetTextValue(SubString(@Num,12,1)) + @Hundred
IF SubString(@num,13,2) <> '00'
Set @Return = @Return + 'And '
Set @Return = @Return + dbo.GetTextValue(SubString(@Num,13,2))
End
If @Dec <> '.00'
Set @Return = @Return + 'Rupees And ' + dbo.GetTextValue(SubString(@Dec,2,2)) + 'Paise Only'
ELSE
Set @Return =@Return+'Zero Rupees Only'
Return @return
End
CREATEFunction [dbo].[GetTextValue]
@dblNumber Numeric
Returns Varchar(1000)
As
Begin
Declare @StrWord Varchar(400)
SEt @strWord = Case @dblNumber
When 1 Then 'One '
When 2 Then 'Two '
When 3 Then 'Three '
When 4 Then 'Four '
When 5 Then 'Five '
When 6 Then 'Six '
When 7 Then 'Seven '
When 8 Then 'Eight '
When 9 Then 'Nine '
When 10 Then 'Ten '
When 11 Then 'Eleven '
When 12 Then 'Twelve '
When 13 Then 'Thirteen '
When 14 Then 'Fourteen '
When 15 Then 'Fifteen '
When 16 Then 'Sixteen '
When 17 Then 'Seventeen '
When 18 Then 'Eighteen '
When 19 Then 'Nineteen '
When 20 Then 'Twenty '
When 21 Then 'Twenty One '
When 22 Then 'Twenty Two '
When 23 Then 'Twenty Three '
When 24 Then 'Twenty Four '
When 25 Then 'Twenty Five '
When 26 Then 'Twenty Six '
When 27 Then 'Twenty Seven '
When 28 Then 'Twenty Eight '
When 29 Then 'Twenty Nine '
When 30 Then 'Thirty '
When 31 Then 'Thirty One '
When 32 Then 'Thirty Two '
When 33 Then 'Thirty Three '
When 34 Then 'Thirty Four '
When 35 Then 'Thirty Five '
When 36 Then 'Thirty Six '
When 37 Then 'Thirty Seven '
When 38 Then 'Thirty Eight '
When 39 Then 'Thirty Nine '
When 40 Then 'Fourty '
When 41 Then 'Fourty One '
When 42 Then 'Fourty Two '
When 43 Then 'Fourty Three '
When 44 Then 'Fourty Four '
When 45 Then 'Fourty Five '
When 46 Then 'Fourty Six '
When 47 Then 'Fourty Seven '
When 48 Then 'Fourty Eight '
When 49 Then 'Fourty Nine '
When 50 Then 'Fifty '
When 51 Then 'Fifty One '
When 52 Then 'Fifty Two '
When 53 Then 'Fifty Three '
When 54 Then 'Fifty Four '
When 55 Then 'Fifty Five '
When 56 Then 'Fifty Six '
When 57 Then 'Fifty Seven '
When 58 Then 'Fifty Eight '
When 59 Then 'Fifty Nine '
When 60 Then 'Sixty '
When 61 Then 'Sixty One '
When 62 Then 'Sixty Two '
When 63 Then 'Sixty Three '
When 64 Then 'Sixty Four '
When 65 Then 'Sixty Five '
When 66 Then 'Sixty Six '
When 67 Then 'Sixty Seven '
When 68 Then 'Sixty Eight '
When 69 Then 'Sixty Nine '
When 70 Then 'Seventy '
When 71 Then 'Seventy One '
When 72 Then 'Seventy Two '
When 73 Then 'Seventy Three '
When 74 Then 'Seventy Four '
When 75 Then 'Seventy Five '
When 76 Then 'Seventy Six '
When 77 Then 'Seventy Seven '
When 78 Then 'Seventy Eight '
When 79 Then 'Seventy Nine '
When 80 Then 'Eighty '
When 81 Then 'Eighty One '
When 82 Then 'Eighty Two '
When 83 Then 'Eighty Three '
When 84 Then 'Eighty Four '
When 85 Then 'Eighty Five '
When 86 Then 'Eighty Six '
When 87 Then 'Eighty Seven '
When 88 Then 'Eighty Eight '
When 89 Then 'Eighty Nine '
When 90 Then 'Ninety '
When 91 Then 'Ninety One '
When 92 Then 'Ninety Two '
When 93 Then 'Ninety Three '
When 94 Then 'Ninety Four '
When 95 Then 'Ninety Five '
When 96 Then 'Ninety Six '
When 97 Then 'Ninety Seven '
When 98 Then 'Ninety Eight '
When 99 Then 'Ninety Nine '
When 100 Then 'One hundred '
else ' '
End
Return @strWord
End
Run the query generator of SAP,paste below query.
Apply FMS on field.
declare @Doc_total numeric (19,6)
set @Doc_total=$[OINV.DocTotal]
select dbo.AmountToWords (@Doc_total) -
Amount in words in Smart Forms.
Dear All,
I want to Print the amount in words in Smart Forms.
Is there any function modules <<removed by moderator>>.
Also how to call it in SF.
Thank you in advance,
Arun.
Search before posting and Read the rules of engagementHi,
This has been discussed a lot of times already in the forum, if you have done a search you would have got hundreds of threads.
Do search the Forum before posting a question.
Read the [Rules of Engagement|https://www.sdn.sap.com/irj/sdn/wiki?path=/display/home/rulesofEngagement] before posting more.
Search Results for [ amount in words (1238 Results)|https://www.sdn.sap.com/irj/sdn/advancedsearch?query=amountinwords&cat=sdn_all]
Search Results for [Spell_amount (158 Results)|https://www.sdn.sap.com/irj/sdn/advancedsearch?query=spell_amount&cat=sdn_all]
Regards
Karthik D
Maybe you are looking for
-
MacBook Air mid-2013 OSX 10.9.1 cannot connect to DVI Monitor
Does anyone else have this problem? I've seen similar issues raised, but so far can't find a solution to my particular issue: MacBook Air Mid 2013 (ordered Jan 2014) - 1.3GHz Intel Core i5 - 8GB 1600MHz DDR3 RAM - OSX 10.9.1 Mavericks. When I connec
-
Hello, I was wondering if someone knows what this error message in the Mac App Store means. I am trying to run Software Update by clicking in the Apple Menu however, I am not able to see my available updates and instead get the following message on t
-
Change default refresh rates reports
Hi!!! In SQL Developer yo have the option to refresh a Report choosing among 5, 10, 15, 20, 25, 30, 60, 120. Is is possible to change that default values????? Thanks a lot! Jose.
-
Trying to enable flashback database on 11g Linux platform database
Hello, SQL> ALTER DATABASE FLASHBACK ON; ALTER DATABASE FLASHBACK ON ERROR at line 1: ORA-38759: Database must be mounted by only one instance and not open Can any one help understand why I am getting this error while I have only one instance open? T
-
An unknown error occurred (-54).
I recently started getting this message when I plug my iphone into my imac "The iTunes library file cannot be saved. An unknown error occurred (-54)."