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

ABAP Classes Information.

Former Member
0 Likes
873

Good Afternoon,

I've never programmed using Classes (Object Oriented) in ABAP but i want to start doing so.

Right now i'm "surfing" in this huge Class Builder and i can see lots of classes... This looks promissing but the problem is that most of the descriptions of the classes are in German and i do read English, French, Spanish, Italian, but unfortunately not German (for now).

Where can i find information on how to start developing using classes, also information about the existing classes in ABAP (something like the API Documentation in JAVA, preferably in English), examples of programs developed this way or tutorials, and at last... best practices.

Every help will be most apreciated.

Best Regards,

Pedro Gaspar

1 ACCEPTED SOLUTION
5 REPLIES 5
Read only

Former Member
0 Likes
626

Pedro,

See the http://help.sap.com/saphelp_bw30b/helpdata/en/ca/c035baa6c611d1b4790000e8a52bed/frameset.htm

Also make a <i>Class Builder</i> search in SDN. I can find lots of information there.

rgds,

TM.

Read only

ashok_kumar24
Contributor
0 Likes
626

Hi,

Good,

Go Through the procedure.

******************************************

  • Definition part

******************************************

CLASS xxx DEFINITION.

*----


  • Public section

*----


PUBLIC SECTION.

TYPES:

DATA:

  • Static data

CLASS-DATA:

  • Methods

METHODS:

  • Using the constructor to initialize parameters

constructor IMPORTING xxx type yyy,

  • Method with parameters

mm1 IMPORTING iii TYPE ttt.

  • Method without parameters

mm2.

  • Static methods

CLASS-METHODS:

----


  • Protected section. Also accessable by subclasses

*----


PROTECTED SECTION.

*----


  • Private section. Not accessable by subclasses

*----


PRIVATE SECTION.

ENDCLASS.

******************************************

  • Implementation part

******************************************

CLASS lcl_airplane IMPLEMENTATION.

METHOD constructor.

ENDMETHOD.

METHOD mm1.

ENDMETHOD.

METHOD mm2.

ENDMETHOD.

ENDCLASS.

Template for calling a class

  • Create reference to class lcl_airplane

DATA: airplane1 TYPE REF TO lcl_airplane.

START-OF-SELECTION.

  • Create instance using parameters in the cosntructor method

CREATE OBJECT airplane1 exporting im_name = 'Hansemand'

im_planetype = 'Boing 747'.

  • Calling a method with parameters

CALL METHOD: airplane1->display_n_o_airplanes,

airplane1->display_attributes.

Subclass

CLASS xxx DEFINITION INHERITING FROM yyy.

Using af class as a parameter for a method

The class LCL_AIRPLANE is used as a parameter for method add_a_new_airplane:

METHODS:

add_a_new_airplane importing im_airplane TYPE REF to lcl_airplane.

Interfaces

In ABAP interfaces are implemented in addition to, and independently of classes. An interface only has a declaration part,

and do not have visibility sections. Components (Attributes, methods, constants, types) can be defined the same way as in classes.

u00B7 Interfaces are listed in the definition part lof the class, and must always be in the PUBLIC SECTION.

u00B7 Operations defined in the interface atre impemented as methods of the class. All methods of the interface

must be present in the implementation part of the class.

u00B7 Attributes, events, constants and types defined in the interface are automatically available to the class

carrying out the implementation.

u00B7 Interface components are addressed in the class by <interface name>~<component name>

Example of how to implement an interface:

INTERFACE lif_document

DATA: author type ref to lcl_author.

METHODS: print,

display.

ENDINTERFACE.

CLASS lcl_text_document DEFINITION.

PUBLIC SECTION.

INTERFACES lif_document.

METHODS display.

ENDCLASS.

CLASS lcl_text_document IMPLEMENTTION.

METHOD lif_document~print.

ENDMETHOD.

METHOD lif_document~display

ENDMETHOD.

METHOD display.

ENDMETHOD.

ENDCLASS.

REPORT zzz.

DATA: text_doc TYPE REF TO lcl_document.

Start-of-selection.

CREATE OBJECT text_doc.

CALL METHOD text_doc->lif_document~print.

CALL METHOD text_doc->lif_document~display.

CALL METHOD text_doc->display.

Events

For events of controls, refer to How to use controls.

u00B7 Events can only have EXPORTING parameters

u00B7 When an event is triggered, only those events handlers that have registered themselves

using SET HANDLER by this point of runtime are executed. You can register an event using

ACTIVATION 'X' and derigert it by using ACTIVATION 'SPACE'.

Defining events:

CLASS <classname> DEFINITION.

EVENTS: <event> EXPORTING VALUE (<ex_par>) TYPE type.

CLASS <classname> IMPLEMENTATION.

METHOD <m>:

RAISE EVENT <event> EXPORTING <ex_par> = .

Handling events:

CLASS <classname> DEFINITION.

METHODS: <on_event> FOR <event> OF <classname> ! <interface> IMPORTING <imp_par1>...<imp_parN> SENDER.

-


Public attributes

Public attributes are defined in the PUBLIC section and can be viewed and changed from outside the class. There is direct access to public attributes. As a general rule, as few public attributes should be defined as possible.

PUBLIC SECTION.

DATA: Counter type i.

Private attributes

Private attributes are defined in the PRIVATE section. The can only be viewes and changed from within the class. There is no direct access from outside the class.

PRIVATE SECTION.

DATA: name(25) TYPE c,

planetype LIKE saplane-planetyp,

Instance attributes

There exist one instance attribute for each instance of the class, thus they exist seperately for each object. Instance attributes are declared with the DATA keyword.

Static attributes

Static attributes exist only once for each class. The data are the same for all instances of the class, and can be used e.g. for instance counters. Static attributes are defined with the keyword CLASS-DATA.

PRIVATE SECTION.

CLASS-DATA: counter type i,

Public methods

Can called from outside the class

PUBLIC SECTION.

METHODS: set_attributes IMPORTING p_name(25) TYPE c,

p_planetype LIKE saplane-planetyp,

Private methods

Can only be called from inside the class. They are placed in the PRIVATE section of the class.

Constructor method

Implicitly, each class has an instance constructor method with the reserved name constructor and a static constructor method with the reserved name class_constructor.

The instance constructor is executed each time you create an object (instance) with the CREATE OBJECT statement, while the class constructor is executed exactly once before you first access a class.

The constructors are always present. However, to implement a constructor you must declare it explicitly with the METHODS or CLASS-METHODS statements. An instance constructor can have IMPORTING parameters and exceptions. You must pass all non-optional parameters when creating an object. Static constructors have no parameters.

Static constructor

The static constructor is always called CLASS_CONSTRUCTER, and is called autmatically before the clas is first accessed, that is before any of the following actions are executed:

Creating an instance using CREATE_OBJECT

Adressing a static attribute using <classname>->

Calling a ststic attribute using CALL METHOD

Registering a static event handler

Registering an evetm handler method for a static event

The static constructor cannot be called explicitly.

Protected components

When we are talking subclassing and enheritance there is one more component than Public and Private, the Protected component. Protected components can be used by the superclass and all of the subclasses. Note that Subclasses cannot access Private components.

Polymorphism

Polymorphism: When the same method is implemented differently in different classes. This can be done using enheritance, by redefining a method from the superclass in subclasses and implement it differently.

-


Check out the following sites .. You will find important information about classes

ABAP-oops

-


-https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/library/webas/abap/abap code samples/abap objects/abap code sample to learn basic concept of object-oriented programming.doc

https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/library/webas/abap/abap code samples/alv grid/abap code sample to display data in alv grid using object oriented programming.doc

http://help.sap.com/saphelp_nw04/helpdata/en/b3/f4b1406fecef0fe10000000a1550b0/content.htm

Good Luck and reward me for the same

Thanks

Ashok.N

Read only

Former Member
0 Likes
626

Hi,

U have to first go through the documentation part which u can find on link- help.sap.com and read about OOP there u will find each n every step how to create how to use n also the T-code for the Classes is SE24.

Wish u luck...

Seema

Read only

Former Member
0 Likes
626

Hi Pedro,

You can start working on OO ABAP by working on one of my uploaded documents, which explains how to code in ABAP Editor and using Class Builder.

http://esnips.com/doc/5c65b0dd-eddf-4512-8e32-ecd26735f0f2/prefinalppt.ppt

You can also go to SAPGenie.com to work on various attributes of OOP mainly inheritance, polymorphism,etc.

Its link is

http://sapgenie.com/abap/OO/index.htm

You can get useful programs in the transaction ABAPDOCU.In that go to ABAP Objects, you will get useful programs.

You can work on Control Frameworks in ABAP using OO methodology by trying out the transaction DWDM.

I will send you other links once I find it...

Award points to all helpful answers.

Regards,

SP.