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

RE:ABAP objects

alex_georgek
Associate
Associate
0 Likes
702

Hi all,

What is the purpose for

interface........endinterface.

What do u mean by

CLASS-DATA team TYPE bikes_team.

pls explain with an example.

Thanks in advance.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
668

(a)

Interfaces are used to define only the framework of a object, but do not contain any implementation.

A local interface (one that is not saved in the dictionary but is defined in the coding) must be coded within the INTERFACE .. ENDINTERFACE tags.

The interface can be enhanced with definition in the classes that implement them. Also interfaces are used to simulate multiple inheritance, which otherwise is not possible using classes themselves.

eg:

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 IMPLEMENTATION.

METHOD lif_document~print.

ENDMETHOD.

METHOD lif_document~display.

ENDMETHOD.

METHOD display.

ENDMETHOD.

ENDCLASS.

(b)

Class data are used to define static attributes.

Static attributes exist once only for each class and are visible for all (runtime) instances in that class.

Static attributes usually contain information that is common to all instances, such as:

- Data that is the same in all instances

- Administrative information about the instances in that class (for example, counters and so on)

Static attributes are defined using the CLASS-DATA keyword.

So, when you code

CLASS-DATA team TYPE bikes_team.

You are defining a static attribute "team" which is of the local type or the dictionary type "bikes_team".

3 REPLIES 3
Read only

Former Member
0 Likes
669

(a)

Interfaces are used to define only the framework of a object, but do not contain any implementation.

A local interface (one that is not saved in the dictionary but is defined in the coding) must be coded within the INTERFACE .. ENDINTERFACE tags.

The interface can be enhanced with definition in the classes that implement them. Also interfaces are used to simulate multiple inheritance, which otherwise is not possible using classes themselves.

eg:

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 IMPLEMENTATION.

METHOD lif_document~print.

ENDMETHOD.

METHOD lif_document~display.

ENDMETHOD.

METHOD display.

ENDMETHOD.

ENDCLASS.

(b)

Class data are used to define static attributes.

Static attributes exist once only for each class and are visible for all (runtime) instances in that class.

Static attributes usually contain information that is common to all instances, such as:

- Data that is the same in all instances

- Administrative information about the instances in that class (for example, counters and so on)

Static attributes are defined using the CLASS-DATA keyword.

So, when you code

CLASS-DATA team TYPE bikes_team.

You are defining a static attribute "team" which is of the local type or the dictionary type "bikes_team".

Read only

Former Member
0 Likes
668

hi,

What is the purpose for

interface........endinterface.

Inheritance should be used to implement generalization and specialization relationships. A superclass is a

generalization of its subclasses. The subclass in turn is a specialization of its superclasses.

However, you can simulate multiple inheritance in ABAP Objects using interfaces

In ABAP Objects, interfaces are implemented in addition to and independently of classes. Interfaces

exclusively describe the external point of contact of a class, but they do not contain their own

implementation part.

Interfaces are usually defined by a user. The user describes in the interface which services (technical and

semantic) it needs in order to carry out a task. The user never actually knows the providers, but

communicates with them through the interface. In this way the user is protected from actual

implementations and can work in the same way with different classes/objects, as long as they provide the

services required (this is polymorphism using interfaces).

INTERFACE lif_document.

DATA: author TYPE REF TO lcl_author.

METHODS: print,

display.

ENDINTERFACE.

Interface only has a declaration

An interface corresponds to an abstract class that only contains abstract methods

Interfaces are implemented in classes

Interfaces do not have visibility sections

Hope this is helpful, Do reward.

Read only

Former Member
0 Likes
668

Hi, this may help you.

Classes and Interfaces

This section describes the definition of classes and interfaces and of their components. Classes and interfaces form the basis for ABAP Objects, the object-oriented part of the ABAP language. Classes and interfaces can be defined in ABAP programs of the following program types:

In a class pool, you use the Class Builder tool of the ABAP Workbench to define exactly one global class of the class library, which can then be used in all other ABAP programs. In the global declaration section of a class pool, you can individually define local data types, classes and interfaces to tbe used in the class pool and make type groups known. Apart from the TYPES and TYPE-POOLS statements, in class pools no other statements are allowed outside of classes and interfaces.

In an interface pool, you use the Class Builder tool of the ABAP Workbench to define exactly one global interface of the class library to be used in all other ABAP programs. In the global declaration section of an interface pool, you are not allowed to define local data types, classes and interfaces. You can declare type groups. Apart from the statement TYPE-POOLS, in interface pools no other statements are allowed outside of the global interfaces.

In all other ABAP programs, except type groups, you can define local classes and interfaces to be used in the program itself.

Apart from the TYPES and TYPE-POOLS statements, in class and interface pools no other statements are allowed outside of CLASS - ENDCLASS or INTERFACE - ENDINTERFACE.

class-data

class-data is used for static data variables.

=> used for accessing static data.staticdata is constant througout the program.static classes containsonly static variables.

Reward If Helpful.