02-04-2008 11:39 AM
hi all,
pls tell me how i can learn quickly oops in abap.
and give me some material.
thanks and regards
vikas saini.'
02-04-2008 11:54 AM
normal ABAP is process oriented, where is OOP-ABAP is a new methodology in ABAP which uses object oriented programming.
we have C++, java, C#, etc as OOP languages.
ABAP has also implemented the OOP technology.
it uses classes, methods and interfaces instead of functiongroups and function modules.
As part of SAPs long-standing commitment to object technology, Release 4.0
of R/3 will contain object-oriented enhancements to the ABAP programming
language. SAPs object strategy is based on SAP Business Objects and now
covers modeling, programming, interfacing, and workflow. By using principles
like encapsulation, inheritance, and polymorphism, the object-oriented
extensions of ABAP will support real object-oriented development. This will
result in improvements in the areas of reusability, maintenance, and quality of
code. SAP offers an evolutionary approach toward objects which leverages
SAPs own and its customers investments in existing business processes,
functionality and data.
Refer these basics
OO ABAP
http://www.sapgenie.com/abap/OO/eg.htm
http://www.sapgenie.com/abap/OO/syntax.htm
http://www.sapgenie.com/abap/OO/index.htm
http://www.sapgenie.com/abap/OO/defn.htm
Detailed
OOPS OO ABAP
http://esnips.com/doc/5c65b0dd-eddf-4512-8e32-ecd26735f0f2/prefinalppt.ppt
http://esnips.com/doc/2c76dc57-e74a-4539-a20e-29383317e804/OO-abap.pdf
http://esnips.com/doc/0ef39d4b-586a-4637-abbb-e4f69d2d9307/SAP-CONTROLS-WORKSHOP.pdf
http://esnips.com/doc/92be4457-1b6e-4061-92e5-8e4b3a6e3239/Object-Oriented-ABAP.ppt
http://esnips.com/doc/448e8302-68b1-4046-9fef-8fa8808caee0/abap-objects-by-helen.pdf
http://esnips.com/doc/39fdc647-1aed-4b40-a476-4d3042b6ec28/class_builder.ppt
http://www.amazon.com/gp/explorer/0201750805/2/ref=pd_lpo_ase/102-9378020-8749710?ie=UTF8
http://help.sap.com/saphelp_nw04/helpdata/en/c3/225b5654f411d194a60000e8353423/content.htm
http://help.sap.com/saphelp_nw2004s/helpdata/en/c3/225b5654f411d194a60000e8353423/content.htm
Reward points if useful.
02-04-2008 12:04 PM
Hi,
http://www.sapgenie.com/abap/OO/index.htm
http://www.geocities.com/victorav15/sapr3/abap_ood.html
http://www.brabandt.de/html/abap_oo.html
Check this cool weblog:
/people/thomas.jung3/blog/2004/12/08/abap-persistent-classes-coding-without-sql
/people/thomas.jung3/blog/2004/12/08/abap-persistent-classes-coding-without-sql
http://help.sap.com/saphelp_nw04/helpdata/en/c3/225b6254f411d194a60000e8353423/frameset.htm
http://www.sapgenie.com/abap/OO/
http://www.sapgenie.com/abap/OO/index.htm
http://help.sap.com/saphelp_nw04/helpdata/en/c3/225b5654f411d194a60000e8353423/content.htm
http://www.esnips.com/doc/375fff1b-5a62-444d-8ec1-55508c308b17/prefinalppt.ppt
http://www.esnips.com/doc/2c76dc57-e74a-4539-a20e-29383317e804/OO-abap.pdf
http://www.esnips.com/doc/5c65b0dd-eddf-4512-8e32-ecd26735f0f2/prefinalppt.ppt
http://www.sapgenie.com/abap/OO/
http://www.sapgenie.com/abap/OO/index.htm
http://www.sapgenie.com/abap/controls/index.htm
http://www.esnips.com/doc/2c76dc57-e74a-4539-a20e-29383317e804/OO-abap.pdf
http://www.esnips.com/doc/0ef39d4b-586a-4637-abbb-e4f69d2d9307/SAP-CONTROLS-WORKSHOP.pdf
http://www.sapgenie.com/abap/OO/index.htm
http://help.sap.com/saphelp_erp2005/helpdata/en/ce/b518b6513611d194a50000e8353423/frameset.htm
http://www.sapgenie.com/abap/OO/
these links
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
For Materials:
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
😎 http://www.amazon.com/gp/explorer/0201750805/2/ref=pd_lpo_ase/102-9378020-8749710?ie=UTF8
1) http://www.erpgenie.com/sap/abap/OO/index.htm
2) http://help.sap.com/saphelp_nw04/helpdata/en/ce/b518b6513611d194a50000e8353423/frameset.htm
Regards,
Satish
02-04-2008 3:08 PM
hi vikas, this will guide u.
OOPs ABAP uses Classes and Interfaces which uses Methods and events.
If you have Java skills it is advantage for you.
There are Local classes as well as Global Classes.
Local classes we can work in SE38 straight away.
But mostly it is better to use the Global classes.
Global Classes or Interfaces are to be created in SE24.
SAP already given some predefined classes and Interfaces.
This OOPS concepts very useful for writing BADI's also.
So first create a class in SE 24.
Define attributes, Methods for that class.
Define parameters for that Method.
You can define event handlers also to handle the messages.
After creation in each method write the code.
Methods are similar to ABAP PERFORM -FORM statements.
After the creation of CLass and methods come to SE38 and create the program.
In the program create a object type ref to that class and with the help of that Object call the methods of that Class and display the data.
Example:
REPORT sapmz_hf_alv_grid .
Type pool for icons - used in the toolbar
TYPE-POOLS: icon.
TABLES: zsflight.
To allow the declaration of o_event_receiver before the
lcl_event_receiver class is defined, decale it as deferred in the
start of the program
CLASS lcl_event_receiver DEFINITION DEFERRED.
*----
G L O B A L I N T E R N A L T A B L E S
*----
*DATA: gi_sflight TYPE STANDARD TABLE OF sflight.
To include a traffic light and/or color a line the structure of the
table must include fields for the traffic light and/or the color
TYPES: BEGIN OF st_sflight.
INCLUDE STRUCTURE zsflight.
Field for traffic light
TYPES: traffic_light TYPE c.
Field for line color
types: line_color(4) type c.
TYPES: END OF st_sflight.
TYPES: tt_sflight TYPE STANDARD TABLE OF st_sflight.
DATA: gi_sflight TYPE tt_sflight.
*----
G L O B A L D A T A
*----
DATA: ok_code LIKE sy-ucomm,
Work area for internal table
g_wa_sflight TYPE st_sflight,
ALV control: Layout structure
gs_layout TYPE lvc_s_layo.
Declare reference variables to the ALV grid and the container
DATA:
go_grid TYPE REF TO cl_gui_alv_grid,
go_custom_container TYPE REF TO cl_gui_custom_container,
o_event_receiver TYPE REF TO lcl_event_receiver.
DATA:
Work area for screen 200
g_screen200 LIKE zsflight.
Data for storing information about selected rows in the grid
DATA:
Internal table
gi_index_rows TYPE lvc_t_row,
Information about 1 row
g_selected_row LIKE lvc_s_row.
*----
C L A S S E S
*----
CLASS lcl_event_receiver DEFINITION.
PUBLIC SECTION.
METHODS:
handle_toolbar FOR EVENT toolbar OF cl_gui_alv_grid
IMPORTING
e_object e_interactive,
handle_user_command FOR EVENT user_command OF cl_gui_alv_grid
IMPORTING e_ucomm.
ENDCLASS.
----
CLASS lcl_event_receiver IMPLEMENTATION
----
CLASS lcl_event_receiver IMPLEMENTATION.
METHOD handle_toolbar.
Event handler method for event toolbar.
CONSTANTS:
Constants for button type
c_button_normal TYPE i VALUE 0,
c_menu_and_default_button TYPE i VALUE 1,
c_menu TYPE i VALUE 2,
c_separator TYPE i VALUE 3,
c_radio_button TYPE i VALUE 4,
c_checkbox TYPE i VALUE 5,
c_menu_entry TYPE i VALUE 6.
DATA:
ls_toolbar TYPE stb_button.
Append seperator to the normal toolbar
CLEAR ls_toolbar.
MOVE c_separator TO ls_toolbar-butn_type..
APPEND ls_toolbar TO e_object->mt_toolbar.
Append a new button that to the toolbar. Use E_OBJECT of
event toolbar. E_OBJECT is of type CL_ALV_EVENT_TOOLBAR_SET.
This class has one attribute MT_TOOLBAR which is of table type
TTB_BUTTON. The structure is STB_BUTTON
CLEAR ls_toolbar.
MOVE 'CHANGE' TO ls_toolbar-function.
MOVE icon_change TO ls_toolbar-icon.
MOVE 'Change flight' TO ls_toolbar-quickinfo.
MOVE 'Change' TO ls_toolbar-text.
MOVE ' ' TO ls_toolbar-disabled.
APPEND ls_toolbar TO e_object->mt_toolbar.
ENDMETHOD.
METHOD handle_user_command.
Handle own functions defined in the toolbar
CASE e_ucomm.
WHEN 'CHANGE'.
PERFORM change_flight.
LEAVE TO SCREEN 0.
ENDCASE.
ENDMETHOD.
ENDCLASS.
*----
S T A R T - O F - S E L E C T I O N.
*----
START-OF-SELECTION.
SET SCREEN '100'.
&----
*& Module USER_COMMAND_0100 INPUT
&----
MODULE user_command_0100 INPUT.
CASE ok_code.
WHEN 'EXIT'.
LEAVE TO SCREEN 0.
ENDCASE.
ENDMODULE. " USER_COMMAND_0100 INPUT
&----
*& Module STATUS_0100 OUTPUT
&----
MODULE status_0100 OUTPUT.
DATA:
For parameter IS_VARIANT that is sued to set up options for storing
the grid layout as a variant in method set_table_for_first_display
l_layout TYPE disvariant,
Utillity field
l_lines TYPE i.
After returning from screen 200 the line that was selected before
going to screen 200, should be selected again. The table gi_index_rows
was the output table from the GET_SELECTED_ROWS method in form
CHANGE_FLIGHT
DESCRIBE TABLE gi_index_rows LINES l_lines.
IF l_lines > 0.
CALL METHOD go_grid->set_selected_rows
EXPORTING
it_index_rows = gi_index_rows.
CALL METHOD cl_gui_cfw=>flush.
REFRESH gi_index_rows.
ENDIF.
Read data and create objects
IF go_custom_container IS INITIAL.
Read data from datbase table
PERFORM get_data.
Create objects for container and ALV grid
CREATE OBJECT go_custom_container
EXPORTING container_name = 'ALV_CONTAINER'.
CREATE OBJECT go_grid
EXPORTING
i_parent = go_custom_container.
Create object for event_receiver class
and set handlers
CREATE OBJECT o_event_receiver.
SET HANDLER o_event_receiver->handle_user_command FOR go_grid.
SET HANDLER o_event_receiver->handle_toolbar FOR go_grid.
Layout (Variant) for ALV grid
l_layout-report = sy-repid. "Layout fo report
*----
Setup the grid layout using a variable of structure lvc_s_layo
*----
Set grid title
gs_layout-grid_title = 'Flights'.
Selection mode - Single row without buttons
(This is the default mode
gs_layout-sel_mode = 'B'.
Name of the exception field (Traffic light field) and the color
field + set the exception and color field of the table
gs_layout-excp_fname = 'TRAFFIC_LIGHT'.
gs_layout-info_fname = 'LINE_COLOR'.
LOOP AT gi_sflight INTO g_wa_sflight.
IF g_wa_sflight-paymentsum < 100000.
Value of traffic light field
g_wa_sflight-traffic_light = '1'.
Value of color field:
C = Color, 6=Color 1=Intesified on, 0: Inverse display off
g_wa_sflight-line_color = 'C610'.
ELSEIF g_wa_sflight-paymentsum => 100000 AND
g_wa_sflight-paymentsum < 1000000.
g_wa_sflight-traffic_light = '2'.
ELSE.
g_wa_sflight-traffic_light = '3'.
ENDIF.
MODIFY gi_sflight FROM g_wa_sflight.
ENDLOOP.
Grid setup for first display
CALL METHOD go_grid->set_table_for_first_display
EXPORTING i_structure_name = 'SFLIGHT'
is_variant = l_layout
i_save = 'A'
is_layout = gs_layout
CHANGING it_outtab = gi_sflight.
*-- End of grid setup -
Raise event toolbar to show the modified toolbar
CALL METHOD go_grid->set_toolbar_interactive.
Set focus to the grid. This is not necessary in this
example as there is only one control on the screen
CALL METHOD cl_gui_control=>set_focus EXPORTING control = go_grid.
ENDIF.
ENDMODULE. " STATUS_0100 OUTPUT
&----
*& Module USER_COMMAND_0200 INPUT
&----
MODULE user_command_0200 INPUT.
CASE ok_code.
WHEN 'EXIT200'.
LEAVE TO SCREEN 100.
WHEN'SAVE'.
PERFORM save_changes.
ENDCASE.
ENDMODULE. " USER_COMMAND_0200 INPUT
&----
*& Form get_data
&----
FORM get_data.
Read data from table SFLIGHT
SELECT *
FROM zsflight
INTO TABLE gi_sflight.
ENDFORM. " load_data_into_grid
&----
*& Form change_flight
&----
Reads the contents of the selected row in the grid, ans transfers
the data to screen 200, where it can be changed and saved.
----
FORM change_flight.
DATA:l_lines TYPE i.
REFRESH gi_index_rows.
CLEAR g_selected_row.
Read index of selected rows
CALL METHOD go_grid->get_selected_rows
IMPORTING
et_index_rows = gi_index_rows.
Check if any row are selected at all. If not
table gi_index_rows will be empty
DESCRIBE TABLE gi_index_rows LINES l_lines.
IF l_lines = 0.
CALL FUNCTION 'POPUP_TO_DISPLAY_TEXT'
EXPORTING
textline1 = 'You must choose a line'.
EXIT.
ENDIF.
Read indexes of selected rows. In this example only one
row can be selected as we are using gs_layout-sel_mode = 'B',
so it is only ncessary to read the first entry in
table gi_index_rows
LOOP AT gi_index_rows INTO g_selected_row.
IF sy-tabix = 1.
READ TABLE gi_sflight INDEX g_selected_row-index INTO g_wa_sflight.
ENDIF.
ENDLOOP.
Transfer data from the selected row to screenm 200 and show
screen 200
CLEAR g_screen200.
MOVE-CORRESPONDING g_wa_sflight TO g_screen200.
LEAVE TO SCREEN '200'.
ENDFORM. " change_flight
&----
*& Form save_changes
&----
Changes made in screen 200 are written to the datbase table
zsflight, and to the grid table gi_sflight, and the grid is
updated with method refresh_table_display to display the changes
----
FORM save_changes.
DATA: l_traffic_light TYPE c.
Update traffic light field
Update database table
MODIFY zsflight FROM g_screen200.
Update grid table , traffic light field and color field.
Note that it is necessary to use structure g_wa_sflight
for the update, as the screen structure does not have a
traffic light field
MOVE-CORRESPONDING g_screen200 TO g_wa_sflight.
IF g_wa_sflight-paymentsum < 100000.
g_wa_sflight-traffic_light = '1'.
C = Color, 6=Color 1=Intesified on, 0: Inverse display off
g_wa_sflight-line_color = 'C610'.
ELSEIF g_wa_sflight-paymentsum => 100000 AND
g_wa_sflight-paymentsum < 1000000.
g_wa_sflight-traffic_light = '2'.
clear g_wa_sflight-line_color.
ELSE.
g_wa_sflight-traffic_light = '3'.
clear g_wa_sflight-line_color.
ENDIF.
MODIFY gi_sflight INDEX g_selected_row-index FROM g_wa_sflight.
Refresh grid
CALL METHOD go_grid->refresh_table_display.
CALL METHOD cl_gui_cfw=>flush.
LEAVE TO SCREEN '100'.
ENDFORM. " save_changes
chk this blog
/people/vijaybabu.dudla/blog/2006/07/21/topofpage-in-alv-using-clguialvgrid
hope this helps.
regs,
Hema.
02-04-2008 9:49 PM
The Object-Oriented Programming Model
Based on your existing knowledge of procedural programming with ABAP, we will
explain the object-oriented approach and encourage you to use it. The main emphasis
will be on explanation. At this stage, it is important that you understand the subject
and its concepts so that we can build on this knowledge later.
For now, it would not make sense to try to argue a conclusive point for or against the
object-oriented approach. Before you can make a qualified decision, you need to
know object-oriented concepts and their advantages and disadvantages.
Moving from the Procedural to the Object-Oriented Programming Model
Object-oriented programming was developed at approximately the same time as
logical and procedural programming models, for example, the programming language
Simula 67. In the past, COBOL and the procedural programming model as expressed
in languages like C or Pascal were dominant in enterprise application development.
Before ABAP, SAP originally used a macro assembler.
Even today, many developers still have more experience with procedural programming
than object-oriented programming. Therefore, this introduction to object-oriented
programming also uses references to the procedural model in its explanations.
History of Selected Programming Languages
ABAP was created with the intention of improving reporting. It was developed
relatively independently as an in-house programming language, although it was
influenced by other programming languages like COBOL and Pascal. ABAP/4
was then extended to form ABAP Objects. Therefore, ABAP Objects unites
object-oriented and procedural elements in one programming language.
For the object-oriented part, only those object-oriented concepts that had proved
their worth for enterprise application development in other languages, such as Java,
C++, and Smalltalk, were adopted. ABAP Objects, like ABAP/4, also contains some
unique, very advantageous concepts.
Characteristics of the Procedural Programming Model
Data and functions are usually kept separate in the procedural programming model.
Global variables for a program contain data, while subroutines contain functions.
Essentially, every subprogram can access every variable. This means that the
programming model itself does not support consistent access to some related parts of
the data.
Typical Procedural ABAP Program
A typical procedural ABAP program consists of type definitions and data declarations,
which describe the structure of the data used by the program when it is executed.
Modularization units (for example, subroutines or function modules) can be
encapsulated. On the main program level, however, there is no special protection for
the data objects: any variables can be accessed by any means.
Encapsulating Data Using Function Groups
Every time a function module is called in a main program, its function group is loaded
into the internal session. The function group remains active until the main program
is finished. The main program and the function groups that were called in it are all
stored in separate memory areas. Even if their data objects have the same names,
they are not shared.
Only function modules of the function groups can be called from the main program.
In turn, the function modules can access the other components – particularly the
global data – of the function groups. In other words, it is not possible to access the
function group's global data directly from the main program.
Encapsulation also incorporates the idea that the implementation of a service can be
hidden from the system's other components, so that these cannot and do not make
assumptions about the internal status of the modularization unit. This way, the design
of these other components is not dependent on a specific implementation of the other
modularization units.
Therefore, a function group is a unit of data and functions that manages this
data. Encapsulated access to data and services – a concept of the object-oriented
programming model – can therefore be supported in the procedural part of ABAP
Objects. This meant that BAPIs could be implemented as function modules and
Business Objects could be implemented as function groups.
The ABAP Objects Object-Oriented Programming Model
The object-oriented concepts of ABAP Objects are essentially the same as those of
other modern object-oriented languages such as C++ or Java. A small number of
concepts that did not prove to be successful in these other languages were not included
in ABAP Objects. On the other hand, ABAP Objects also has helpful language
elements that C++ and Java do not offer.
Some specific features of ABAP Objects only exist because of the guaranteed upward
compatibility of older ABAP language elements.
Major differences in comparison to other object-oriented languages are in the
development environment. You can use the ABAP Workbench's entire range of
functions with ABAP Objects.
ABAP Objects as a Compatible Extension of ABAP
ABAP Objects is not a new language, but has been designed as a systematic extension
of ABAP. All of the extensions, including the old procedural parts, are upwardly
compatible.
Type checks in the object-oriented contexts of ABAP Objects are stricter than those in
the procedural contexts.
object-oriented contexts. This means that obsolete statements lead to syntax errors.
However, it is also advisable to avoid obsolete statements in the purely procedural
environment, as this creates source texts that are safer and more flexible. Nevertheless,
as the language is upwardly compatible, it is not possible to entirely prevent the use
of such statements.
For a list of obsolete language elements, refer to the ABAP keyword documentation.
Every obsolete statement is also specifically noted as forbidden in the object-oriented
context.
Client/Server Relationships Between Objects
Objects behave like client/server systems. When one object sends a message to
another object, telling it to behave in a certain way, the first object can be seen as a
client and the other as a server.
To separate requests and deliveries of services, the following must be true:
• Theclient object must adhere to the server object's protocol.
• The protocol must be clearly described so that a potential client can follow it
without any problems.
In principle, objects can perform both roles simultaneously; they can offer services to
other objects while requesting services at the same time.
In object-oriented programming, the services are distributed among the objects in
such a way as to avoid redundancies and so that each object offers exactly those
services that are within its area of responsibility. If an object needs any other services,
it requests these from other objects. This is known as the principle of delegation.
For example, the common task “data retrieval and output” should be distributed over
at least two objects: one is responsible for data retrieval and one for output. As long
as the data retrieval object does not change its protocol, its internal implementation
can be altered without any necessary changes to the output object. Alternately, the
data retrieval object could be replaced by a different object, providing that the new
object uses the same protocol. These exchanges can also take place at runtime.
Additional Concepts of the Object-Oriented Programming Model
inheritance
Inheritance defines the implementation relationships between classes. One class
(the subclass) adopts the structure and behavior of another class (superclass),
possibly also adapting or extending it.
PolymorphismPolymorphism is when instances of different classes respond differently to the
same messages.
Event controlInstead of sending messages directly to specific objects, objects can also trigger
events. Events can be triggered if it is not yet known at the time of development
if and how objects will react.
To summarize, the object-oriented programming model of ABAP Objects has the
following key characteristics:
• Objects are a direct abstraction of the real world.
• Objects are units made up of data and the functions belonging to that data.
• Processes can be implemented realistically.
The model has the following advantages:
• Improved software structure and consistency in the development process
• Reduced maintenance effort and less susceptibility to errors
• Better integration of the customer/user into the analysis, design, and maintenance
processes
• Options for extending the software are simpler and more secure
A standardized language is used in the various phases of software development
(analysis, specification, design, and implementation). Communication is much easier
when changing between phases.
In object-oriented programming, analysis and design decisions have an even greater
effect on implementation than they do in procedural programming. Therefore, you
should already structure and formally standardize the analysis and design phase. You
can use modeling languages to do this.