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

Program which creates function module

Former Member
0 Likes
1,424

Hi,

I wonder if there is a way to write an ABAP program, that will read predefined source code (e.g from file) and then creates a new function module, which will contain the source code.

Thanks for the help,

Sivan

14 REPLIES 14
Read only

Former Member
0 Likes
1,383

Hi,

Nothing comes automatically or predefined.

You need to code your requirement in a FM/program(include) and you may use that in your program.

You may also create a generic business object or check out OO polymorphism(create a generic class with predefined methods and parameters) which might help.

All the best.

Regards,

Amit

Read only

Former Member
0 Likes
1,383

Thanks for the answer.

Maybe I'll explain my requirement in more details.

I want to write a report, which gets parameters and from these parameters create a FM.

(the function module will be created after the report ends the execution).

Is there an API to create FM?

A parameter can be FM name and FM code.

Thanks,

Sivan

Edited by: Sivan Zommer on Sep 13, 2009 4:14 PM

Read only

0 Likes
1,383

Hello Sivan,

One alternative I can see for this requirement is to record function module creation using BDC and then convert that

record in function module. You can replace the function module name, code, function group name from user input.

Hope this helps!

Thanks,

Augustin.

Read only

Former Member
0 Likes
1,383

I don't think this is a good idea...

Can the user also influence the file path?

Since ancient times SAP has a function module called RFC_ABAP_INSTALL_AND_RUN. If you take a look through the coding and consider that it is in it's own function group then you might also think to yourself what good this could possibly bring - except in a sandbox system in an isolated network...

I have seen some solutions which create FM's "on the fly" but their source is always the problem.

Can you explain your requirement? Perhaps it is "only" a release dependency which you are trying to achieve? I am sure there is a better way.

Cheers,

Julius

Read only

Former Member
0 Likes
1,383

The thing is that I want to run a 'main' report, that will get data from external system and then use this data to create a FM.

This external data will be used in the source code for the FM.

Afterwards I want to create a web service from the function module.

Read only

0 Likes
1,383

> The thing is that I want to run a 'main' report, that will get data from external system and then use this data to create a FM.

> This external data will be used in the source code for the FM.

>

> Afterwards I want to create a web service from the function module.

Sounds very much as if transporting (see transaction STMS) is what you are looking for...?

Or alternately something like SAINT with which you can upload packages?

Or does the "external system" also need to be your own PC? Is your PC in the same network as the database server? Is the data txt file format?

Cheers,

Julius

Read only

0 Likes
1,383

I'll try to explain this in example:

I have a text file, which includes 3 field names and types.

The report reads the file and the 3 fields.

Now, I want to create a function module that will get those field as parameters and use them in the source code of the FM.

(the function module can be created in the same system as the report exists in).

Sivan

Read only

0 Likes
1,383

Sorry, I am a bit slow today

So you want a whole bunch of identical FMs except for a part of each which you want to load from the text file instead of typing it into the editor?

I think it would be much easier to simply put all the text file data into the FM itself in form subroutines and call it with a parameter which determines the form to be performed.

You can still create as many services as you wish for the FM and set the parameter in the service call.

Am I on the right track now?

Cheers,

Julius

Read only

Former Member
0 Likes
1,383

Hi Sivan,

if the logic which your are going to write is same

i guess u can try using BDC

as said by some one in the same thread

record SE37

and try to start with your coding

with regards

s.janagar

Read only

Former Member
0 Likes
1,383

Hello Sivan,

please have a look at the packet SFUNC. This Packet holds everything you need to create functions modules programmatically.

But if you have always the same source code and it differs only in the parameters it could be better to write a function module which has a "key/value" Table as parameter. I guess you want so write some generic Import Interface which can be called from outside.

If you give us more information about the thing you want to do, we can help you.

bastian

Read only

0 Likes
1,383

Hi,

Thanks. I think that is what I need.

Maybe you can help me with one more simple thing:

What is the procedure to create the FM automatically, means that the function name, package and parameters will be set in the code (and not as user input).

Thanks,

Sivan

Read only

0 Likes
1,383

My understanding of Basitian's post and my simultaneous one is that you don't need to create the FM name, package, parameters "on the fly".

The "variable" parts are inside the function module which you can create normally and then call with a parametere value which instructs it which code to run.

Cheers,

Julius

Read only

0 Likes
1,383

Hi Sivan,

as Julius and I mentioned before, we don't think that you have to create a dozends of FM. So it would be easier for you, if you create one generic FM with flexible Interface (Parameters).

Think about maintaining a bunch of FM if something changes in Source. You have to change every module instead of just one FM.

bastian

Read only

0 Likes
1,383

First of all, thanks for the good advice

The thing behind my thought now is to generate several web services and each one of them is based on function module.

Each web service will get different parameters...

I have a look at SFUNC and managed to create a function module. My question now is how to insert the input, output and source code into it (automatically of course - in the function call from SFUNC).

Sivan