‎2007 Jan 19 6:04 PM
Hi,
am a functional guy. I want to understand clearly how a particular functional module works. Like if I want to print invoice value in words there is a functional module Spell_amount. can i have explanation with this as an example.
Thanks in advance
‎2007 Jan 19 6:10 PM
chk this sample
1. Function modules take some input parameters
2. Execute the code written in that using those parameters.
3. Output some parameters
In this Function module , it will take the amont in numbers as input , and the currency and output the amount in words
REPORT ZSPELL.
TABLES SPELL.
DATA : T_SPELL LIKE SPELL OCCURS 0 WITH HEADER LINE.
DATA : PAMOUNT LIKE SPELL-NUMBER VALUE '123451022343333235'.
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
‎2007 Jan 19 6:10 PM
chk this sample
1. Function modules take some input parameters
2. Execute the code written in that using those parameters.
3. Output some parameters
In this Function module , it will take the amont in numbers as input , and the currency and output the amount in words
REPORT ZSPELL.
TABLES SPELL.
DATA : T_SPELL LIKE SPELL OCCURS 0 WITH HEADER LINE.
DATA : PAMOUNT LIKE SPELL-NUMBER VALUE '123451022343333235'.
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
‎2007 Jan 19 6:14 PM
Hi Sahu,
In func module exporting parameters you always pass your values. Importing values will be returned back from func module. tables may be importing or exporting. If you provide exceptions & sy-subrc is not equals to zero then system will throw a particular exception.
Here is a sample code for speel amout. In ths you can pass v_amount that has to be converted to words. sy-langu as a language. currency like 'USD' etc.
v_amount sould be type character.
CALL FUNCTION 'SPELL_AMOUNT'
EXPORTING
amount = v_samount
language = sy-langu
currency = x_regud-waers
IMPORTING
in_words = x_spell
EXCEPTIONS
not_found = 1
too_large = 2
OTHERS = 3.
Ashven
‎2007 Jan 19 6:18 PM
This fn. mod gets the amount in words based on the amount passed.
For eg:
CALL FUNCTION 'SPELL_AMOUNT'
EXPORTING
amount = rv_wrbtr (Amnt in Figures) 10
currency = rv_waers (Currency) USD
language = rv_spras (Language - default EN) EN
IMPORTING
in_words = rv_spell ( The amount in words would be available in the field called word). TEN.
Hope this helps.
Regards
Deepu
‎2007 Jan 19 6:28 PM
Sadhu,
Func Modules are "packages" of code that exist into a special program type called a Function Pool.
A Func Pool is a pool (a collection) of Func Modules.
In ABAP, we can call a Func Mod from inside of an existing/running program...say my custom program - Z_MY_PROG calls out to Function Module Spell_amount.
Z_MY_PROG will halt temporarily upon the call to SPELL_AMOUNT (assuming the called Func Mod it is set to Start Immediately - as SPELL_AMOUNT and most Func Mods are).
The Func Pool program (the main program of SPELL_AMOUNT) will be loaded into memory (if it is not already active in memory) and the package of code in SPELL_AMOUNT will be executed using any values in passed INPUT parameters in the call to SPELL_AMOUNT. Once the func module completes, it will fill in any values into EXPORT parameters (which are the results of the Func Mod's processing) and then return to the calling prog (Z_MY_PROG - in this case).
Z_MY_PROG will then resume execution. It will likely use any returned values from the EXPORT parameters to complete it's needs.