‎2008 Mar 02 12:18 PM
what is the difference between function module and classes. plz any one tel me.
‎2008 Mar 02 2:18 PM
hi venu..!
Before release of 4.0 function modules where played the key role like Classes (methods & Attributes ).
i.e, classes contains components.( like attributes,events,methods & interfaces)
while creating function module it will asks function Group name,
where we can declare global data in that function group.
that data will be accessed by the Any function module that belongs to that function group.!
(Global data is nothing but simliar to Atributes in classes )
what ever we declare in global data (function group) we cannot access it directly, to access them we use Function module .
so these function modules are the interface between the function group and the user.
we will write the logic in function module in the source code tab.
that is providing the functionality when the function module is called.
(i,e is nothing method like in classes )
The main diff. between Classes and function group is :
we cannot have more than one instance for the same function group.
But, for Classes we can create number of instances(Objects) for the same class in the same program.
Note : when we call a function module or Any number of function modules that belongs to that goup ,
that all function module uses the same global data variabe (memory same for that variable ).
for Classes when we Create an object or any number of objects ,
Each object will have its own memory. (for Attributes (eg : a = 10)
assume : two objects are Created obj1 , obj2.
i.,e when we change a value of the attribute using first object obj1.
obj1->a = 15.
the specific value changed in the first object i.e, obj1.
the value of 'a = 10 ' in obj2 will not be changed.
because it has its own memory.
Reward if useful,
Regards,
Rajesh.
‎2008 Mar 03 6:08 AM
Hi
At the center of any object-oriented model are objects, which contain attributes (data) and methods (functions). Objects should enable programmers to map a real problem and its proposed software solution on a one-to-one basis. Typical objects in a business environment are, for example, customer, Order, or Invoice. From Release 3.1 onwards, the Business Object Repository (BOR) has contained examples of such objects. The object model of ABAP Objects, the object-oriented extension of ABAP, is compatible with the object model of the BOR.
Before R/3 Release 4.0, the nearest equivalent of objects in ABAP were function modules and function groups. Suppose we have a function group for processing orders. The attributes of an order correspond to the global data of the function group, while the individual function modules represent actions that manipulate that data (methods). This means that the actual order data is encapsulated in the function group, and is never directly addressed, but instead only through the function modules. In this way, the function modules can ensure that the data is consistent.
When you run an ABAP program, the system starts a new internal session. The internal session has a memory area that contains the ABAP program and its associated data. When you call a function module, an instance of its function group plus its data, is loaded into the memory area of the internal session. An ABAP program can load several instances by calling function modules from different function groups.
The instance of a function group in the memory area of the internal session almost represents an object in the sense of object orientation. (See also the definition in the section What is Object Orientation?.. When you call a function module, the calling program uses the instance of a function group, based on its description in the Function Builder. The program cannot access the data in the function group directly, but only through the function module. The function modules and their parameters are the interface between the function group and the user.
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. Suppose a program wanted to use several independent counters, or process several orders at the same time. In this case, you would have to adapt the function group to include instance administration, for example, by using numbers to differentiate between the instances.
In practice, this is very awkward. Consequently, the data is usually stored in the calling program, and the function modules are called to work with it (structured programming). One problem is, for example, that all users of the function module must use the same data structures as the function group itself. Changing the internal data structure of a function group affects many users, and it is often difficult to predict the implications. The only way to avoid this is to rely heavily on interfaces and a technique that guarantees that the internal structures of instances will remain hidden, allowing you to change them later without causing any problems.
This requirement is met by object orientation. ABAP Objects allows you to define data and functions in classes instead of function groups. Using classes, an ABAP program can work with any number of instances (objects) based on the same template.
Instead of loading a single instance of a function group into memory implicitly when a function module is called, the ABAP program can now generate the instances of classes explicitly using the new ABAP statement CREATE OBJECT. The individual instances represent unique objects. You address these using object references. The object references allow the ABAP program to access the interfaces of the instances.
The following sections contain more information about classes, objects, interfaces, and object references in ABAP Objects.
‎2008 Mar 03 10:04 AM
Hi,
Function modules are procedures that are defined in special ABAP programs only, so-called function groups, but can be called from all ABAP programs. Function groups act as containers for function modules that logically belong together. You create function groups and function modules in the ABAP Workbench using the Function Builder.
Function modules allow you to encapsulate and reuse global functions in the SAP System. They are managed in a central function library. The SAP System contains several predefined functions modules that can be called from any ABAP program. Function modules also play an important role during updating and in interaction between different SAP systems, or between SAP systems and remote systems through remote communications.
Unlike subroutines, you do not define function modules in the source code of your program. Instead, you use the Function Builder. The actual ABAP interface definition remains hidden from the programmer. You can define the input parameters of a function module as optional. You can also assign default values to them. Function modules also support exception handling. This allows you to catch certain errors while the function module is running. You can test function modules without having to include them in a program using the Function Builder.
The Function Builder also has a release process for function modules. This ensures that incompatible changes cannot be made to any function modules that have already been released. This applies particularly to the interface. Programs that use a released function module will not cease to work if the function module is changed.
Classes:
Classes are templates for objects. Conversely, you can say that the type of an object is the same as its class. A class is an abstract description of an object. You could say that it is a set of instructions for building an object. The attributes of objects are defined by the components of the class, which describe the state and behavior of objects.
Local and Global Classes:
Classes in ABAP Objects can be declared either globally or locally. You define global classes and interfaces in the Class Builder (Transaction SE24) in the ABAP Workbench. They are stored centrally in class pools in the class library in the R/3 Repository. All of the ABAP programs in an R/3 System can access the global classes. Local classes are defined within an ABAP program. Local classes and interfaces can only be used in the program in which they are defined. When you use a class in an ABAP program, the system first searches for a local class with the specified name. If it does not find one, it then looks for a global class. Apart from the visibility question, there is no difference between using a global class and using a local class.
There is, however, a significant difference in the way that local and global classes are designed. If you are defining a local class that is only used in a single program, it is usually sufficient to define the outwardly visible components so that it fits into that program. Global classes, on the other hand, must be able to be used anywhere. This means that certain restrictions apply when you define the interface of a global class, since the system must be able to guarantee that any program using an object of a global class can recognize the data type of each interface parameter.
The following sections describe how to define local classes and interfaces in an ABAP program. For information about how to define local classes and interfaces, refer to the Class Builder section of the ABAP Workbench Tools documentation.
Defining Local Classes:
Local classes consist of ABAP source code, enclosed in the ABAP statements CLASS ... ENDCLASS. A complete class definition consists of a declaration part and, if required, an implementation part. The declaration part of a class <class> is a statement block:
CLASS <class> DEFINITION.
...
ENDCLASS.
It contains the declaration for all components (attributes, methods, events) of the class. When you define local classes, the declaration part belongs to the global program data. You should therefore place it at the beginning of the program.
If you declare methods in the declaration part of a class, you must also write an implementation part for it. This consists of a further statement block:
CLASS <class> IMPLEMENTATION.
...
ENDCLASS.
The implementation part of a class contains the implementation of all methods of the class. The implementation part of a local class is a processing block. Subsequent coding that is not itself part of a processing block is therefore not accessible.
Structure of a Class:
The following statements define the structure of a class:
A class contains components
Each component is assigned to a visibility section
Classes implement methods
The following sections describe the structure of classes in more detail.
Cheers,
vasavi.
‎2008 Mar 05 9:06 AM
Hi,
Before programming a new function or creating a new function module, you should look in the Function Builder to see whether there is an existing function module that already performs the same task.
For more information about this, refer to Finding Function Modules in the ABAP Workbench documentation. For example, you might look for function modules that process strings by entering STRING as a search criterion in the Repository Information System. This is an extract from the list of function modules found:
The title CSTR is the function group. Therefore, there is a function group SAPLCSTR that contains these function modules. If you select a function module, you can display its attributes in the Function Builder.
Important attributes:
· Documentation
The documentation describes the purpose of the function module, lists the parameters for passing data to and from the module, and the exceptions.
It tells you the input and output parameters of the function module, and which errors it handles.
· Interface parameters and exceptions
This section provides further information about the interface parameters and exceptions, and how to use the function module. For further information, refer to Displaying Information about Interface Parameters in the ABAP Workbench documentation. Function modules can have the following interface parameters:
· IMPORTparameters. These must be supplied with data when you call the function module, unless they are flagged as optional. You cannot change them in the function module.
· EXPORTparameters. These pass data from the function module back to the calling program. EXPORT parameters are always optional. You do not have to receive them in your program.
· CHANGING parameters. These must be supplied with data when you call the function module, unless they are flagged as optional. They can be changed in the function module. The changed values are then returned to the calling program.
· Tables parameters. You use these to pass internal tables. They are treated like CHANGING parameters. However, you can also pass internal tables with other parameters if you specify the parameter type appropriately.
The interface parameters can be typed. You can do so either by referring to ABAP Dictionary types or elementary ABAP types. When you call a function module, you must ensure that the actual parameter and the interface parameters are compatible.
Interface parameters are, by default, passed by value. However, they can also be passed by reference. Tables parameters can only be passed by reference. You can assign default values to optional importing and CHANGING parameters. If an optional parameter is not passed in a function module call, it either has an initial value, or is set to the default value.
Exceptions are used to handle errors that occur in function modules. The calling program checks whether any errors have occurred and then takes action accordingly.
Classes
LIKE-Zusatz
Classes are templates for objects. Conversely, you can say that the type of an object is the same as its class. A class is an abstract description of an object. You could say that it is a set of instructions for building an object. The attributes of objects are defined by the components of the class, which describe the state and behavior of objects.
Local and Global Classes
Classes in ABAP Objects can be declared either globally or locally. You define global classes and interfaces in the Class Builder (Transaction SE24) in the ABAP Workbench. They are stored centrally in class pools in the class library in the R/3 Repository. All of the ABAP programs in an R/3 System can access the global classes. Local classes are defined within an ABAP program. Local classes and interfaces can only be used in the program in which they are defined. When you use a class in an ABAP program, the system first searches for a local class with the specified name. If it does not find one, it then looks for a global class. Apart from the visibility question, there is no difference between using a global class and using a local class.
There is, however, a significant difference in the way that local and global classes are designed. If you are defining a local class that is only used in a single program, it is usually sufficient to define the outwardly visible components so that it fits into that program. Global classes, on the other hand, must be able to be used anywhere. This means that certain restrictions apply when you define the interface of a global class, since the system must be able to guarantee that any program using an object of a global class can recognize the data type of each interface parameter.
The following sections describe how to define local classes and interfaces in an ABAP program. For information about how to define local classes and interfaces, refer to the Class Builder section of the ABAP Workbench Tools documentation.
Defining Local Classes
Local classes consist of ABAP source code, enclosed in the ABAP statements CLASS ... ENDCLASS. A complete class definition consists of a declaration part and, if required, an implementation part. The declaration part of a class DEFINITION.
PUBLIC SECTION.
...
PROTECTED SECTION.
...
PRIVATE SECTION.
...
ENDCLASS.
These areas define the external visibility of the class components, that is, the interface between the class and its users. Each component of a class must be assigned to one of the visibility sections.
Public Section
All of the components declared in the public section are accessible to all users of the class, and to the methods of the class and any classes that inherit from it. The public components of the class form the interface between the class and its users.
Protected Section
All of the components declared in the protected section are accessible to all methods of the class and of classes that inherit from it. Protected components form a special interface between a class and its subclasses. Since inheritance is not active in Release 4.5B, the protected section currently has the same effect as the private section.
Private Section
Components that you declare in the private section are only visible in the methods of the same class. The private components are not part of the external interface of the class.
Encapsulation
The three visibility areas are the basis for one of the important features of object orientation - encapsulation. When you define a class, you should take great care in designing the public components, and try to declare as few public components as possible. The public components of global classes may not be changed once you have released the class.
For example, public attributes are visible externally, and form a part of the interface between an object and its users. If you want to encapsulate the state of an object fully, you cannot declare any public attributes. As well as defining the visibility of an attribute, you can also protect it from changes using the READ-ONLY addition.
with regards,
sowjanyagosala.
‎2008 Mar 08 6:46 AM
Hi,
Function Module is is a reusable piece of code that is primarily procedural oriented.
Class is also a similar reusable code, but the basic difference here, is that classes are object oriented.
YOu can search the forum with your sibject line and you can get a lot of answers.
YOu can have a look at the sample programs:
demo_function_group_counter
and
demo_class_counter
to notice the difference.
Reward Points if found helpfull..
Cheers,
Chandra Sekhar.