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

OOP and function groups

Former Member
0 Likes
1,422

Hi all,

I got this from SAP library:

The main difference between real object orientation and function groups is that although a program can work with the instances of several function groups at the same time, it cannot work with several instances of a single function group.

Can someone give me some example in code on the above explanation?

Many thanks.

1 ACCEPTED SOLUTION
Read only

uwe_schieferstein
Active Contributor
0 Likes
1,061

Hello

You can take any standard report calling function modules of two different function groups.

When a function module of a function group is called for the first time the entire function group is loaded ("instantiated").

However, this happens only once even if the same or other fm's of the same group are called later because the function group is already loaded (for the executed report). This means that any global data of the function group can be initiated only once.

In contrast, you can instantiate a class as many times as you want within a report yet all "global" instance attributes are initiated for each separate instance and they are completely independent of each other.

Regards

Uwe

7 REPLIES 7
Read only

Former Member
0 Likes
1,061

hi

The main difference between real object orientation and function groups is that although a program can work with the instances of several function groups at the same time, it cannot work with several instances of a single function group.

Explanation:

This requirement is met by object orientation, Abap object allows you to define data and function in calss

instead of function group. using classes , an aba program can work with any number of instances(objects)

based on the same template.complex software system become easier to understand, since object-oriented strucring

provide a closer representation of reality than other programing techniquess.

in a well- designed object- oriented system, it should be possible to implement changes at class level, without

having to make alterations at other points in the system this Reduces the overall amount of maintance requried.

through polymorphism and inheritance, object-oriented programing allows you to reuse individual

components, in an object-oriented system , the amount of work involved in revising ang maintaining the system is reduced,

since many problems can be detected and corrected in the desing phase.

Regards

venu thaluri

Read only

0 Likes
1,061

Hi venu thaluri,

Thanks your reply. But what I was asking is the abap coding example?

Anyone can provide me some example to differentiate between OOP and function group?

Thanks.

Read only

0 Likes
1,061

Please go through the slides in the following link

[https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/0a33479c-0b01-0010-7485-dc8c09d6bc69]

Read only

uwe_schieferstein
Active Contributor
0 Likes
1,062

Hello

You can take any standard report calling function modules of two different function groups.

When a function module of a function group is called for the first time the entire function group is loaded ("instantiated").

However, this happens only once even if the same or other fm's of the same group are called later because the function group is already loaded (for the executed report). This means that any global data of the function group can be initiated only once.

In contrast, you can instantiate a class as many times as you want within a report yet all "global" instance attributes are initiated for each separate instance and they are completely independent of each other.

Regards

Uwe

Read only

0 Likes
1,061

Hi Uwe,

Thanks for your explanation. At least I understand abit of the difference now.

However, I do not understand what it can be initial only once. In a program, I can call the fm as many times. At the end, I still getting the same result instead of using class objects.

Sorry, I am new to this topic.

Read only

0 Likes
1,061

Hello Myahsam

Each function group has an explicit or implicit event:

LOAD-OF-PROGRAM.  " called once and only once

This event is triggered as soon as any "part" of the function group is accessed for the very first time.

This event is comparable to the CLASS_CONSTRUCTOR of classes.

I try to explain the difference between function group and classes using an example:

- Function group: has a global variable GD_TIME (of TYPE sy-uzeit)

- Class: has an instance attribute MD_TIME (of TYPE sy-uzeit)

The variables should be filled either at event LOAD-OF-PROGRAM (function group) or in the CONSTRUCTOR method (class).

Results:

When you call you function group (i.e. a function module) for the first time GD_TIME will be filled with the time when this function call happened. However, GD_TIME will never change even if you repeatedly call the same or other modules of the same function group (because you never pass LOAD-OF-PROGRAM again).

In constast, MD_TIME will be different for each instance you have created of the class.

Regards

Uwe

Read only

0 Likes
1,061

Hi,

Whenever any function module is called in any program Function Group is loaded in Memory. You can call same function module as many time as you want but Function Group will not be instantiated (i.e. loaded in memory) every time.

Here author is trying to comapre Function Group and Class Instance.

In OOP, Class Instance can be initiated as many times as you are defining an object of that class, you can work independently with one or more instance.

Regards,

Mohaiyuddin