‎2009 Sep 13 11:34 AM
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
‎2009 Sep 13 1:12 PM
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
‎2009 Sep 13 3:01 PM
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
‎2009 Sep 13 4:44 PM
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.
‎2009 Sep 13 9:45 PM
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
‎2009 Sep 14 7:56 AM
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.
‎2009 Sep 14 12:48 PM
> 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
‎2009 Sep 14 12:56 PM
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
‎2009 Sep 14 1:27 PM
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
‎2009 Sep 14 12:58 PM
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
‎2009 Sep 14 1:27 PM
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
‎2009 Sep 14 1:58 PM
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
‎2009 Sep 14 2:17 PM
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
‎2009 Sep 14 2:39 PM
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
‎2009 Sep 14 3:05 PM
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