SAP R/3 форум ABAP консультантов
Russian ABAP Developer's Club

Home - FAQ - Search - Memberlist - Usergroups - Profile - Log in to check your private messages - Register - Log in - English
Blogs - Weblogs News

FAQ



 
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> ABAP Objects
View previous topic :: View next topic  
Author Message
admin
Администратор
Администратор



Joined: 01 Sep 2007
Posts: 1640

PostPosted: Mon Oct 01, 2007 4:29 pm    Post subject: FAQ Reply with quote

Display CDS View - Program DEMO_SHOW_DDL_SOURCE

ABAP Language & Runtime Environment

Q. What is the difference between SAP memory and ABAP memory?
A. SAP Memory is a global memory area which all sessions within a
SAPgui have access to if they run on the same application server instance. This allows for passing data between
sessions.
The SET PARAMETER ID and GET PARAMETER ID statements are
used to manipulate the SAP Memory.

Code:
SET PARAMETER ID 'MAT' field p_matnr.
GET PARAMETER ID 'MAT' field p_matnr.


ABAP Memory is a memory area which all programs in the call stack
within the same internal session can access. The EXPORT and IMPORT
statements are used here.

Code:
export p_matnr = p_matnr to memory id 'ZTESTMAT'.
import p_matnr = p_matnr from memory id 'ZTESTMAT'.


Q. How to read table with a non-structured line type?
A. In tables with a non-structured line type, for which the whole table line is defined as a table key,
the pseudo component table_line can be specified as a component.
Code:
TYPES: GUSL_T_FIELDS LIKE DFIES-FIELDNAME OCCURS 0.
DATA: C_T_FIELDCAT TYPE  GUSL_T_FIELDS.
*...
READ TABLE c_t_fieldcat WITH KEY table_line = 'RBUKRS'
  TRANSPORTING NO FIELDS.
IF NOT sy-subrc IS INITIAL.
  APPEND 'RBUKRS' TO c_t_fieldcat.
ENDIF.


Q. What are the events used in report programs?
A.
Load-of-Program
Initialization
At Selection-Screen
At Selection-Screen on
At Selection-Screen on block
At Selection-Screen output
At Line-Selection
At User-Command
Start-of-Selection
End-of-Selection
Top-of-Page
End-of-Page
Top-of-Page during line-selection

Q. Are header lines and the OCCURS extension obsolete?
A. In regard to internal tables, header lines and the OCCURS extension are obsolete. These are actually not allowed in the OO context. The correct way to define internal tables and work areas is to use a TYPE statement to define the structure and the table type and then to use a DATA statement to define the internal table and work area.

Code:
types:
  begin of ty_Item,
    fld1 type c length 10,
    fld2 type c length 10,
  end of ty_Item,
  ty_Items type standard table of ty_Item with default key.
data: itab type ty_Items.
data: wa   like line of itab.


Q. What is the difference between OCCURS n and INITIAL SIZE n?
A. OCCURS n is obsolete in OO Context and it is advisable to use INITIAL SIZE instead. The difference between the two is that OCCURS n allocates memory to store specified number of rows in the internal table and also creates a header line, whereas INITIAL SIZE allocates memory for the specified number of rows without creating the header line.

Q. How do I define a deep structure in modern ABAP?
A.
Code:
TYPES:
  BEGIN OF ty_Message,
    count          TYPE sy-tabix,
    bdc_Messages   TYPE STANDARD TABLE OF bdcmsgcoll WITH DEFAULT KEY,
  END OF ty_Message,
  ty_Messages TYPE STANDARD TABLE OF ty_Message WITH DEFAULT KEY.
DATA:  all_Messages TYPE ty_Messages.


One thing need to be clarified is there are 3 terms are often mixed up,
1. Nested Structure,
2. Deep Structure,
3. Flat Structure.

According to official training material BC402, they are explained like following:
1. Nested Structure: Structure contains other structure as component.
2. Deep Structure: Structure contains variable length components (string / xstring), or even an internal table.
3. Flat Structure: Structure only contains fixed-length components.

Q. What is the difference between "'" and "`" in a character literal?
A. A character sequence within single quote characters (') is a char literal, while within (`) is a string literal. That get´s especially important for trailing spaces. A string literal presveres the trailing space while a char literal ignores them.

Code:
DATA v_char TYPE c LENGTH 32.
v_char = 'This is a'.
CONCATENATE v_char 'text   ' INTO v_char SEPARATED BY space.
*" v_char would be "This is a text"
CONCATENATE v_char `text   ` INTO v_char SEPARATED BY space.
*" v_char would be "This is a text   "


Q. How can I access parameters to MACROS?
A.The parameters in MACROS can be accessed by &1, &2 ...
Code:
DATA sum TYPE i.

"Macro definition
DEFINE add_macro.
sum = *&1 + &2*.
END-OF-DEFINITION.

START-OF-SELECTION.
add_macro 10 20.
WRITE sum.


ABAP Objects
Why use ABAP Object. SAP Tutorial - Ckick Here.
Eight reasons why each ABAP developer should use ABAP Object

Short Description of 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.

Class Components
The components of a class make up its contents. All components are declared in the declaration part of the class. The components define the attributes of the objects in a class. When you define the class, each component is assigned to one of the three visibility sections, which define the external interface of the class. All of the components of a class are visible within the class. All components are in the same namespace. This means that all components of the class must have names that are unique within the class.

There are two kinds of components in a class - those that exist separately for each object in the class, and those that exist only once for the whole class, regardless of the number of instances. Instance-specific components are known as instance components. Components that are not instance-specific are called static components.

In ABAP Objects, classes can define the following components. Since all components that you can declare in classes can also be declared in interfaces, the following descriptions apply equally to interfaces.

Attributes
Attributes are internal data fields within a class that can have any ABAP data type. The state of an object is determined by the contents of its attributes. One kind of attribute is the reference variable. Reference variables allow you to create and address objects. Reference variables can be defined in classes, allowing you to access objects from within a class.

Instance Attributes
The contents of instance attributes define the instance-specific state of an object. You declare them using the DATA statement.

Static Attributes
The contents of static attributes define the state of the class that is valid for all instances of the class. Static attributes exist once for each class. You declare them using the CLASS-DATA statement. They are accessible for the entire runtime of the class.

All of the objects in a class can access its static attributes. If you change a static attribute in an object, the change is visible in all other objects in the class.

Methods
Methods are internal procedures in a class that define the behavior of an object. They can access all of the attributes of a class. This allows them to change the data content of an object. They also have a parameter interface, with which users can supply them with values when calling them, and receive values back from them The private attributes of a class can only be changed by methods in the same class.

The definition and parameter interface of a method is similar to that of function modules. You define a method <met> in the definition part of a class and implement it in the implementation part using the following processing block:

METHOD <meth>.

...

ENDMETHOD.

You can declare local data types and objects in methods in the same way as in other ABAP procedures (subroutines and function modules). You call methods using the CALL METHOD statement.

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.

Special Methods
As well as normal methods, which you call using CALL METHOD, there are two special methods called CONSTRUCTOR and CLASS_CONSTRUCTOR, which are automatically called when you create an object (CONSTRUCTOR) or when you first access the components of a class (CLASS_CONSTRUCTOR).

Events
Objects or classes can use events to trigger event handler methods in other objects or classes. In a normal method call, one method can be called by any number of users. When an event is triggered, any number of event handler methods can be called. The link between the trigger and the handler is not established until runtime. In a normal method call, the calling program determines the methods that it wants to call. These methods must exist. With events, the handler determines the events to which it wants to react. There does not have to be a handler method registered for every event.

The events of a class can be triggered in the methods of the same class using the RAISE EVENT statement. You can declare a method of the same or a different class as an event handler method for the event <evt> of class <class> using the addition FOR EVENT <evt> OF <class>.

Events have a similar parameter interface to methods, but only have output parameters. These parameters are passed by the trigger (RAISE EVENT statement) to the event handler method, which receives them as input parameters.

The link between trigger and handler is established dynamically in a program using the SET HANDLER statement. The trigger and handlers can be objects or classes, depending on whether you have instance or static events and event handler methods. When an event is triggered, the corresponding event handler methods are executed in all registered handling classes.

Instance Events
You declare instance events using the EVENTS statement. An instance event can only be triggered in an instance method.

Static Events
You declare static events using the CLASS-EVENTS statement. All methods (instance and static methods) can trigger static events. Static events are the only type of event that can be triggered in a static method.

See also Triggering and Handling Events.

Types
You can define your own ABAP data types within a class using the TYPES statement. Types are not instance-specific, and exist once only for all of the objects in a class.

Constants
Constants are special static attributes. You set their values when you declare them, and they can then no longer be changed. You declare them using the CONSTANTS statement. Constants are not instance-specific, and exist once only for all of the objects in a class.

Visibility Sections
You can divide the declaration part of a class into up to three visibility areas:

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

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>-><attrbute>
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 this standard Programs.
ABAPDOCU -> ABAP Objects.
ABAP_OBJECTS_ENJOY_0 Template for Solutions of ABAP Object Enjoy Course
ABAP_OBJECTS_ENJOY_1 Model Solution 1: ABAP Objects Enjoy Course
ABAP_OBJECTS_ENJOY_2 Model Solution 2: ABAP Objects Enjoy Course
ABAP_OBJECTS_ENJOY_3 Model Solution 3: ABAP Objects Enjoy Course
ABAP_OBJECTS_ENJOY_4 Model Solution 4: ABAP Objects Enjoy Course
ABAP_OBJECTS_ENJOY_5 Model Solution 5: ABAP Objects Enjoy Course
DEMO_ABAP_OBJECTS Complete Demonstration for ABAP Objects
DEMO_ABAP_OBJECTS_CONTROLS GUI Controls on Screen
DEMO_ABAP_OBJECTS_EVENTS Demonstration of Events in ABAP

Refer these links :

1) http://help.sap.com/printdocu/core/Print46c/en/data/pdf/BCABA/BCABA.pdf -- Page no: 1291
2) http://esnips.com/doc/5c65b0dd-eddf-4512-8e32-ecd26735f0f2/prefinalppt.ppt
3) http://esnips.com/doc/2c76dc57-e74a-4539-a20e-29383317e804/OO-abap.pdf
4) http://esnips.com/doc/0ef39d4b-586a-4637-abbb-e4f69d2d9307/SAP-CONTROLS-WORKSHOP.pdf
5) http://esnips.com/doc/92be4457-1b6e-4061-92e5-8e4b3a6e3239/Object-Oriented-ABAP.ppt
6) http://esnips.com/doc/448e8302-68b1-4046-9fef-8fa8808caee0/abap-objects-by-helen.pdf
7) http://esnips.com/doc/39fdc647-1aed-4b40-a476-4d3042b6ec28/class_builder.ppt
8 ) http://www.amazon.com/gp/explorer/0201750805/2/ref=pd_lpo_ase/102-9378020-8749710?ie=UTF8

http://www.erpgenie.com/sap/abap/OO/index.htm

http://help.sap.com/saphelp_nw04/helpdata/en/ce/b518b6513611d194a50000e8353423/frameset.htm

http://www.sapgenie.com/abap/OO/

http://www.sapgenie.com/abap/controls/index.htm

check these links also :

http://help.sap.com/saphelp_47x200/helpdata/en/ce/b518b6513611d194a50000e8353423/content.htm

For funtion module to class
http://help.sap.com/saphelp_47x200/helpdata/en/c3/225b5954f411d194a60000e8353423/content.htm

for classes
http://help.sap.com/saphelp_47x200/helpdata/en/c3/225b5c54f411d194a60000e8353423/content.htm

for methods
http://help.sap.com/saphelp_47x200/helpdata/en/08/d27c03b81011d194f60000e8353423/content.htm

for inheritance
http://help.sap.com/saphelp_47x200/helpdata/en/dd/4049c40f4611d3b9380000e8353423/content.htm

for interfaces
http://help.sap.com/saphelp_47x200/helpdata/en/c3/225b6254f411d194a60000e8353423/content.htm
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> ABAP Objects All times are GMT + 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG.
SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG.
Every effort is made to ensure content integrity. Use information on this site at your own risk.