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

Local Classes in Function Modules

former_member213112
Participant
7,141

Hi,

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

Thanks,

Watchpoint.

1 ACCEPTED SOLUTION
Read only

matt
Active Contributor
3,820

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
Read only

matt
Active Contributor
3,821

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.

Read only

joachimrees1
Active Contributor
0 Likes
3,820

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!

Read only

matt
Active Contributor
0 Likes
3,820

Shame it had an error should read:

  • Suffix "Pxx": Implementation of methods and classes
Read only

Sandra_Rossi
Active Contributor
0 Likes
3,820

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

Read only

matt
Active Contributor
0 Likes
3,820

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.

Read only

3,820

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.

Read only

loyd_enochs3
Participant
0 Likes
3,820

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

Read only

matt
Active Contributor
0 Likes
3,820

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.

Read only

former_member184158
Active Contributor
0 Likes
3,820

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

Read only

3,820

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.

Read only

developerone
Contributor
0 Likes
3,820

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.