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: 

Change the Source Code of a FM Dynamically.

Former Member
0 Kudos

Hi All,

I wanted to change the source code of FM Dynamically.

Is there any way for that ?

Thanking You All..!!

1 ACCEPTED SOLUTION

Juwin
Active Contributor
0 Kudos

*******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

19 REPLIES 19

vijayanandpaul_puvvula3
Active Participant
0 Kudos

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.

Former Member
0 Kudos

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

0 Kudos

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..!!

Former Member
0 Kudos

I hope not - it would be pretty dangerous.

Rob

Former Member
0 Kudos

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.... .

0 Kudos

Hi Lucas,

I am still searching for the solution.

Would request  you kindly share your views..!!

Thanking You All..!!

0 Kudos

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.

0 Kudos

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

matt
Active Contributor
0 Kudos

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.

0 Kudos

Sorry Matt - wasn't aware of that. But I think in the OPs context, it shouldn't be allowed.

Rob

matt
Active Contributor
0 Kudos

I don't disagree Rob. I can't think of any purpose (other than SAPLink and CTS!) for dynamically generating function modules.

Last chance to respond, or the thread is going to be rejected.

0 Kudos

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.

0 Kudos

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

0 Kudos

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..!!

0 Kudos

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

0 Kudos

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..!!

nishantbansal91
Active Contributor
0 Kudos

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

0 Kudos

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 ( , , Sir ), can I proceed with this approch ?

Thanking You All..!!

Juwin
Active Contributor
0 Kudos

*******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