‎2012 Apr 27 3:10 PM
I am learning OO and I tried to convert a function to method of global class.
In existing function, there is recuresive call of a sub routine defined in the function group.
Question is how can I make a recursive call of this routine inside my method.
I tried to create a local class inside my method M1 of global class A but got syntax issue.
So I created a private method in the class A and call this private method PM1 inside my method M1.
Is this the right approach? I just want this private method known to my method only, Not inside the class.
For example:
Funtion F1.
Perform form1.
Form Form1.
Loop at itab into struct.
Do something here.
perform sub1.
Do something more.
endloop.
endform.
Now I convert to
Class A definition.
public section.
method M1.
Endclass.
Class A implementation.
Method M1.
Loop at itab into struct.
call method PM1a
endloop.
Endmethod.
Method PM1a is private method inside class A.
Is there any better approach?
Thanks for your guidance.
‎2012 Apr 27 3:17 PM
Hi Valerie,
that sounds like a reasonable approach, making the subforms private methods.
Regards
Adi
‎2012 Apr 30 11:08 AM
The example you have written doesn't show any recursive calls. Recursive calls - calling the same routine internally in the called routine.
In your case Form1 calls sub1 - both are different, so not a recursive call. Just go through the design patterns available and choose the appropriate one.
You can find the best examples of design patterns here http://zevolving.com/category/abapobjects/oo-design-patterns/
‎2012 Apr 30 11:49 AM
I gues in your code you meant to
Form Form1.
Loop at itab into struct.
Do something here.
perform Form1.
Do something more.
endloop.
endform.
I think your current approach is correct which as per your example.
Method M1.
Loop at itab into struct.
call method PM1
endloop.
Endmethod.
Method PM1.
IF SOME CONDITION.
call method PM1.
ELSE.
EXIT.
ENDIF.
Endmethod.
‎2013 Feb 04 11:19 AM
Hi,
In OOP ABAP from inside a method of a class you can call other instance methods of the same class whether public or private using keyowrd ME.
ME is a self refrencing variable of a class object created automatically by runtime. i.e it contains reference of the its own object.
thus you can use it like
Class A implementation.
Method M1.
Loop at itab into struct.
ME->PM1a( ). "using self referencing variable to call method of its own object.
endloop.
EndMethod.
Method PM1a.
...
...
Endmethod.
Endclass.
Thank You.