Application Development and Automation 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: 
Read only

How to convert Function Module to subroutine

Former Member
0 Likes
747

Hi,

How we can convert functional module to subroutine.

for example i want to convert gui_download ( function module ) to

PERFORM GUI_DOWNLOAD.

Can you pls elaborate this using some code sample.

Regards,

Parnith.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
670

It's easy

perform gui_download using filename ...etc.

form gui_download using p_filename type ....etc.

call function 'gui_download'

filename = p_filename

...etc.

Kind regards, Rob Dielemans

5 REPLIES 5
Read only

Former Member
0 Likes
671

It's easy

perform gui_download using filename ...etc.

form gui_download using p_filename type ....etc.

call function 'gui_download'

filename = p_filename

...etc.

Kind regards, Rob Dielemans

Read only

Former Member
0 Likes
670

Hi,

You just need to paste all the code from that FM to subroutine. But doing this is not recommended.

FM- When the functionality can be used in many programs. Big logic

Subroutine - To modularise the code. Same functionality within progra.

Regards,

Atish

Read only

0 Likes
670

Hi ,

Thanks for your reply.

can you pls let me know how actually we need to define parameters in that function module to parameters of subroutine.

And also how we need to code for exceptions in subroutine.

Can you pls explain me by taking one small example.( converting gui_download FM to

Form GUI_Download.

Regards,

Parnith.

Read only

0 Likes
670

First of all it is not a good idea to convert a fm into a subroutine. Why do you need to duplicate code?

If at all you want to do that, you can see function module import parameter declaration and declare your parameters into subroutine in similar fashion.

Like GUI_DOWNLOAD has import parameter FILENAME declared as string, you can do the same in your routine.

For exceptions, as you are handling this in routine, you need to use message command. Either you can store all messages into a internal table and display at the end or you can show error message and stop processing.

Hope this helps.

ashish

Read only

0 Likes
670

Hi,

I am not in front of system so can't explain using code.

But you have USING CHANGING and TABLES in subroutines whichcan be linked to IMPORTING EXPORTING/CHANGING TABLES in FM.

And for exceptions you need to write your error message using MESSAGE.

Regards,

Atish