Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

function module issue

968

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

1 ACCEPTED SOLUTION

michael_piesche
Active Contributor
436

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)
7 REPLIES 7

former_member1716
Active Contributor
436

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!

0 Kudos
436

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

0 Kudos
436
slanda,In case your are creating a Function Module, ensure your Inputs defined as a part of Import Parameters and Outputs defined as part of export parameters. You can even refer any simple standard function module and check how it is designed.Regards!

michael_piesche
Active Contributor
437

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)

436

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

0 Kudos
436

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

  • What do I import to handle a request and what do I export to give a response?

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

  • What do I export to that FM to handly my request and what do I import from the FM for its response?

michael_piesche
Active Contributor
0 Kudos
436

slanda, please follow up on your open question.

  • comment answers or your question if there are still open issues.
  • otherwise mark an answer as accepted if it helped you solve your problem
  • or post an answer of yourself and accept it if you found another useful solution yourself
  • or redirect your question to another question that is related and was useful to solve your problem
  • in the end, close your question