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

OOABAP

Former Member
0 Likes
817

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.

1 ACCEPTED SOLUTION
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
798

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

7 REPLIES 7
Read only

Former Member
0 Likes
798

I have created the Method.

Now how will we be able to call it in the ABAP Editor.That is SE38???

Read only

marcelo_ramos1
SAP Mentor
SAP Mentor
0 Likes
798

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

Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
799

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

Read only

0 Likes
798

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

Read only

0 Likes
798

> 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

Read only

0 Likes
798

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

Read only

GrahamRobbo
SAP Mentor
SAP Mentor
0 Likes
798

Hi Shashi,

buy the book <a href="http://www.sappress.com/product.cfm?account=&product=H1934">ABAP Objects</a>.

Cheers

Graham