Application Development and Automation 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: 
Read only

qustion in abap objects

Former Member
0 Likes
603

hallow

i have this simple program (i try to learn abap objects) in oo and i wont to now what is the interface... of this program?

Regards

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.

hallow

i have this simple program (i try to learn abap objects) in oo and i wont to now what is the interface... of this program?

Regards

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.

4 REPLIES 4
Read only

Former Member
0 Likes
581

HI,

see this example for interface.

REPORT ZINTERFACE.

<b>INTERFACE inter1.

DATA:inter1_num TYPE i.

METHODS:inter1_meth importing value(number1) type i.

ENDINTERFACE.</b>

<b>INTERFACE inter2.

DATA:inter2_num TYPE i.

METHODS:inter2_meth importing value(number2) type i.

ENDINTERFACE.

</b>

CLASS clas1 DEFINITION.

PUBLIC SECTION.

<b>INTERFACES:inter1,inter2.</b>

<b> ALIASES:triple FOR inter2~inter2_meth.</b>

DATA:cls_num TYPE i.

METHODS:cls_meth.

ENDCLASS.

CLASS clas1 IMPLEMENTATION.

<b> METHOD inter1~inter1_meth.

cls_num = number1 + number1.

inter1~inter1_num = cls_num + cls_num.

write:/ 'i am from first interface'.

write:/ number1,/ cls_num,/ inter1~inter1_num.

ENDMETHOD.</b>

<b> METHOD triple.

cls_num = number2 + number2 + number2.

inter2~inter2_num = cls_num + cls_num + cls_num.

write:/ 'i am from second interface(triple)'.

write:/ number2,/ cls_num,/ inter2~inter2_num.

ENDMETHOD.</b>

METHOD cls_meth.

write:/ 'i am from class'.

ENDMETHOD.

ENDCLASS.

START-OF-SELECTION.

DATA:myinput TYPE i value 20.

DATA:obj TYPE REF TO clas1.

CREATE OBJECT obj.

<b>CALL METHOD obj->inter1~inter1_meth</b>

exporting number1 = myinput.

<b>CALL METHOD obj->triple

exporting number2 = myinput.</b>

CALL METHOD obj->cls_meth.

<b>reward if helpful</b>

rgds,

bharat.

Read only

Pawan_Kesari
Active Contributor
0 Likes
581

Can you elaborate your question?

Read only

0 Likes
581

hi

lets say i wont to add interface to my program how i can do that?

regards

Read only

Former Member
0 Likes
581

Hi

There is no interface in this program.

Interface is the one which contains only abstract methods.

and those methods are implemented by the class which implements that Interface.

Here you just used the class and its methods

see the sample code

report ysubdel .

interface i1.

data : num type i .

methods : meth1.

endinterface.

class c1 definition.

public section.

methods : meth1. “ class C1’s own method

interfaces : i1.

endclass.

class c1 implementation.

method : meth1.

write:/5 'I am meth1 in c1'.

endmethod.

method i1~meth1.

write:/5 'I am meth1 from i1'.

endmethod.

endclass.

start-of-selection.

data : oref type ref to c1.

create object oref.

write:/5 oref->i1~num.

call method oref->meth1.

call method oref->i1~meth1.

<b>Reward points for useful Answers</b>

Regards

Anji