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: 

Examples for Reports with oops

Former Member
0 Kudos
166

Hi all,

Can any body please send me some examples for creating reports using oops, and also send me the material for oops.

Thanks in Advance

Ranjith

5 REPLIES 5

gopi_narendra
Active Contributor
0 Kudos
107

go into se80 give ur dev class as SLIS and u cansee lots of programs starting with BCALV_GRID*... this can give u a clear idea...

Former Member
0 Kudos
107

you can check the OOPS ALV grid programs BCALV_GRID*

former_member184495
Active Contributor
0 Kudos
107

hi,

go to t-code /nabapdocu

cheers,

Aditya.

Former Member
0 Kudos
107

Hi,

Iam sending you some Example Programs.

You can go thru Tcode : Abapdoc.

*&----


*& Report ZABAP_OBJ_13424

*&

*&----


*&

*&

*&----


report zabap_obj_13424.

*----


  • CLASS c1 DEFINITION

*----


*

*----


class c1 definition.

public section.

data : var type i value '3'.

methods : write_output.

endclass. "c1 DEFINITION

*----


  • CLASS c1 IMPLEMENTATION

*----


*

*----


class c1 implementation.

method write_output.

write 😕 'Hello World', var.

endmethod. "write_output

endclass. "c1 IMPLEMENTATION

data : obj1 type ref to c1,

obj2 type ref to c1.

start-of-selection.

create object obj1.

create object obj2.

call method obj1->write_output.

obj1->var = '16'.

call method obj1->write_output.

call method obj2->write_output.

obj2->var = '12'.

call method obj2->write_output.

call method obj1->write_output.

2.

&----


*& Report ZABAP_OBJ_13424_01 *

*& *

&----


*& *

*& *

&----


report zabap_obj_13424_01 .

parameters : p_vbeln like vbap-vbeln obligatory,

p_matnr like mara-matnr.

types : begin of ty_vbap,

vbeln type vbap-vbeln,

matnr type vbap-matnr,

arktx type vbap-arktx,

end of ty_vbap.

----


  • CLASS sales_order DEFINITION

----


*

----


class sales_order definition.

public section.

data : v_matnr type mara-matnr,

v_vbeln type vbap-vbeln.

events : no_data_found.

methods : constructor importing vbeln type vbap-vbeln

matnr type mara-matnr optional,

get_vbap_details,

disp_vbap_details,

Handle_no_data_found

for event no_data_found of sales_order.

data : it_vbap type standard table of ty_vbap.

endclass. "sales_order DEFINITION

----


  • CLASS sales_order IMPLEMENTATION

----


*

----


class sales_order implementation.

method get_vbap_details.

clear : it_vbap.

refresh : it_vbap.

select vbeln

matnr

arktx

from vbap

into table it_vbap

where vbeln = p_vbeln.

if sy-subrc <> 0.

raise event no_data_found.

endif.

endmethod. "get_vbap_details

method constructor.

clear : v_vbeln,

v_matnr.

v_vbeln = vbeln.

v_matnr = matnr.

endmethod. "constructor

method Handle_no_data_found.

write : / 'No Data Found for the given selection Criteria'.

endmethod.

method disp_vbap_details.

data : wx_vbap like line of it_vbap.

loop at it_vbap into wx_vbap.

write 😕 wx_vbap-vbeln,

wx_vbap-matnr,

wx_vbap-arktx.

endloop.

clear : it_vbap.

endmethod. "disp_vbap_details

endclass. "sales_order IMPLEMENTATION

data : obj type ref to sales_order.

start-of-selection.

if not p_matnr is initial.

create object obj exporting vbeln = p_vbeln

matnr = p_matnr.

else.

create object obj exporting vbeln = p_vbeln.

endif.

set handler obj->Handle_no_data_found for obj.

call method obj->get_vbap_details.

call method obj->disp_vbap_details.

3.

&----


*& Report ZABAP_OBJ_13424_01_GBL *

*& *

&----


*& *

*& *

&----


report zabap_obj_13424_01_gbl

no standard page heading.

parameters : p_vbeln like vbap-vbeln obligatory,

p_matnr like mara-matnr.

data : obj type ref to zcl_assign_13424_01,

v_flg(1) value 'N'.

start-of-selection.

perform Select_Display_VBAP.

top-of-page.

if v_flg = 'Y'.

perform Heading_for_VBAP.

endif.

&----


*& Form Select_Display_VBAP

&----


  • text

----


form Select_Display_VBAP .

if not p_matnr is initial.

create object obj exporting vbeln = p_vbeln

matnr = p_matnr.

else.

create object obj exporting vbeln = p_vbeln.

endif.

set handler obj->handle_no_data_found for obj.

call method obj->get_vbap.

call method obj->disp_vbap.

if not obj->v_vbeln is initial.

v_flg = 'Y'.

endif.

endform. " Select_Display_VBAP

&----


*& Form Heading_for_VBAP

&----


  • text

----


form Heading_for_VBAP .

write :/01 'S.O.No.',

12 'Material No.',

31 'Material Desc'.

endform. " Heading_for_VBAP

4.

&----


*& Report ZABAP_OBJ_13424_ABSTRACT_01 *

*& *

&----


*& *

*& *

&----


REPORT ZABAP_OBJ_13424_ABSTRACT_01 .

Class C1 definition ABSTRACT.

public section.

methods : M1 ABSTRACT.

Endclass.

*Class C1 implementation.

*method M1.

  • write 😕 'Iam M1 in C1'.

*endmethod.

*Endclass.

class C2 definition inheriting from C1.

Public Section.

Methods : M1 Redefinition.

Endclass.

Class C2 implementation.

method M1.

skip.

write 😕 'Iam M1 in C2'.

endmethod.

Endclass.

Data : Obj1 type ref to C2,

Obj2 type ref to C2.

Start-of-selection.

Create Object Obj1.

Create Object Obj2.

Call method : Obj1->M1,

Obj2->M1.

5.

&----


*& Report ZABAP_OBJ_13424_FINAL_01 *

*& *

&----


*& *

*& *

&----


REPORT ZABAP_OBJ_13424_FINAL_01 .

Class C1 definition.

public section.

methods : M1 FINAL.

Endclass.

Class C1 implementation.

method M1.

write 😕 'Iam M1 in C1'.

endmethod.

Endclass.

class C2 definition inheriting from C1.

Public Section.

*Methods : M1 Redefinition.

Endclass.

*Class C2 implementation.

*method M1.

  • skip.

  • write 😕 'Iam M1 in C2'.

*endmethod.

*Endclass.

Data : Obj1 type ref to C1,

Obj2 type ref to C2.

Start-of-selection.

Create Object Obj1.

Create Object Obj2.

Call method : Obj1->M1,

Obj2->M1.

6.

&----


*& Report ZABAP_OBJ_13424_INHERIT_01 *

*& *

&----


*& *

*& *

&----


REPORT ZABAP_OBJ_13424_INHERIT_01 .

Class C1 definition.

public section.

methods : M1.

Endclass.

Class C1 implementation.

method M1.

write 😕 'Iam M1 in C1'.

endmethod.

Endclass.

class C2 definition inheriting from C1.

Public Section.

Methods : M1 Redefinition.

Endclass.

Class C2 implementation.

method M1.

skip.

write 😕 'Iam M1 in C2'.

endmethod.

Endclass.

Data : Obj1 type ref to C1,

Obj2 type ref to C2.

Start-of-selection.

Create Object Obj1.

Create Object Obj2.

Call method : Obj1->M1,

Obj2->M1.

7.

&----


*& Report ZABAP_OBJ_13424_INTERFACE *

*& *

&----


*& *

*& *

&----


REPORT ZABAP_OBJ_13424_INTERFACE .

interface i1.

end===

class c1 definition.

public section.

methods: m1.

endclass.

class c1 implementation.

method m1.

write:/ "im m1 in c1'.

endmethod.

endclass.

7.

&----


*& Report ZABAP_OBJECTS1 *

*& *

&----


*& *

*& *

&----


REPORT ZABAP_OBJECTS1 .

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

  • SIMPLE EXAMPLE USING PUBLIC & PRIVATE SECTIONS

  • Class definition.

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

CLASS C1 DEFINITION.

PUBLIC SECTION.

METHODS: CONSTRUCTOR,

CAL_DATA,

DISPLAY_DATA.

DATA: A TYPE I,

B TYPE I.

PRIVATE SECTION.

DATA C TYPE I.

ENDCLASS.

start-of-selection.

DATA OBJ TYPE REF TO C1.

CREATE OBJECT OBJ.

call method obj->cal_data.

call method obj->display_data.

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

  • Class Implementation

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

CLASS C1 IMPLEMENTATION.

METHOD CONSTRUCTOR.

A = 5.

B = 10.

ENDMETHOD.

METHOD CAL_DATA.

C = A + B.

ENDMETHOD.

METHOD DISPLAY_DATA.

WRITE: /(2) C .

ENDMETHOD.

ENDCLASS.

8.

&----


*& Report ZABAP_OBJECTS2 *

*& *

&----


*& *

*& *

&----


REPORT ZABAP_OBJECTS2.

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

  • USING PARAMETERS.

  • Class definition.

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

CLASS CLA DEFINITION.

PUBLIC SECTION.

DATA: A TYPE I,

B TYPE I.

METHODS: GET_DATA IMPORTING A TYPE I

B TYPE I,

WRITE_DATA.

PRIVATE SECTION.

DATA: C TYPE I,

D TYPE I.

ENDCLASS.

start-of-selection.

PARAMETERS: X TYPE I,

Y TYPE I.

DATA OBJ TYPE REF TO CLA.

CREATE OBJECT OBJ.

call method obj->GET_data EXPORTING A = X

B = Y.

call method obj->WRITE_data.

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

  • Class Implementation

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

CLASS CLA IMPLEMENTATION.

METHOD GET_DATA.

C = A + B.

D = A - B.

ENDMETHOD.

METHOD WRITE_DATA.

WRITE: /(2) C ,

(5) D .

ENDMETHOD.

ENDCLASS.

10.

&----


*& Report ZABAP_OBJECTS3 *

&----


REPORT ZABAP_OBJECTS3.

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

  • INHERITING A CLASS

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

CLASS CLASS1 DEFINITION.

PUBLIC SECTION.

METHODS: CONSTRUCTOR,

PROCESS_DATA.

DATA: ITAB TYPE TABLE OF VBAK,

WTAB TYPE VBAK.

ENDCLASS. "CLASS1 DEFINITION

----


  • CLASS CLASS2 DEFINITION

----


*

----


CLASS CLASS2 DEFINITION INHERITING FROM CLASS1.

PUBLIC SECTION.

METHODS: PROCESS_DATA REDEFINITION.

ENDCLASS. "CLASS2 DEFINITION

START-OF-SELECTION.

DATA: OBJ2 TYPE REF TO CLASS2,

OBJ1 TYPE REF TO CLASS1.

CREATE OBJECT OBJ1.

CREATE OBJECT OBJ2.

CALL METHOD OBJ2->PROCESS_DATA.

END-OF-SELECTION.

AT USER-COMMAND.

----


  • CLASS CLASS1 IMPLEMENTATION

----


*

----


CLASS CLASS1 IMPLEMENTATION.

METHOD CONSTRUCTOR.

REFRESH ITAB.

SELECT * FROM VBAK

INTO TABLE ITAB.

  • CALL METHOD OBJ2->PROCESS_DATA.

ENDMETHOD. "GET_DATA

METHOD PROCESS_DATA.

OBJ2->ITAB = ME->ITAB.

ENDMETHOD.

ENDCLASS. "CLASS1 IMPLEMENTATION

----


  • CLASS CLASS2 IMPLEMENTATION

----


*

----


CLASS CLASS2 IMPLEMENTATION.

METHOD PROCESS_DATA.

CALL METHOD OBJ1->PROCESS_DATA.

LOOP AT OBJ2->ITAB INTO WTAB.

WRITE: /2 WTAB-VBELN.

ENDLOOP.

ENDMETHOD. "PROCESS_DATA

ENDCLASS. "CLASS2 IMPLEMENTATION

11.

&----


*& Report ZABAPOBJ_REPORT *

*& *

&----


*& *

*& *

&----


REPORT ZABAPOBJ_REPORT .

PARAMETERS : P_VBELN LIKE VBAK-VBELN OBLIGATORY.

TYPES:BEGIN OF T_VBPA,

VBELN TYPE VBELN,

PERNR TYPE VBPA-PERNR,

POSNR TYPE VBPA-POSNR,

PARVW TYPE VBPA-PARVW,

END OF T_VBPA.

DATA:IT_VBPA TYPE STANDARD TABLE OF T_VBPA.

----


  • CLASS header DEFINITION

----


*

----


CLASS HEADER DEFINITION.

PUBLIC SECTION.

EVENTS:NO_DATA.

METHODS: CONSTRUCTOR IMPORTING VBELN TYPE VBAK-VBELN ,

GET_DATA,

PROSESS_DATA,

  • display_data,

HANDLE_NODATA FOR EVENT NO_DATA OF HEADER.

TYPES : BEGIN OF T_VBAK,

VBELN TYPE VBAK-VBELN,

ERDAT TYPE DATS,

ERNAM TYPE ERNAME,

END OF T_VBAK.

DATA : V_VBELN TYPE VBAK-VBELN.

DATA:IT_VBAK TYPE STANDARD TABLE OF T_VBAK.

DATA : W_VBAK LIKE LINE OF IT_VBAK.

ENDCLASS. "header DEFINITION

----


  • CLASS header IMPLEMENTATION

----


*

----


CLASS HEADER IMPLEMENTATION.

METHOD GET_DATA.

CLEAR IT_VBAK.

SELECT VBELN ERDAT ERNAM

FROM VBAK

INTO TABLE IT_VBAK

WHERE VBELN = P_VBELN.

IF SY-SUBRC <> 0.

RAISE EVENT NO_DATA.

ENDIF.

ENDMETHOD. "get_data

METHOD CONSTRUCTOR.

CLEAR V_VBELN.

V_VBELN = VBELN.

ENDMETHOD. "constructor

METHOD HANDLE_NODATA.

WRITE : / 'No Data Found for the given contract'.

ENDMETHOD. "HANDLE_NODATA

METHOD PROSESS_DATA.

DATA : W_VBPA LIKE LINE OF IT_VBPA.

IF NOT IT_VBAK[] IS INITIAL.

SELECT VBELN PERNR POSNR PARVW

INTO TABLE IT_VBPA

FROM VBPA

FOR ALL ENTRIES IN IT_VBAK

WHERE VBELN = IT_VBAK-VBELN.

ENDIF.

IF SY-SUBRC <> 0.

RAISE EVENT NO_DATA.

ENDIF.

LOOP AT IT_VBPA INTO W_VBPA.

WRITE:/10 W_VBPA-VBELN,

W_VBPA-PERNR,

W_VBPA-POSNR,

W_VBPA-PARVW.

ENDLOOP.

ENDMETHOD. "PROSESS_DATA

ENDCLASS. "header IMPLEMENTATION

DATA:OBJ TYPE REF TO HEADER.

START-OF-SELECTION.

CREATE OBJECT OBJ EXPORTING VBELN = P_VBELN.

SET HANDLER OBJ->HANDLE_NODATA FOR OBJ.

CALL METHOD OBJ->GET_DATA.

CALL METHOD OBJ->PROSESS_DATA.

12.

&----


*& Report ZABAPOBJ1 *

*& *

&----


*& *

*& *

&----


REPORT ZABAPOBJ1.

PARAMETER: P_VBELN TYPE VBAP-VBELN,

P_MATNR TYPE VBAP-MATNR.

CLASS SALES_ORDER DEFINITION.

PUBLIC SECTION.

TYPES: BEGIN OF T_VBAP,

VBELN TYPE VBAP-VBELN,

MATNR TYPE VBAP-MATNR,

ARKTX TYPE VBAP-ARKTX,

END OF T_VBAP.

DATA: IT_VBAP TYPE STANDARD TABLE OF T_VBAP .

DATA: TAB_VBAP TYPE T_VBAP.

METHODS: CONSTRUCTOR IMPORTING V_VBELN TYPE VBAP-VBELN

V_MATNR TYPE MARA-MATNR OPTIONAL,

WRITE_SALES_ORDER_DATA.

ENDCLASS.

CLASS SALES_ORDER IMPLEMENTATION.

METHOD: CONSTRUCTOR.

IF V_VBELN IS NOT INITIAL AND V_MATNR IS NOT INITIAL.

SELECT VBELN MATNR ARKTX

FROM VBAP INTO TABLE IT_VBAP

WHERE VBELN = V_VBELN AND MATNR = V_MATNR.

ENDIF.

IF V_MATNR IS INITIAL.

SELECT VBELN MATNR ARKTX FROM VBAP INTO TABLE IT_VBAP

WHERE VBELN = V_VBELN .

ENDIF.

ENDMETHOD.

METHOD WRITE_SALES_ORDER_DATA.

WRITE:/10 'Sales Document',

30 'Material Number',

50 'Short Text for Sales Order Item'.

LOOP AT IT_VBAP INTO TAB_VBAP.

WRITE:/10 TAB_VBAP-VBELN(10),

30 TAB_VBAP-MATNR(18),

50 TAB_VBAP-ARKTX.

ENDLOOP.

ENDMETHOD.

ENDCLASS.

START-OF-SELECTION.

DATA : OBJ TYPE REF TO SALES_ORDER.

CREATE OBJECT OBJ EXPORTING V_VBELN = P_VBELN V_MATNR = P_MATNR.

CALL METHOD OBJ->WRITE_SALES_ORDER_DATA.

13.

&----


*& Report ZABAPOBJ2 *

*& *

&----


*& *

*& *

&----


REPORT ZABAPOBJ2.

parameters : p_vbeln type vbap-vbeln obligatory,

p_matnr type vbap-matnr.

data : obj type ref to ZCL_abapobj_SALES_ORDER.

start-of-selection.

if not p_matnr is initial.

create object obj exporting vbeln = p_vbeln

matnr = p_matnr.

else.

create object obj exporting vbeln = p_vbeln.

endif.

set handler obj->handle_no_data_found for obj.

call method obj->get_salesorder_details.

call method obj->display_sales_orders.

14.

&----


*& Report ZABAPOBJ3 *

*& *

&----


*& *

*& *

&----


REPORT ZABAPOBJ3.

.

parameters : p_vbeln like vbap-vbeln,

p_matnr like vbap-matnr.

class sales_order definition.

public section.

events : no_data_found.

methods : constructor importing vbeln type vbap-vbeln

matnr type mara-matnr OPTIONAL,

GET_SALES_ORDER_DATA,

write_sales_order_data,

handle_no_data_found for event no_data_found of sales_order.

types: begin of ty_vbap,

vbeln type vbap-vbeln,

matnr type vbap-matnr,

arktx type vbap-arktx,

end of ty_vbap.

data : it_vbap type standard table of ty_vbap.

data: t_vbap type ty_vbap.

data : v_vbeln type vbap-vbeln,

v_matnr type vbap-matnr.

endclass.

class sales_order implementation.

method constructor.

v_vbeln = vbeln.

if not matnr is initial.

v_matnr = matnr.

endif.

endmethod.

method get_sales_order_data.

if not v_vbeln is initial and v_matnr is not initial.

select vbeln

matnr

arktx

into table it_vbap

from vbap where vbeln = v_vbeln and matnr = v_matnr.

if sy-subrc <> 0.

raise event no_data_found.

endif.

endif.

if not v_vbeln is initial.

select vbeln

matnr

arktx

into table it_vbap

from vbap where vbeln = v_vbeln.

if sy-subrc <> 0.

raise event no_data_found.

endif.

endif.

endmethod.

method write_sales_order_data.

loop at it_vbap into t_vbap.

write : / t_vbap-vbeln,

/ t_vbap-matnr,

/ t_vbap-arktx.

endloop.

endmethod.

method handle_no_data_found.

write 😕 'NO DATA FOUND'.

endmethod.

endclass.

data: obj type ref to sales_order.

start-of-selection.

if not p_vbeln is initial.

create object obj exporting vbeln = p_vbeln

matnr = p_matnr.

else.

create object obj exporting vbeln = p_vbeln.

endif.

set handler obj->handle_no_data_found for obj.

call method obj->get_sales_order_data.

call method obj->write_sales_order_data.

15.

&----


*& Report ZABAPOBJ4 *

*& *

&----


*& *

*& *

&----


REPORT ZABAPOBJ4 .

parameters : p_le type i,

p_br type i,

p_base type i,

p_height type i,

p_radius type i.

interface i1.

methods: calculate_area,

get_parameters.

endinterface.

data : interface type ref to i1.

data : it_area type ref to i1 occurs 0.

class Rectangle definition.

public section.

interfaces: i1.

private section.

data: length type i,

breadth type i,

area type f.

endclass.

class Triangle definition.

public section.

interfaces:i1.

private section.

data: base type i,

height type i,

area type f.

endclass.

class Circle definition.

public section.

interfaces:i1.

data: radius type i,

area type f.

endclass.

class Rectangle implementation.

method i1~get_parameters.

length = p_le.

breadth = p_br.

endmethod.

method i1~calculate_area.

area = length * breadth.

write 😕 'AREA of Rectangle is ', area.

endmethod.

endclass.

class Triangle implementation.

method i1~get_parameters.

base = p_base.

height = p_height.

endmethod.

method i1~calculate_area.

area = ( base * height ) / 2.

write 😕 'AREA of Triangle is ', area.

endmethod.

endclass.

class Circle implementation.

method i1~get_parameters.

radius = p_radius.

endmethod.

method i1~calculate_area.

area = ( 22 * radius * radius ) / 7.

write 😕 'AREA of Circle is ', area.

endmethod.

endclass.

data : obj1 type ref to Rectangle,

obj2 type ref to Triangle,

obj3 type ref to Circle,

obj4 type ref to Circle.

start-of-selection.

create object obj1.

create object obj2.

create object obj3.

create object obj4.

call method obj1->i1~get_parameters.

call method obj2->i1~get_parameters.

call method obj3->i1~get_parameters.

call method obj1->i1~calculate_area.

call method obj2->i1~calculate_area.

call method obj3->i1~calculate_area.

obj4->radius = '5'.

call method obj4->i1~calculate_area.

obj3 = obj4.

call method obj3->i1~calculate_area.

write 😕 'Here after interface reference output will be excuted'.

interface = obj1.

append interface to it_area.

clear interface.

interface = obj2.

append interface to it_area.

clear interface.

interface = obj3.

append interface to it_area.

clear interface.

loop at it_area into interface.

call method interface->calculate_area.

clear interface.

endloop.

16.

ASHOK----


&----


*& Report ZASHOK_ABAPOBJ1 *

*& *

&----


*& *

*& *

&----


REPORT ZASHOK_ABAPOBJ1 .

CLASS C1 DEFINITION.

PUBLIC SECTION.

DATA: VAR1 TYPE I VALUE '5'.

METHODS :METH1.

ENDCLASS.

CLASS C1 IMPLEMENTATION.

METHOD METH1.

WRITE : ' THIS IS FIRST METHOD', VAR1.

ENDMETHOD.

ENDCLASS.

DATA : OBJ1 TYPE REF TO C1.

START-OF-SELECTION.

CREATE OBJECT OBJ1.

CALL METHOD: OBJ1->METH1.

OBJ1->VAR1 = 10.

CALL METHOD OBJ1->METH1.

2.

&----


*& Report ZASHOK_ABAPOBJ2 *

*& *

&----


*& *

*& *

&----


REPORT ZASHOK_ABAPOBJ2 .

PARAMETERS : P_VBELN LIKE VBAP-VBELN,

P_MATNR LIKE MARA-MATNR.

CLASS SALES_ORDER DEFINITION.

PUBLIC SECTION.

TYPES : BEGIN OF TYPE_VBAP ,

VBELN TYPE VBAP-VBELN,

MATNR TYPE MARA-MATNR,

ARKTX TYPE VBAP-ARKTX,

END OF TYPE_VBAP.

DATA: IT_VBAP TYPE STANDARD TABLE OF TYPE_VBAP,

TYPE_VBAP1 TYPE TYPE_VBAP.

METHODS: CONSTRUCTOR IMPORTING VBELN TYPE VBAP-VBELN

MATNR TYPE MARA-MATNR OPTIONAL,

DISPDATA.

PRIVATE SECTION.

*CLASS-DATA: V_VBELN TYPE VBAP-VBELN,

  • V_MATNR TYPE MARA-MATNR.

ENDCLASS .

CLASS SALES_ORDER IMPLEMENTATION.

METHOD CONSTRUCTOR.

IF NOT VBELN IS INITIAL AND

NOT MATNR IS INITIAL.

SELECT VBELN

MATNR

ARKTX

FROM VBAP

INTO TABLE IT_VBAP

WHERE VBELN = VBELN AND

MATNR = MATNR.

ELSE.

SELECT VBELN

MATNR

ARKTX

FROM VBAP

INTO TABLE IT_VBAP

WHERE VBELN = VBELN.

ENDIF.

ENDMETHOD.

METHOD DISPDATA.

LOOP AT IT_VBAP INTO TYPE_VBAP1.

WRITE 😕 'VBELN' , TYPE_VBAP1-VBELN,

/ 'MATNR' , TYPE_VBAP1-MATNR,

/ 'ARKTX' , TYPE_VBAP1-ARKTX.

ENDLOOP.

ENDMETHOD.

ENDCLASS.

START-OF-SELECTION.

DATA : OBJ1 TYPE REF TO SALES_ORDER.

CREATE OBJECT OBJ1 EXPORTING VBELN = P_VBELN MATNR = P_MATNR.

CALL METHOD OBJ1->DISPDATA.

3&----


*& Report ZASHOK_ABAPOBJ3 *

*& *

&----


*& *

*& *

&----


REPORT ZASHOK_ABAPOBJ3 .

PARAMETERS : P_VBELN LIKE VBAP-VBELN,

P_MATNR LIKE MARA-MATNR.

CLASS SALES_ORDER DEFINITION.

PUBLIC SECTION.

TYPES : BEGIN OF TYPE_VBAP ,

VBELN TYPE VBAP-VBELN,

MATNR TYPE MARA-MATNR,

ARKTX TYPE VBAP-ARKTX,

END OF TYPE_VBAP.

DATA: IT_VBAP TYPE STANDARD TABLE OF TYPE_VBAP,

TYPE_VBAP1 TYPE TYPE_VBAP.

EVENTS : EVENT1.

METHODS: CONSTRUCTOR IMPORTING VBELN TYPE VBAP-VBELN

MATNR TYPE MARA-MATNR OPTIONAL,

DISPDATA,

EVENT_HANDLER FOR EVENT EVENT1 OF SALES_ORDER.

PRIVATE SECTION.

*CLASS-DATA: V_VBELN TYPE VBAP-VBELN,

  • V_MATNR TYPE MARA-MATNR.

ENDCLASS .

CLASS SALES_ORDER IMPLEMENTATION.

METHOD CONSTRUCTOR.

IF NOT VBELN IS INITIAL AND

NOT MATNR IS INITIAL.

SELECT VBELN

MATNR

ARKTX

FROM VBAP

INTO TABLE IT_VBAP

WHERE VBELN = VBELN AND

MATNR = MATNR.

ELSE.

SELECT VBELN

MATNR

ARKTX

FROM VBAP

INTO TABLE IT_VBAP

WHERE VBELN = VBELN.

ENDIF.

ENDMETHOD.

METHOD DISPDATA.

RAISE EVENT EVENT1.

*LOOP AT IT_VBAP INTO TYPE_VBAP1.

*WRITE 😕 'VBELN' , TYPE_VBAP1-VBELN,

  • / 'MATNR' , TYPE_VBAP1-MATNR,

  • / 'ARKTX' , TYPE_VBAP1-ARKTX.

*ENDLOOP.

ENDMETHOD.

METHOD EVENT_HANDLER.

LOOP AT IT_VBAP INTO TYPE_VBAP1.

WRITE 😕 'VBELN' , TYPE_VBAP1-VBELN,

/ 'MATNR' , TYPE_VBAP1-MATNR,

/ 'ARKTX' , TYPE_VBAP1-ARKTX.

ENDLOOP.

ENDMETHOD.

ENDCLASS.

START-OF-SELECTION.

DATA : OBJ1 TYPE REF TO SALES_ORDER,

OBJ2 TYPE REF TO SALES_ORDER.

CREATE OBJECT OBJ1 EXPORTING VBELN = P_VBELN MATNR = P_MATNR.

CREATE OBJECT OBJ2 EXPORTING VBELN = P_VBELN.

SET HANDLER OBJ2->EVENT_HANDLER FOR : OBJ1, OBJ2.

*SET HANDLER OBJ1->EVENT_HANDLER FOR ALL INSTANCES.

CALL METHOD OBJ1->DISPDATA.

CALL METHOD OBJ2->DISPDATA.

4.

&----


*& Report ZASHOK_ABAPOBJ4 *

*& *

&----


*& *

*& *

&----


REPORT ZASHOK_ABAPOBJ4 .

PARAMETERS : P_VBELN LIKE VBAP-VBELN,

P_MATNR LIKE MARA-MATNR.

START-OF-SELECTION.

DATA : OBJ1 TYPE REF TO ZASHOK_ABAPOBJ3.

CREATE OBJECT OBJ1 EXPORTING VBELN = P_VBELN MATNR = P_MATNR.

SET HANDLER OBJ1->EVENT_HANDLER FOR OBJ1.

CALL METHOD OBJ1->DISPDATA.

5.

&----


*& Report ZASHOK_ABAPOBJ5 *

*& *

&----


*& *

*& *

&----


REPORT ZASHOK_ABAPOBJ5 .

CLASS C1 DEFINITION.

PUBLIC SECTION.

*DATA:.

METHODS : METHOD1.

EVENTS : EVENT1.

ENDCLASS.

CLASS C2 DEFINITION.

PUBLIC SECTION.

*DATA:.

METHODS : HANDLER_METHOD FOR EVENT EVENT1 OF C1.

ENDCLASS.

CLASS C1 IMPLEMENTATION.

METHOD METHOD1.

WRITE : 'THIS IS METHOD OF C1 USED FOR TRIGGERING'.

RAISE EVENT EVENT1.

ENDMETHOD.

ENDCLASS.

CLASS C2 IMPLEMENTATION.

METHOD HANDLER_METHOD.

WRITE : /' THIS IS METHOD OF C2 USED FOR HANDLING'.

ENDMETHOD.

ENDCLASS.

START-OF-SELECTION.

DATA : OBJ1 TYPE REF TO C1,

OBJ2 TYPE REF TO C2.

CREATE OBJECT OBJ1.

CREATE OBJECT OBJ2.

SET HANDLER OBJ2->HANDLER_METHOD FOR OBJ1.

CALL METHOD OBJ1->METHOD1.

6.

&----


*& Report ZASHOK_ABAPOBJ6 *

*& *

&----


*& *

*& *

&----


REPORT ZASHOK_ABAPOBJ6 .

CLASS C1 DEFINITION.

PUBLIC SECTION.

*DATA:.

EVENTS : EVENT1.

METHODS : METHOD1,

HANDLER_METHOD1 FOR EVENT EVENT1 OF C1,

HANDLER_METHOD2 FOR EVENT EVENT1 OF C1.

ENDCLASS.

CLASS C2 DEFINITION.

PUBLIC SECTION.

*DATA:.

METHODS : HANDLER_METHOD2 FOR EVENT EVENT1 OF C1.

ENDCLASS.

CLASS C1 IMPLEMENTATION.

METHOD METHOD1.

WRITE : /'THIS IS METHOD OF C1 USED FOR TRIGGERING'.

RAISE EVENT EVENT1.

ENDMETHOD.

METHOD HANDLER_METHOD1.

WRITE : /' THIS IS METHOD1 OF C1 USED FOR HANDLING'.

ENDMETHOD.

METHOD HANDLER_METHOD2.

WRITE : /' THIS IS METHOD2 OF C1 USED FOR HANDLING'.

ENDMETHOD.

ENDCLASS.

CLASS C2 IMPLEMENTATION.

METHOD HANDLER_METHOD2.

WRITE : /' THIS IS METHOD2 OF C2 USED FOR HANDLING'.

ENDMETHOD.

ENDCLASS.

START-OF-SELECTION.

DATA : OBJ1 TYPE REF TO C1,

OBJ2 TYPE REF TO C2,

OBJ3 TYPE REF TO C1.

CREATE OBJECT OBJ1.

CREATE OBJECT OBJ2.

CREATE OBJECT OBJ3.

SET HANDLER OBJ1->HANDLER_METHOD1 FOR :OBJ1 .

CALL METHOD OBJ1->METHOD1.

SET HANDLER OBJ1->HANDLER_METHOD1 FOR OBJ1 ACTIVATION SPACE.

SET HANDLER OBJ2->HANDLER_METHOD2 FOR OBJ3.

CALL METHOD OBJ3->METHOD1.

*CALL METHOD OBJ1->METHOD1.

7.

&----


*& Report ZASHOK_ABAPOBJ7 *

*& *

&----


*& *

*& *

&----


REPORT ZASHOK_ABAPOBJ7 .

PARAMETERS : PAR1 TYPE I,

PAR2 TYPE I.

----


  • CLASS c1 DEFINITION

----


*

----


CLASS C1 DEFINITION.

PUBLIC SECTION.

EVENTS : E1 EXPORTING VALUE(NUM1) TYPE I

VALUE(NUM2) TYPE I.

METHODS : M1 FOR EVENT E1 OF C1

IMPORTING NUM1

NUM2

.

METHODS : T1 IMPORTING NUM3 TYPE I

NUM4 TYPE I.

ENDCLASS. "c1 DEFINITION

----


  • CLASS C1 IMPLEMENTATION

----


*

----


CLASS C1 IMPLEMENTATION.

METHOD : M1.

WRITE:/5 'First input ' , NUM1 .

WRITE:/5 'Second input ' , NUM2 .

ENDMETHOD. ":

METHOD T1.

RAISE EVENT E1 EXPORTING NUM1 = NUM3

NUM2 = NUM4.

ENDMETHOD. "T1

ENDCLASS. "C1 IMPLEMENTATION

START-OF-SELECTION.

DATA : OREF TYPE REF TO C1.

CREATE OBJECT OREF.

SET HANDLER OREF->M1 FOR OREF.

CALL METHOD OREF->T1 EXPORTING NUM3 = PAR1 NUM4 = PAR2.

8.

&----


*& Report ZASHOK_ABAPOBJ8 *

*& *

&----


*& *

*& *

&----


REPORT ZASHOK_ABAPOBJ8 .

PARAMETERS : P_VBELN LIKE VBAP-VBELN,

P_MATNR LIKE MARA-MATNR.

DATA : OBJ1 TYPE REF TO ZASHOK_ABAPOBJ3.

START-OF-SELECTION.

CREATE OBJECT OBJ1 EXPORTING VBELN = P_VBELN MATNR = P_MATNR.

SET HANDLER OBJ1->EVENT_HANDLER FOR OBJ1.

CALL METHOD OBJ1->DISPDATA.

9.

&----


*& Report ZASHOK_ABAPOBJ9 *

*& *

&----


*& *

*& *

&----


REPORT ZASHOK_ABAPOBJ9 .

CLASS C1 DEFINITION.

PUBLIC SECTION.

DATA: NUM1 TYPE I.

METHODS : METHOD1.

PROTECTED SECTION.

DATA : NUM1_PRO TYPE I.

*METHODS : METHOD1_PRO.

ENDCLASS.

CLASS C2 DEFINITION INHERITING FROM C1.

PUBLIC SECTION.

DATA:NUM2 TYPE I.

METHODS : METHOD2 .

PROTECTED SECTION.

DATA : NUM2_PRO TYPE I.

*METHODS : METHOD2_PRO.

ENDCLASS.

CLASS C3 DEFINITION INHERITING FROM C2.

PUBLIC SECTION.

DATA:NUM3 TYPE I.

METHODS : METHOD3 .

PROTECTED SECTION.

DATA : NUM3_PRO TYPE I.

*METHODS : METHOD3_PRO.

ENDCLASS.

CLASS C1 IMPLEMENTATION.

METHOD METHOD1.

NUM1 = 10.

WRITE : /'NUM1=', NUM1.

NUM1_PRO = 20.

WRITE : /'NUM1_PRO=', NUM1_PRO.

ENDMETHOD.

ENDCLASS.

CLASS C2 IMPLEMENTATION.

METHOD METHOD2.

WRITE :/' WE ARE IN METHOD 2'.

NUM2 = 30.

WRITE : /'NUM2=', NUM2.

NUM2_PRO = 40.

WRITE : /'NUM2_PRO=', NUM2_PRO.

WRITE : /'BEFORE CHANGE NUM1=', NUM1.

WRITE : /'BEFORE CHANGE NUM1_PRO=', NUM1_PRO.

NUM1 = 15.

WRITE : /'AFTER CHANGE NUM1=', NUM1.

NUM1_PRO = 25.

WRITE : /'AFTER CHANGE NUM1_PRO=', NUM1_PRO.

ENDMETHOD.

ENDCLASS.

CLASS C3 IMPLEMENTATION.

METHOD METHOD3.

WRITE :/' WE ARE IN METHOD 3'.

NUM3 = 60.

WRITE : /' NUM3=', NUM3.

NUM3_PRO = 70.

WRITE : /' NUM3_PRO=', NUM3_PRO.

WRITE : /'BEFORE CHANGE NUM2=', NUM2.

WRITE : /'BEFORE CHANGE NUM2_PRO=', NUM2_PRO.

NUM2 = 50.

WRITE : /'AFTER CHANGE IN METHOD3 NUM2=', NUM2.

NUM2_PRO = 55.

WRITE : /'AFTER CHANGE IN METHOD3 NUM2_PRO=', NUM2_PRO.

*NUM1 = 80. // IT DONE USING OBJECT OF C3

WRITE : /'AFTER CHANGE IN USING C3 OBJECT NUM1=', NUM1.

NUM1_PRO = 85.

WRITE : /'AFTER CHANGE IN METHOD3 NUM1_PRO=', NUM1_PRO.

ENDMETHOD.

ENDCLASS.

START-OF-SELECTION.

DATA : OBJ1 TYPE REF TO C1,

OBJ2 TYPE REF TO C2,

OBJ3 TYPE REF TO C3.

CREATE OBJECT OBJ1.

CREATE OBJECT OBJ2.

CREATE OBJECT OBJ3.

CALL METHOD OBJ1->METHOD1.

CALL METHOD OBJ2->METHOD2.

OBJ3->NUM1 = 80.

*OBJ3->NUM1_PRO = 85. // IT GIVES ERROR

CALL METHOD OBJ3->METHOD3.

10.

&----


*& Report ZASHOK_ABAPOBJ10 *

*& *

&----


*& *

*& *

&----


REPORT ZASHOK_ABAPOBJ10 .

----


  • INTERFACE i1

----


*

----


INTERFACE I1 .

DATA : NUM1 TYPE I ,

NUM2 TYPE I .

ENDINTERFACE. "i1

----


  • CLASS c1 DEFINITION

----


*

----


CLASS C1 DEFINITION.

PUBLIC SECTION.

INTERFACES : I1 DATA VALUES NUM1 = 5 NUM2 = 6 .

METHODS M1.

ENDCLASS. "c1 DEFINITION

----


  • CLASS c1 IMPLEMENTATION

----


*

----


CLASS C1 IMPLEMENTATION.

METHOD M1.

WRITE:/5 'num1=', I1~NUM1,

'num2=',I1~NUM2.

ENDMETHOD. "m1

ENDCLASS. "c1 IMPLEMENTATION

START-OF-SELECTION.

DATA : OREF TYPE REF TO C1.

CREATE OBJECT OREF.

CALL METHOD OREF->M1.

11.

&----


*& Report ZASHOK_ABAPOBJ11 *

*& *

&----


*& *

*& *

&----


REPORT ZASHOK_ABAPOBJ11 .

INTERFACE I1.

METHODS : METHOD1,

METHOD2.

ENDINTERFACE.

CLASS C1 DEFINITION ABSTRACT.

PUBLIC SECTION.

DATA: NUM1 TYPE I.

METHODS : C1_METHOD1.

INTERFACES : I1 FINAL METHODS METHOD1

ABSTRACT METHODS METHOD2.

ENDCLASS.

CLASS C1 IMPLEMENTATION.

METHOD C1_METHOD1.

WRITE : /'WE ARE IN METHOD1 OF C1'.

ENDMETHOD.

METHOD I1~METHOD1.

NUM1 = 10.

WRITE 😕 'WE ARE IN FINAL METHOD ' .

ENDMETHOD.

ENDCLASS.

CLASS C2 DEFINITION INHERITING FROM C1.

PUBLIC SECTION.

METHODS I1~METHOD2 REDEFINITION.

ENDCLASS.

CLASS C2 IMPLEMENTATION.

METHOD I1~METHOD2.

WRITE :/' WE ARE IN ABSTARCT METHOD2'.

ENDMETHOD.

ENDCLASS.

START-OF-SELECTION.

DATA : OBJ TYPE REF TO C2.

CREATE OBJECT OBJ.

CALL METHOD OBJ->C1_METHOD1.

CALL METHOD OBJ->I1~METHOD1.

CALL METHOD OBJ->I1~METHOD2.

12.

&----


*& Report ZASHOK_ABAPOBJ12 *

*& *

&----


*& *

*& *

&----


REPORT ZASHOK_ABAPOBJ12 .

----


  • INTERFACE i1

----


*

----


INTERFACE I1 .

CONSTANTS : C_NAME(4) TYPE C VALUE 'ABAP'.

DATA : INUM TYPE I .

CLASS-DATA : CNUM TYPE I .

METHODS : M1 .

CLASS-METHODS : M2.

ENDINTERFACE. "i1

----


  • CLASS c1 DEFINITION

----


*

----


CLASS C1 DEFINITION .

PUBLIC SECTION.

INTERFACES : I1 DATA VALUES INUM = 5 CNUM = 6 .

ENDCLASS. "c1 DEFINITION

----


  • CLASS c1 IMPLEMENTATION

----


*

----


CLASS C1 IMPLEMENTATION.

METHOD I1~M1.

WRITE:/5 'I am m1 in c1'.

ENDMETHOD. "i1~m1

METHOD I1~M2.

WRITE:/5 'I am class method m2 in c1'.

ENDMETHOD. "i1~m2

ENDCLASS. "c1 IMPLEMENTATION

START-OF-SELECTION.

DATA : IREF TYPE REF TO I1 ,

OREF TYPE REF TO C1 .

CREATE OBJECT : OREF.

WRITE:/5 OREF->I1~INUM ,

OREF->I1~CNUM ,

C1=>I1~CNUM .

CALL METHOD : OREF->I1~M1 ,

OREF->I1~M2 ,

C1=>I1~M2 .

WRITE:/5 SY-ULINE .

IREF = OREF .

WRITE:/5 IREF->INUM ,

IREF->CNUM ,

I1=>C_NAME .

CALL METHOD : IREF->M1 ,

IREF->M2 .

13.

&----


*& Report ZASHOK_ABAPOBJ13 *

*& *

&----


*& *

*& *

&----


REPORT ZASHOK_ABAPOBJ13 .

INTERFACE I1 .

METHODS : AREA IMPORTING PAR1 TYPE I

PAR2 TYPE I OPTIONAL

PAR3 TYPE I OPTIONAL.

ENDINTERFACE. "i1

----


  • CLASS c1 DEFINITION

----


*

----


CLASS C1 DEFINITION .

PUBLIC SECTION.

INTERFACES : I1 .

ENDCLASS. "c1 DEFINITION

----


  • CLASS c2 DEFINITION

----


*

----


CLASS C2 DEFINITION .

PUBLIC SECTION.

INTERFACES : I1 .

ENDCLASS. "c2 DEFINITION

----


  • CLASS c3 DEFINITION

----


*

----


CLASS C3 DEFINITION .

PUBLIC SECTION.

INTERFACES : I1 .

ENDCLASS. "c3 DEFINITION

----


  • CLASS c1 IMPLEMENTATION

----


*

----


CLASS C1 IMPLEMENTATION.

METHOD I1~AREA.

DATA : AREA TYPE I.

AREA = ( 22 / 7 ) * PAR1 * PAR1.

WRITE:/5 'AREA OF CIRCLE IS ', AREA.

ENDMETHOD. "i1~m1

ENDCLASS. "c1 IMPLEMENTATION

----


  • CLASS c2 IMPLEMENTATION

----


*

----


CLASS C2 IMPLEMENTATION.

METHOD I1~AREA.

DATA : AREA TYPE I.

AREA = PAR1 * PAR1 .

WRITE:/5 'AREA OF SQUARE IS ', AREA.

ENDMETHOD. "i1~m1

ENDCLASS. "c2 IMPLEMENTATION

----


  • CLASS c3 IMPLEMENTATION

----


*

----


CLASS C3 IMPLEMENTATION.

METHOD I1~AREA.

DATA : AREA TYPE I.

AREA = PAR1 * PAR2 .

WRITE:/5 'AREA OF RECTANGLE IS ', AREA.

ENDMETHOD. "i1~m1

ENDCLASS. "c3 IMPLEMENTATION

START-OF-SELECTION.

DATA : OREF1 TYPE REF TO C1 ,

OREF2 TYPE REF TO C2 ,

OREF3 TYPE REF TO C3.

CREATE OBJECT : OREF1 , OREF2 , OREF3.

CALL METHOD : OREF1->I1~AREA EXPORTING PAR1 = 10,

OREF2->I1~AREA EXPORTING PAR1 = 5,

OREF3->I1~AREA EXPORTING PAR1 = 10 PAR2 = 15.

14.

&----


*& Report ZASHOK_ABAPOBJ14 *

*& *

&----


*& *

*& *

&----


REPORT ZASHOK_ABAPOBJ14 .

CLASS C1 DEFINITION DEFERRED.

----


  • CLASS C2 DEFINITION

----


*

----


CLASS C2 DEFINITION FRIENDS C1 .

PUBLIC SECTION.

METHODS : M2.

PROTECTED SECTION.

DATA : NUM2 TYPE I VALUE 15.

PRIVATE SECTION.

DATA : PRI_NUM2 TYPE I VALUE 20.

ENDCLASS. "C2 DEFINITION

----


  • CLASS c1 DEFINITION

----


*

----


CLASS C1 DEFINITION FRIENDS C2 .

PUBLIC SECTION.

METHODS : METHPUB.

PRIVATE SECTION .

DATA : NUM1 TYPE I VALUE 10 .

METHODS : M1.

ENDCLASS. "c1 DEFINITION

----


  • CLASS C2 IMPLEMENTATION

----


*

----


CLASS C2 IMPLEMENTATION.

METHOD M2.

DATA : OREF1 TYPE REF TO C1.

CREATE OBJECT OREF1.

WRITE:/5 OREF1->NUM1.

ENDMETHOD. "M2

ENDCLASS . "C2 IMPLEMENTATION

----


  • CLASS c1 IMPLEMENTATION

----


*

----


CLASS C1 IMPLEMENTATION.

METHOD M1.

DATA : OREF2 TYPE REF TO C2.

CREATE OBJECT OREF2.

WRITE:/5 OREF2->NUM2,

OREF2->PRI_NUM2.

ENDMETHOD. "m1

METHOD METHPUB.

CALL METHOD M1.

ENDMETHOD. "methpub

ENDCLASS. "c1 IMPLEMENTATION

START-OF-SELECTION.

DATA : OREF1 TYPE REF TO C1,

OREF2 TYPE REF TO C2.

CREATE OBJECT : OREF1 , OREF2 .

CALL METHOD : OREF1->METHPUB,

OREF2->M2.

15.

&----


*& Report ZASHOK_ABAPOBJ15 *

*& *

&----


*& *

*& *

&----


REPORT ZASHOK_ABAPOBJ15 .

CLASS C1 DEFINITION.

PUBLIC SECTION.

DATA: NO1 TYPE I VALUE 10.

METHODS: METH1.

INTERFACES: ZASHOK_ABAPOBJG2.

ENDCLASS.

CLASS C1 IMPLEMENTATION.

METHOD METH1.

WRITE :'VALUE OF LOCAL CLASS VARIABLE NO1 = ', NO1.

ENDMETHOD.

METHOD ZASHOK_ABAPOBJG2~METHOD1.

ZASHOK_ABAPOBJG2~NUM1 = 5.

WRITE : /'VALUE OF INTERFACE VAR NUM1= ', ZASHOK_ABAPOBJG2~NUM1.

ENDMETHOD.

METHOD ZASHOK_ABAPOBJG2~METHOD2.

ZASHOK_ABAPOBJG2~NUM2 = 10.

WRITE : /'VALUE OF INTERFACE VAR NUM2= ', ZASHOK_ABAPOBJG2~NUM2.

ENDMETHOD.

ENDCLASS.

START-OF-SELECTION.

DATA : OBJ TYPE REF TO C1.

CREATE OBJECT OBJ.

CALL METHOD :OBJ->METH1,

OBJ->ZASHOK_ABAPOBJG2~METHOD1,

OBJ->ZASHOK_ABAPOBJG2~METHOD2.

Thanks

Sunil