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: 

Local Classes in Function Modules

former_member213112
Participant

Hi,

Is it good practice to create Local classes in Function Modules, please provide details with valid reasons.

Thanks,

Watchpoint.

1 ACCEPTED SOLUTION

matt
Active Contributor

1) Yes it is good practice

2) Modularisation and encapsulation is generally seen in programming as a good thing. FORMs are obsolete, so that leaves you with local classes to modularise and encapsulate your code.

11 REPLIES 11

matt
Active Contributor

1) Yes it is good practice

2) Modularisation and encapsulation is generally seen in programming as a good thing. FORMs are obsolete, so that leaves you with local classes to modularise and encapsulate your code.

joachimrees1
Active Contributor
0 Kudos

I was hoping to also find an answer to "where (which include) in a function group should I add local classes to ?", and now, on a 2nd look I saw you give the answers right here: https://answers.sap.com/comments/13220293/view.html . Thanks!

matt
Active Contributor
0 Kudos

Shame it had an error should read:

  • Suffix "Pxx": Implementation of methods and classes

Sandra_Rossi
Active Contributor
0 Kudos

Like subroutines, function modules may also be considered (*) obsolete, except when required for using RFC, update tasks, screens.

(*) it's not officially said in the ABAP doc

matt
Active Contributor
0 Kudos

Really? I thought it was just FORMS? But it makes sense... but what about where you need a reusable dynpro? That can only be done via FM, which don't have to be RFCs.

Matthew Billingham I should have mentioned that it's not officially said in the ABAP doc. Function modules are required for RFC, update tasks, screens. You can't do that with class pools. For the rest, use class and interface pools.

loyd_enochs3
Participant
0 Kudos

"...to create Local classes in Function Modules"

But it is NOT good practice to create local classes within a Function module. Use one or the other, but not both in combination.

matt
Active Contributor
0 Kudos

loyd.enochs3

Nah. See Sandra's answer below.

If you need an RFC, then modularise using local classes. There's even a naming convention for the includes (can't quite remember what it is at the moment).

Also, function modules with screens might well benefit from a bit of modularisation using local classes.

former_member184158
Active Contributor
0 Kudos

Why it is good to practice to create Local classes in Function Modules? I think it is better when to create global class and use it in FM rather than local class. Of course we can create local class in FM like in Program rather than Form (Subroutine).

If the class is very specific to the FM, then a local FM makes sense.

Furthermore, if you have code in the FM and want to test it, you should write local test classes.

developerone
Contributor
0 Kudos

Personal Opinion:

not a fan of the hybrid approach. I would rather stick to either procedural or object oriented. I've been hearing the FORMS are obsolete argument for a while now. SAP still hasn't re-written all the subroutines in standard objects.

I hope to keep using the subroutines till the day I get syntax errors or loss of program performance due to subroutines.