Friday, November 5, 2010
Know the difference between Class and Function Module
0 comments Posted by e-punk at 11/05/2010 10:19:00 AMDifference between class and a function module?
Ans. Function modules are ABAP routines that are administered in a central function library. They apply across applications and are available throughout the system. You must assign function modules to a function pool that is called a function group. A function group is nothing but a container for the function modules.
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.
What is wrapper class?
A data structure or software that contains ("wraps around") other data or software, so that the contained elements can exist in the newer system. The term is often used with component software, where a wrapper is placed around a legacy routine to make it behave like an object. This is also called "encapsulation" or "wrapper encapsulation," but is not the same as "object encapsulation," a fundamental concept of object technology.
What are events in classes?
Triggering Events
To trigger an event, a class must
- Declare the event in its declaration part
- Trigger the event in one of its methods
Declaring Events
You declare events in the declaration part of a class or in an interface. To declare instance events, use the following statement:
EVENTS
To declare static events, use the following statement:
CLASS-EVENTS
Both statements have the same syntax.
When you declare an event, you can use the EXPORTING addition to specify parameters that are passed to the event handler. The parameters are always passed by value. Instance events always contain the implicit parameter SENDER, which has the type of a reference to the class or the interface in which the event is declared.
Triggering Events
An instance event in a class can be triggered by any method in the class. Static events can be triggered by any static method. To trigger an event in a method, use the following statement:
RAISE EVENT
For each formal parameter
Handling Events
Events are handled using special methods. To handle an event, a method must
- be defined as an event handler method for that event
- be registered at runtime for the event.
Difference between global and local class?
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.
Difference between static method and instance method?
Instance Methods
You declare instance methods using the METHODS statement. They can access all of the attributes of a class, and can trigger all of the events of the class.
Static Methods
You declare static methods using the CLASS-METHODS statement. They can only access static attributes and trigger static events.
What is friend class?
In object-oriented programming to allow access to "private" or "protected" data of a class in another class, the latter class is declared as a friend class.
Purpose
A friend class has full access to the private data members of a class without being a member of that class.
Example
A friend class can be declared as shown:
class A
What is static constructor and instance constructor?
Static constructor is used to initialize static data members as soon as the class is referenced first time, whereas an instance constructor is used to create an instance of that class with
Since static constructor is a class constructor, they are guaranteed to be called as soon as we refer to that class or by creating an instance of that class.
You may say, why not initialize static data members where we declare them in the code. Like this :
private static int id = 10;
private static string name = "jack";
Static data members can certainly be initialized at the time of their declaration but there are times when value of one static member may depend upon the value of another static member. In such cases we definitely need some mechanism to handle conditional initialization of static members.
What is abstract class?
A class without a instance is abstract classes. Consists of abstract methods whose implementation is to be provided by the user itself. Abstract classes are classes that contain one or more abstract methods. An abstract method is a method that is declared, but contains no implementation. Abstract classes may not be instantiated, and require subclasses to provide implementations for the abstract methods.
What is overriding polymorphism?
Method overriding, in object oriented programming, is a language feature that allows a subclass to provide a specific implementation of a method that is already provided by one of its super-classes. The implementation in the subclass overrides (replaces) the implementation in the super-class.
A subclass can give its own definition of methods which also happen to have the same signature as the method in its super-class. This means that the subclass's method has the same name and parameter list as the super-class's overridden method. Constraints on the similarity of return type vary from language to language, as some languages support covariance on return types.
Method overriding is an important feature that facilitates polymorphism in the design of object-oriented programs.
Some languages allow the programmer to prevent a method from being overridden, or disallow method overriding in certain core classes. This may or may not involve an inability to subclass from a given class.
In many cases, abstract classes are designed — i.e. classes that exist only in order to have specialized subclasses derived from them. Such abstract classes have methods that do not perform any useful operations and are meant to be overridden by specific implementations in the subclasses. Thus, the abstract super-class defines a common interface which all the subclasses inherit.
Monday, December 1, 2008
Function Module HU_STATUS_UPDATE to change HU User Status
2 comments Posted by e-punk at 12/01/2008 07:23:00 PMDATA : lv_stsma TYPE hum_stsma,
lt_status TYPE TABLE OF gty_status,
lk_status TYPE gty_status,
lv_venum TYPE venum,
lv_vhart TYPE vhart.
SELECT SINGLE venum vhart
INTO (lv_venum, lv_vhart)
FROM vekp
WHERE exidv EQ p_exidv.
CONCATENATE gc_hu lv_venum INTO gvc_object.
* Get current status information
SELECT SINGLE stat inact
INTO lk_status
FROM husstat
WHERE objnr EQ gvc_object
AND inact EQ space.
IF sy-subrc = 0.
APPEND lk_status TO lt_status.
ENDIF.
SELECT SINGLE stsma
INTO lv_stsma
FROM tvty
WHERE traty EQ lv_vhart.
CLEAR gk_uphustatus.
REFRESH gt_uphustatus.
gk_uphustatus-objnr = gvc_object.
gk_uphustatus-stat = lk_status-stat.
gk_uphustatus-inact = gc_x.
gk_uphustatus-stsma = lv_stsma.
gk_uphustatus-mod = gc_u.
APPEND gk_uphustatus TO gt_uphustatus.
CLEAR gk_uphustatus.
CALL FUNCTION 'HU_STATUS_UPDATE'
EXPORTING
it_hustatus = gt_uphustatus
it_hustobj = gt_uphustobj.
IF sy-subrc EQ 0.
SELECT SINGLE estat
FROM tj30t
INTO gv_estat_stag
WHERE stsma = lv_stsma
AND spras = gc_e
AND txt04 = gc_stag.
CLEAR gk_uphustatus.
REFRESH gt_uphustatus.
* Check if new status exists, maybe inactive
CLEAR lk_status.
SELECT SINGLE stat inact
INTO lk_status
FROM husstat
WHERE objnr EQ gvc_object
AND stat EQ gv_estat_stag.
IF sy-subrc 0.
gk_uphustatus-mod = gc_i.
ELSE.
gk_uphustatus-mod = gc_u.
ENDIF.
gk_uphustatus-objnr = gvc_object.
gk_uphustatus-stat = gv_estat_stag.
gk_uphustatus-stsma = lv_stsma.
APPEND gk_uphustatus TO gt_uphustatus.
CLEAR gk_uphustatus.
CALL FUNCTION 'HU_STATUS_UPDATE'
EXPORTING
it_hustatus = gt_uphustatus
it_hustobj = gt_uphustobj.
ENDIF.
Labels: ABAP MM, Function Modules
Wednesday, October 29, 2008
EXPORTING
retfield = 'input/output screen field'
value_org = 'S'
TABLES
value_tab = itab "it contains 2 fields that will be shown in the list box
EXCEPTIONS
parameter_error = 1
no_values_found = 2
OTHERS = 3.
IF sy-subrc <> 0.
...
ENDIF.
ENDMODULE.
EXPORTING
id = 'i/o screen field'
values = values.
values TYPE vrm_values,
value LIKE LINE OF values.
PARAMETERS: p_name(10) AS LISTBOX VISIBLE LENGTH 10.
AT SELECTION-SCREEN OUTPUT.
param = 'P_NAME'.
value-key = '1'.
value-text = 'JOHN'.
APPEND value TO values.
value-key = '2'.
value-text = 'PETER'.
APPEND value TO values.
CALL FUNCTION 'VRM_SET_VALUES'
EXPORTING id = param
values = values.
ref: http://sap.niraj.tripod.com/id38.html
Labels: Dialog Programming, Function Modules, List-box