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

To define a class inside a method

Former Member
0 Likes
2,801

Hi,

Iam new to OOPS ABAP.

I had one doubt,

Can we define and implement a new class inside a method... end method (like below)

Method M1

-


-


-


Class C1 Defination.

Class C1 Implementation

Method

Endmethod

-


-


-


Endmethod

Please suggest me on this how to proceed.

Regards

Srinivas

6 REPLIES 6
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
1,388

No, ABAP Objects does not support that.

Regards,

Rich Heilman

Read only

naimesh_patel
Active Contributor
0 Likes
1,388

It is not possible.

Which requirment leads you to think to create class inside a class.?

Regards,

Naimesh Patel

Read only

Former Member
0 Likes
1,388

Hi Rich Heilman/Naimesh

The requirement is

In XI Proxy(XI proxy is related to creation of materials in SAP),there are macros defined, and my client told us to find out wheather is it possible to replace the macros with the classes and methods.

Can i define a global class and call that method inside the class.

Method M1

-


-


-


Define a global class oref

create object.

Call method oref->m2.

-


-


-


Endmethod

Can i do it in the above way.Please suggest.

Regards

Srinivas

Read only

0 Likes
1,388

Sure, you can add private methods to the class, and call these private methods within that method. Or you can create another global class, with methods, and create an object of this class inside your method, and call the appropriate methods of this other global class.

There is no way to create an "inner class" in ABAP.

Regards,

Rich Heilman

Read only

Former Member
0 Likes
1,388

Thanks for your help

Read only

0 Likes
1,388

Actually there's a third option: Inside your global class you can create as many local classes as you need. Not inside any method, but in the specific Local class Definition and Implementation sections (SE24 -> menu Goto -> Class Local-Types).

Then, somewhere in your class, you should create instances of those classes and you can call their methods.

Have in mind though, those local classes (as their name implies) are visible to your global class only. There's no external access.

Regards