‎2020 Apr 02 2:49 PM
Hi abapers,
I have SAP BW background.I have used a function module but i have an issue.The functiom module is to spell the amount which we type for example 213 if we enter,the output must be two hundred thirteen
when i execute it im getting the error:
parameters for programs other than type 1 can only be used between begin/end of screenFUNCTION zspellamount.
Below is the code
*"----------------------------------------------------------------------
*"*"Local Interface:
*"----------------------------------------------------------------------
DATA result TYPE spell.
PARAMETERS num_1 TYPE i.
CALL FUNCTION 'SPELL_AMOUNT'
EXPORTING
amount = num_1
currency = ' '
filler = ' '
language = sy-langu
IMPORTING
in_words = result.
IF sy-subrc <> 0.
WRITE:'value returned is:',sy-subrc.
ELSE.
WRITE:'amount in words is:',result-word.
ENDIF.
.
ENDFUNCTION.
Please help
Thank you guys
‎2020 Apr 02 3:06 PM
Your error has nothing to do with the Standard function module SPELL_AMOUNT. It has to do with a syntax error in your Custom function module ZSPELLAMOUNT. You cannot assign a Selection-Screen PARAMETER in a function module.
>> parameters for programs other than type 1 can only be used between begin/end of screen
You should be able to fix it like this:
DATA result TYPE spell.
" PARAMETERS num_1 TYPE i. " you cant have this here !!!
DATA num_1 TYPE i. " use this instead !
" now you need an importing parameter in your function modules interface
" and move that value to variable num_1
" (or use that import parameter instead of num_1 directly for the FM SPELL_AMOUNT)
‎2020 Apr 02 3:05 PM
slanda,
I have used the below Code in a normal report program and its working fine for me.
DATA result TYPE spell.
PARAMETERS num_1 TYPE i.
CALL FUNCTION 'SPELL_AMOUNT'
EXPORTING
amount = num_1
currency = ' '
filler = ' '
language = sy-langu
IMPORTING
in_words = result.
IF sy-subrc <> 0.
WRITE:'value returned is:',sy-subrc.
ELSE.
WRITE:'amount in words is:',result-word.
ENDIF.Now the question is, where have you written this code?
Have you written this code in any Class method or Function Module? Then you have got it totally wrong, you are not supposed declare any parameters there rather you need to use the IMPORT/EXPORT parameters available there. Advice you to go through the respective documentation on the same.
Regards!
‎2020 Apr 03 8:21 AM
Hi Satish,
Thanks for the response.
I also tried to run the code as normal report program and it works fine.I was actually trying to create a customised fn module using a predefined fn module.As i dont have a prior coding experience,Iam unable to understand why the error is being displayed.I will go through you advise of import /export parameters.
Regards,
Siva
‎2020 Apr 03 8:40 AM
‎2020 Apr 02 3:06 PM
Your error has nothing to do with the Standard function module SPELL_AMOUNT. It has to do with a syntax error in your Custom function module ZSPELLAMOUNT. You cannot assign a Selection-Screen PARAMETER in a function module.
>> parameters for programs other than type 1 can only be used between begin/end of screen
You should be able to fix it like this:
DATA result TYPE spell.
" PARAMETERS num_1 TYPE i. " you cant have this here !!!
DATA num_1 TYPE i. " use this instead !
" now you need an importing parameter in your function modules interface
" and move that value to variable num_1
" (or use that import parameter instead of num_1 directly for the FM SPELL_AMOUNT)
‎2020 Apr 03 8:21 AM
Hi Michael,
Thanks for the response.
I have checked your comments and it is very useful.Iam trying to figure out the error.Thanks a lot.
Regards,
Siva
‎2020 Apr 05 4:45 AM
slanda , let me know if you get stuck with other errors, but the first thing you need to do, is to declare your num_1 variable by DATA and not by PARAMETERS.
Then, of course, you need to use input- and output- parameters (IMPORTING, EXPORTING) for your ZSPELLAMOUNT function in order to 'import' an integer with e.g. type NUM_1 and in order to 'export' a word with e.g. type STRING. Look at how the function SPELL_AMOUNT defines its import and export parameters and try to do the similar thing with your function module as well as teh Report RF_SPELL, to see how the FM SPELL_AMOUNT was used in that report.
Side Note: When defining IMPORTING and EXPORTING parameters for the function, they are named and used from the internal function modules view

Whereas when calling or using a function module from another programm (e.g. another report, function module or class-method), the exporting and importing is reversed, looking at the called FM from an external function modules view

‎2020 May 13 3:53 PM
slanda, please follow up on your open question.