‎2007 Aug 07 3:19 PM
Hi,
I want to learn OOABAP.Can anyone tell me how to create a simple method and call it in the ABAP Editor SE38.
Can you give me the steps.Points assured.
Thanks,
Shashi Devi.
‎2007 Aug 07 7:22 PM
You can create a local class within a report program in SE38.
report zrich_0001.
*---------------------------------------------------------------------*
* CLASS lcl_a DEFINITION
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
class lcl_a definition.
public section.
methods: constructor,
a_method.
endclass.
*---------------------------------------------------------------------*
* CLASS lcl_a IMPLEMENTATION
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
class lcl_a implementation.
method constructor.
write:/ 'A constructor'.
endmethod.
method a_method.
write:/ 'A method of the class lCL_A has been fired'.
endmethod.
endclass.
data: o_cla type ref to lcl_a.
start-of-selection.
create object o_cla.
call method o_cla->a_method( ).
If your class was created in class builder in SE24, then you will need to instanitate your object, meaning use th create object statement, and then call your method, like in the "START-OF-SELECTION in the above program.
Regards,
Rich Heilman
‎2007 Aug 07 4:07 PM
I have created the Method.
Now how will we be able to call it in the ABAP Editor.That is SE38???
‎2007 Aug 07 7:03 PM
Hi,
Look at this link. There is an example like you need.
<a href="https://wiki.sdn.sap.com/wiki/display/ABAP/ABAPObjectsGetting+Started">ABAP Objects Getting Started</a>
Regards.
Marcelo Ramos
‎2007 Aug 07 7:22 PM
You can create a local class within a report program in SE38.
report zrich_0001.
*---------------------------------------------------------------------*
* CLASS lcl_a DEFINITION
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
class lcl_a definition.
public section.
methods: constructor,
a_method.
endclass.
*---------------------------------------------------------------------*
* CLASS lcl_a IMPLEMENTATION
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
class lcl_a implementation.
method constructor.
write:/ 'A constructor'.
endmethod.
method a_method.
write:/ 'A method of the class lCL_A has been fired'.
endmethod.
endclass.
data: o_cla type ref to lcl_a.
start-of-selection.
create object o_cla.
call method o_cla->a_method( ).
If your class was created in class builder in SE24, then you will need to instanitate your object, meaning use th create object statement, and then call your method, like in the "START-OF-SELECTION in the above program.
Regards,
Rich Heilman
‎2007 Aug 07 8:58 PM
Rich,
I don't understand why the write statement in the 'Constructor' method produced output in the list. Unlike the 'A_method' method, it wasn't explicitly called within the Start-of-selection event.
I'm up to page 100 in the new 'ABAP OBJECTS' book and I'm quite confused by different examples I see in different places.
Thanks
Bruce
‎2007 Aug 07 10:07 PM
> Rich,
>
> I don't understand why the write statement in the
> 'Constructor' method produced output in the list.
> Unlike the 'A_method' method, it wasn't explicitly
> called within the Start-of-selection event.
The constructor method is called by the "create object" within the start-of-selection. This fires off the constructor method.
Good luck.
Brian
‎2007 Aug 08 6:47 PM
Thanks Brian. As I was drifting off to sleep last night I thought that "Constructor" must be a reserved word. I appreciate your answer. Unfortunately, since I didn't start this message, I can't award you any points.
Thanks again
Bruce
‎2007 Aug 07 11:55 PM
Hi Shashi,
buy the book <a href="http://www.sappress.com/product.cfm?account=&product=H1934">ABAP Objects</a>.
Cheers
Graham