Application Development 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: 

abap objects

Former Member
0 Kudos

Hallow

i wont example of simple abap statment like select in Function module and how i do that in abap objects (the same code)and which benefit i have in using objects.

plz i wont short example not links for sap help

Regards

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hello SHNYA TAL,

I hope the below mentioned code will help u get the difference.

Suppose that our requirement is to select 10 records from MARA table.

1 ) USING FUNCTION MODULE (in this case a subroutine)

*************

DATA : gt_mara TYPE TABLE OF mara INITIAL SIZE 100.

DATA : gw_mara TYPE mara.

START-OF-SELECTION.

PERFORM select_data.

PERFORM disp_data.

FORM select_data.

SELECT * FROM mara

INTO TABLE gt_mara

UP TO 10 ROWS.

ENDFORM.

FORM disp_data .

LOOP AT gt_mara INTO gw_mara.

WRITE : gw_mara-matnr, 20 gw_mara-mtart.

ENDLOOP.

ENDFORM.

*************

2 ) USING OOPS (Objects)

***************

DATA : gt_mara TYPE TABLE OF mara INITIAL SIZE 100.

DATA : gw_mara TYPE mara.

CLASS c1 DEFINITION.

PUBLIC SECTION.

METHODS : select_data,

disp_data.

ENDCLASS. "c1 DEFINITION

CLASS c1 IMPLEMENTATION.

METHOD select_data.

SELECT * FROM mara

INTO TABLE gt_mara

UP TO 10 ROWS.

ENDMETHOD. "select_data

METHOD disp_data.

LOOP AT gt_mara INTO gw_mara.

WRITE : gw_mara-matnr, 20 gw_mara-mtart.

ENDLOOP.

ENDMETHOD. "disp_data

ENDCLASS. "c1 IMPLEMENTATION

DATA : obj TYPE REF TO c1.

START-OF-SELECTION.

CREATE OBJECT obj.

CALL METHOD obj->select_data.

CALL METHOD obj->disp_data.

*************

Please dont forget to award points if answer's found helpful.

Regards,

Sanghamitra.

7 REPLIES 7

Former Member
0 Kudos

Please refere sample report on transaction code ABAPDOCU

Former Member
0 Kudos

frinds

thankes for answer but i need simple program example

regards

Former Member
0 Kudos

Here is an example of inheritance.

REPORT zdemo_inheritance.

----


  • CLASS counter DEFINITION

----


*

----


CLASS counter DEFINITION.

PUBLIC SECTION.

METHODS: set IMPORTING value(set_value) TYPE i,

increment,

get EXPORTING value(get_value) TYPE i.

PROTECTED SECTION .

DATA count TYPE i.

ENDCLASS. "counter DEFINITION

----


  • CLASS counter IMPLEMENTATION

----


*

----


CLASS counter IMPLEMENTATION.

METHOD set.

count = set_value.

ENDMETHOD. "set

METHOD increment.

ADD 1 TO count.

ENDMETHOD. "increment

METHOD get.

get_value = count.

ENDMETHOD. "get

ENDCLASS. "counter IMPLEMENTATION

----


  • CLASS counter_ten DEFINITION

----


*

----


CLASS counter_ten DEFINITION INHERITING FROM counter.

PUBLIC SECTION.

METHODS increment REDEFINITION .

DATA count_ten.

ENDCLASS. "counter_ten DEFINITION

----


  • CLASS counter_ten IMPLEMENTATION

----


*

----


CLASS counter_ten IMPLEMENTATION.

METHOD increment.

DATA modulo TYPE i.

CALL METHOD super->increment .

WRITE / count.

modulo = count MOD 10.

IF modulo = 0.

count_ten = count_ten + 1.

WRITE count_ten.

ENDIF.

ENDMETHOD. "increment

ENDCLASS. "counter_ten IMPLEMENTATION

************************************************************************

DATA: count TYPE REF TO counter_ten,

number TYPE i.

START-OF-SELECTION.

CREATE OBJECT count TYPE counter_ten .

CALL METHOD count->set

EXPORTING

set_value = number.

DO 20 TIMES.

CALL METHOD count->increment.

ENDDO.

Former Member
0 Kudos

Hello SHNYA TAL,

I hope the below mentioned code will help u get the difference.

Suppose that our requirement is to select 10 records from MARA table.

1 ) USING FUNCTION MODULE (in this case a subroutine)

*************

DATA : gt_mara TYPE TABLE OF mara INITIAL SIZE 100.

DATA : gw_mara TYPE mara.

START-OF-SELECTION.

PERFORM select_data.

PERFORM disp_data.

FORM select_data.

SELECT * FROM mara

INTO TABLE gt_mara

UP TO 10 ROWS.

ENDFORM.

FORM disp_data .

LOOP AT gt_mara INTO gw_mara.

WRITE : gw_mara-matnr, 20 gw_mara-mtart.

ENDLOOP.

ENDFORM.

*************

2 ) USING OOPS (Objects)

***************

DATA : gt_mara TYPE TABLE OF mara INITIAL SIZE 100.

DATA : gw_mara TYPE mara.

CLASS c1 DEFINITION.

PUBLIC SECTION.

METHODS : select_data,

disp_data.

ENDCLASS. "c1 DEFINITION

CLASS c1 IMPLEMENTATION.

METHOD select_data.

SELECT * FROM mara

INTO TABLE gt_mara

UP TO 10 ROWS.

ENDMETHOD. "select_data

METHOD disp_data.

LOOP AT gt_mara INTO gw_mara.

WRITE : gw_mara-matnr, 20 gw_mara-mtart.

ENDLOOP.

ENDMETHOD. "disp_data

ENDCLASS. "c1 IMPLEMENTATION

DATA : obj TYPE REF TO c1.

START-OF-SELECTION.

CREATE OBJECT obj.

CALL METHOD obj->select_data.

CALL METHOD obj->disp_data.

*************

Please dont forget to award points if answer's found helpful.

Regards,

Sanghamitra.

Former Member
0 Kudos

The main difference between FM and abpa objects is

if u r using same fm for addition, subtractin, multiplication and so on.

if are calling the same function module at a time for all the functions(add,mult etc..)

but u want to use the same value of parameter for all the cases,suppose u have a parameter S_a in fm and u want to add 2 to that parameter and multiply 2 that parameter only.

suppose initially s_a = 2.

when u call the fm first time for addition then s_a becomes 4

then u call the same fm for multiplication it multiplies with 4 instead of 2.

with the help of abap objects we can multiply with only 2.

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) of SAP Web AS ABAP 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 instaces.

The following sections contain more information about classes, objects, interfaces, and object references in ABAP Objects.

Ref the following link for more information

http://www.geocities.com/rmtiwari/Resources/Training/BusinessWorkflow/BusinessObjects_files/frame.ht...

Message was edited by:

Anjaneyulu Gude

former_member235056
Active Contributor
0 Kudos

Hi,

The absolute guide for all abap statements:

http://www.geocities.com/rmtiwari/main.html?http://www.geocities.com/rmtiwari/Resources/Utilities/AB...

Pls reward all helpful points.

Regards,

Ameet