04-28-2015 3:56 PM
Hi All,
I wanted to change the source code of FM Dynamically.
Is there any way for that ?
Thanking You All..!!
05-01-2015 3:27 PM
*******I strongly recommend against doing this.......
If you need to build code dynamically based on some conditions, there should be a way to statically code those conditions as well.
That said, if you absolutely want to generate code dynamically, my recommendation would be to generate subroutine pool, and call the generated subroutine from your RFC.
RFC function module code shouldn't change because, that function may be called simultaneously by different instances/threads/systems. If the code inside RFC function module changes, that will effect everyone calling the RFC. Instead, for each RFC call, you will have to generate a unique subroutine pool name, insert the code into the subroutine pool, generate subroutine pool, call the subroutine and then delete the subroutine pool.
Thanks,
Juwin
04-28-2015 4:06 PM
Dear SAP Rocks,
Thanks for your question. It is very interesting. First of all, the code you write in your FM is what the system executes based on the logic. You can control which piece of code you want to execute based on the logical statements such as
IF...ELSE...
CASE... ENDCASE...
Regards,
Vijay.
04-28-2015 4:07 PM
As far as I know, you cannot change function module source code dynamically. Maybe you could do something where you put all the logic of the function into an INCLUDE program; then you can re-create the include program using INSERT REPORT statement. But that won't help you if you also need to change the function module interface dynamically.
A better approach is to try to use dynamic programming techniques within your code and avoid generating programs if possible.
Jim
04-28-2015 4:12 PM
Thanks Vijay and Jim,
I believe there must be some thing.
Since there are FM to create FM, I am searching some thing to change existing FM.
FUNCTION_CREATE
Further more the Syntax of INSERT REPORT gives provision for Function group or function pool,, I am searching for Function Module.
Thanking You All..!!
04-28-2015 4:13 PM
04-28-2015 6:11 PM
Sounds like you've come up with a solution. What problem are you trying to solve? I'm sure we can find a better way.... .
04-28-2015 9:15 PM
Hi Lucas,
I am still searching for the solution.
Would request you kindly share your views..!!
Thanking You All..!!
04-28-2015 9:18 PM
You have not stated what problem you are trying to solve.
I'm saying that you probably don't need to dynamically modify function modules.
04-28-2015 9:49 PM
And I'm saying that it should not be possible.
For example, an unscrupulous ABAPer dynamically changes a FM to write him or herself a check and then dynamically changes it back so that his or her tracks are erased.
So, as Lucas asked, what is your basic requirement?
Rob
04-29-2015 6:42 AM
It must be possible or SAPLink wouldn't work... or CTS for that matter!
but if the OP doesn't respond with an answer to the question of why he thinks he needs to do this, I will reject the whole thread.
04-29-2015 4:05 PM
Sorry Matt - wasn't aware of that. But I think in the OPs context, it shouldn't be allowed.
Rob
04-29-2015 4:09 PM
04-29-2015 4:15 PM
SAPLink and CTS don't really change code 'dynamically' ie: during execution. That's where my mind goes.
If you've ever imported a transport accidentally during a batch run that impacts one of the classes/functions used by that batch you'll be familiar with the 'load program mismatch' error.
So once you've started execution of a program I don't think it's possible to modify the code of something it uses. I don't know this to be 100% true though.
04-29-2015 5:53 PM
I'm sure with "dynamically" he does not mean "during execution".
There is several ways to generate ABAP code on the fly and then execute it (as executable program or function module), and all are on top of IT auditors' lists when scanning for potentially hazardous code.
Thomas
04-29-2015 9:40 PM
Hi Thomas, Lucas, Rob and Matthew Sir,
I am very sorry for this late reply, in fact I was on plant visit in poor network area..
I need to change the logic inside few RFC FMs based on current unit price of the material.
These RFC FMs are invoked from legacy system.
Thanking You All..!!
04-29-2015 9:55 PM
It doesn't sound to me like you need to change the logic "dynamically". More like you need a BADI or EXIT to change the logic statically, based on your conditions.
Rob
04-30-2015 10:13 AM
Hi Rob,
These are Z* FMs written in our APO System, and we have some changes in algorithm based on the forcasting status for coming months.
I am looking some thing to chnage the Algorithm dynamically.
Thanking You All..!!
04-30-2015 2:32 PM
Dear ,
You can generate the dynamic code using generate subroutine pool.
Using this statement you can create dynamic class using your own source code.
If you need any more help let me know.
Thanks
Nishant
05-01-2015 12:02 PM
Hi Nishant,
Thanks for the help.
But I can not go with subroutine pool, since the code is to be called from a Legacy System.
So, I need an RFC enabled FM.
Any ways, I tried with INSERT REPORT with the generated Include name for FM and I found it working too, I am still testing it with various possible scenario.
Just wanted to get an opinion from you all ( Rob Burbank, Thomas Zloch, Lucas Tétreault, Matthew Billingham Sir ), can I proceed with this approch ?
Thanking You All..!!
05-01-2015 3:27 PM
*******I strongly recommend against doing this.......
If you need to build code dynamically based on some conditions, there should be a way to statically code those conditions as well.
That said, if you absolutely want to generate code dynamically, my recommendation would be to generate subroutine pool, and call the generated subroutine from your RFC.
RFC function module code shouldn't change because, that function may be called simultaneously by different instances/threads/systems. If the code inside RFC function module changes, that will effect everyone calling the RFC. Instead, for each RFC call, you will have to generate a unique subroutine pool name, insert the code into the subroutine pool, generate subroutine pool, call the subroutine and then delete the subroutine pool.
Thanks,
Juwin