Sei sulla pagina 1di 49

Reliance Global Services OOABAP Programming by A.

Vijayendar Reddy
REPORT ZRELIANCE_PROGRAM1. PROGRAM1: Class SALES definition. Public section. Methods: create_sales_order, Change_sales_order, Display_sales_order. EndClass. Class SALES implementation. Method create_sales_order. Call Transaction 'VA01'. EndMethod. Method change_sales_order. Call Transaction 'VA02'. EndMethod. Method display_sales_order. Call Transaction 'VA03'. EndMethod.

EndClass. Start-of-selection. Selection-screen begin of Block B1 with Frame Title Sales. Parameter: RB_crete RadioButton Group G1, RB_chnge RadioButton Group G1, RB_displ RadioButton Group G1. Selection-screen end of Block B1. Data: obj Type Ref To SALES. Create Object obj. If RB_crete = 'X'. Obj->create_sales_order( ). Elseif RB_chnge = 'X'. Obj->change_sales_order( ). Elseif RB_displ = 'X'. Obj->display_sales_order( ). Endif.

Note: Convert the Above Local Class( SE38 ) To Global Class ( SE24 ).

Create a Global Class: Name : ZCL_SALES. In SE38 Program: Change local class NAME to global Class NAME. And implement the following code .
Start-of-selection. Selection-screen begin of Block B1 with Frame Title Sales. Parameter: RB_crete RadioButton Group G1, RB_chnge RadioButton Group G1, RB_displ RadioButton Group G1. Selection-screen end of Block B1. Data: obj Type Ref To ZCL_SALES. Create Object obj. If RB_crete = 'X'. Obj->create_sales_order( ). Elseif RB_chnge = 'X'. Obj->change_sales_order( ). Elseif RB_displ = 'X'. Obj->display_sales_order( ). Endif.

PROGRAM 1: REPORT ZRELIANCE_PROGRAM2.

Class EMP definition. Public Section. Methods : ASSIGNMD, DISPLAYMD. PROTECTED SECTION. DATA : EMPNO TYPE I, ENAME(20) TYPE C. ENDCLASS. CLASS EMP IMPLEMENTATION. METHOD ASSIGNMD. EMPNO = '1'. ENAME = 'VIJAYENDAR REDDY'. ENDMETHOD. METHOD DISPLAYMD. WRITE : / EMPNO,ENAME. ENDMETHOD. ENDCLASS. START-OF-SELECTION. DATA OBJ TYPE REF TO EMP. CREATE OBJECT OBJ. OBJ->DISPLAYMD( ). OBJ->ASSIGNMD( ). OBJ->DISPLAYMD( ). Note: Convert the Above Local Class( SE38 ) To Global Class ( SE24 ).

Create a Global Class: Name : ZCL_EMP. In SE38 Program: Change local class NAME to global Class NAME. And implement the following code .
START-OF-SELECTION. DATA OBJ TYPE REF TO ZCL_EMP.

CREATE OBJECT OBJ. OBJ->DISPLAYMD( ). OBJ->ASSIGNMD( ). OBJ->DISPLAYMD( ).

REPORT ZRELIANCE_PROGRAM3. DESCRIPTION : THIS CLASS WILL DISPLAY THE LIST OF COMPANY CODE. CLASS COMPANYCLASS DEFINITION. PUBLIC SECTION. DATA : BEGIN OF WA, BUKRS TYPE BUKRS, BUTXT TYPE BUTXT, ORT01 TYPE ORT01, LAND1 TYPE LAND1, END OF WA. DATA ITAB LIKE TABLE OF WA. METHODS : SELECTMD, DISPLAYMD. ENDCLASS. CLASS COMPANYCLASS IMPLEMENTATION. METHOD SELECTMD. SELECT BUKRS BUTXT ORT01 LAND1 FROM T001 INTO TABLE ITAB. ENDMETHOD. METHOD DISPLAYMD. WRITE : / 'CODE', 'COMPANY NAME ', ' COMPANY COUNTRY'. NEW-lINE. LOOP AT ITAB INTO WA. WRITE : / wa-bukrs,WA-BUTXT,WA-ORT01,WA-LAND1. ENDLOOP. ENDMETHOD. ENDCLASS. START-OF-SELECTION. DATA OBJ TYPE REF TO COMPANYCLASS. CREATE OBJECT OBJ. OBJ->SELECTMD( ). OBJ->DISPLAYMD( ).

COMPANY ADDRESS' , '

Using Method Parameters: ------------------------------------------------------------IF Method definition: methods : selectmd importing vbelnlow type vbak-vbeln vbelnhigh type vbak-vbeln returning name type string

THEN while calling method : obj->selectmd( exporting vbelnlow = so_vbeln-Low vbelnhigh = so_vbeln-high receiving name = tname.

OOABAP Report which displays SALES HEADER DATA: Without Select-OPTIONS:


CLASS Sales DEFINITION.

PUBLIC SECTION. tYPES : BEGIN OF ty_vbak, vbeln type vbak-vbeln, ernam type vbak-ernam, erdat type vbak-erdat, erzet type vbak-erzet, END OF ty_vbak. data : itab TYPE STANDARD TABLE OF TY_VBAK. DATA : WA TYPE TY_VBAK. METHODS: SELECTMD, DISPLAYMD.

EndClass. CLASS Sales METHOD IMPLEMENTATION.

SELECTMD.

SELECT VBELN ERNAM ERDAT ERZET FROM VBAK INTO TABLE ITAB. ENDMETHOD . METHOD DISPLAYMD.

LOOP AT ITAB INTO WA. WRITE:/ ENDLOOP. ENDMETHOD . EndClass. START-OF-SELECTION. DATA OBJ TYPE REF TO SALES. CREATE OBJECT OBJ. OBJ->SELECTMD( ). OBJ->DISPLAYMD( ). WA-VBELN, WA-ERNAM,WA-ERDAT, WA-ERZET.

OOABAP Report which displays SALES HEADER DATA: With Select-OPTIONS: Technique 1: without METHOD parameters:
CLASS Sales DEFINITION.

PUBLIC SECTION. tYPES : BEGIN OF ty_vbak, vbeln type vbak-vbeln, ernam type vbak-ernam, erdat type vbak-erdat, erzet type vbak-erzet, END OF ty_vbak. data : itab TYPE STANDARD TABLE OF TY_VBAK. DATA : WA TYPE TY_VBAK. DATA : data : vbelnlow Type vbak-vbeln. vbelnhigh Type vbak-vbeln.

METHODS:

SELECTMD , DISPLAYMD.

EndClass. CLASS Sales METHOD IMPLEMENTATION.

SELECTMD.

SELECT VBELN ERNAM ERDAT ERZET FROM VBAK INTO TABLE ITAB where vbeln >= vbelnlow AND vbeln <= vbelnhigh . ENDMETHOD . METHOD DISPLAYMD.

LOOP AT ITAB INTO WA. WRITE:/ ENDLOOP. ENDMETHOD . EndClass. WA-VBELN, WA-ERNAM,WA-ERDAT, WA-ERZET.

START-OF-SELECTION. TABLES VBAK. DATA OBJ TYPE REF TO SALES.

Select-OPTIONS

so_vbeln for vbak-vbeln.

CREATE OBJECT OBJ. obj->vbelnlow = so_vbeln-low. obj->vbelnhigh = so_vbeln-high. OBJ->SELECTMD( ). OBJ->DISPLAYMD( ).

OOABAP Report which displays SALES HEADER DATA: With Select-OPTIONS: Technique 2: with METHOD parameters:
CLASS Sales DEFINITION.

PUBLIC SECTION. tYPES : BEGIN OF ty_vbak, vbeln type vbak-vbeln, ernam type vbak-ernam, erdat type vbak-erdat, erzet type vbak-erzet, END OF ty_vbak. data : itab TYPE STANDARD TABLE OF TY_VBAK. DATA : WA TYPE TY_VBAK. METHODS: SELECTMD DISPLAYMD. EndClass. CLASS Sales METHOD IMPLEMENTATION. importing vbelnlow TYPE vbak-vbeln vbelnhigh TYPE vbak-vbeln,

SELECTMD.

SELECT VBELN ERNAM ERDAT ERZET FROM VBAK INTO TABLE ITAB where vbeln >= vbelnlow AND vbeln <= vbelnhigh . ENDMETHOD . METHOD DISPLAYMD.

LOOP AT ITAB INTO WA. WRITE:/ WA-VBELN, WA-ERNAM,WA-ERDAT, WA-ERZET. ENDLOOP. ENDMETHOD . EndClass.

START-OF-SELECTION. TABLES VBAK. DATA OBJ TYPE REF TO SALES. Select-OPTIONS so_vbeln for vbak-vbeln.

CREATE OBJECT OBJ. OBJ->SELECTMD( EXPORTING vbelnlow = so_vbeln-low vbelnhigh = so_vbeln-high OBJ->DISPLAYMD( ).

).

730 AM OOPS OBJECTS: PROGRAM1(CLASS WITHOUT METHODS):


REPORT Z730AMOOPS1. class emp definition. public section. data : empno type i, ename(20) type c. endclass. * * class emp implementation. endclass. data k type ref to emp.

create object k. write :/ k->empno, k->ename. k->empno = 10. k->ename = 'xyz'. write :/ k->empno, k->ename.

PROGRAM2(CALL GLOBAL CLASS):


REPORT Z730AMOOPS2. data ob type ref to z730amclass1. CREATE OBJECT ob. ob->empno = 1. ob->ename = 'xyz'. write :/ ob->empno, ob->ename.

Z730AMCLASS1(SE24): ATTRIBUTES: PROGRAM3(LOCAL CLASS WITH METHODS):


REPORT Z730AMOOPS3. class emp definition. public section. methods : m1, m2. protected section. data : empno type i, ename(20) type c. endclass. class emp implementation. method m1. empno = 1. ename = 'xyz'. endmethod. method m2. write :/ empno,ename. endmethod. endclass. data ob type ref to emp. start-of-selection. create object ob. call method ob->m2. call method ob->m1. ob->m2( ).

PROGRAM4(ACCESS GLOBAL CLASS METHODS):


REPORT Z730AMOOPS4. data ob type ref to z730amclass2. CREATE OBJECT ob. CALL METHOD ob->m1.

Z730AMCLASS2: ATTRIBUTES: METHODS: DOUBLE CLICK ON METHOD M1:


method m1. empno = 1. ename = 'abc'. call method m2. endmethod.

DOUBLE CLICK ON METHOD M2:


method m2. write :/ empno,ename. endmethod.

PROGRAM5(LOCAL CLASS METHODS WITH PARAMETERS):


REPORT Z730AMOOPS5. class emp definition. public section. methods : m1 importing x type i y type c m2. protected section. data : empno type i, ename(20) type c. endclass. class emp implementation. method m1. empno = x. ename = y. endmethod. method m2. write :/ empno,ename. endmethod. endclass. start-of-selection. data ob type ref to emp. create object ob.

optional,

parameters : p_x type i, p_y(20) type c. call method ob->m1 exporting x = p_x y = p_y. call method ob->m2.

PROGRAM6(ACCESS GLOBAL CLASS METHODS WITH PARAMETERS):


REPORT Z730AMOOPS6. data ob type ref to z730amclass3. CREATE OBJECT ob. parameters : p_x type i, p_y(20) type c. CALL METHOD ob->m1 EXPORTING x = p_x y = p_y. CALL METHOD ob->m2 .

Z730AMCLASS3: ATTRIBUTES: METHODS: PARAMETERS METHOD M1: DOUBLE CLICK ON METHOD M1:
method m1. empno = x. ename = y. endmethod.

DOUBLE CLICK ON METHOD M1:


method m2. write :/ empno,ename. endmethod.

PROGRAM7(METHOD RETURNING MULTIPLE VALUES):


REPORT Z730AMOOPS7. class abc definition. public section. methods m1 importing x y exporting m n endclass. type type type type i i i i.

class abc implementation. method m1. m = x + y. n = x - y. endmethod. endclass. start-of-selection. data ob type ref to abc. create object ob. data : lv_r1 type i, lv_r2 type i. call method ob->m1 exporting x = 20 y = 10 importing m = lv_r1 n = lv_r2. write :/ lv_r1,lv_r2.

PROGRAM8(RETURNING PARAMETERS):
REPORT Z730AMOOPS8. class abc definition. public section. methods m1 importing x type i y type i returning value(z) type i. endclass. class abc implementation. method m1. z = x + y. endmethod. endclass. start-of-selection. data ob type ref to abc. create object ob. data lv_r type i. call method ob->m1 exporting x = 10 y = 20 receiving z = lv_r. write :/ 'sum is ',lv_r. clear lv_r.

lv_r = ob->m1( x = 10 y = 25 ). write :/ 'sum is ',lv_r.

PROGRAM9(ACCESS GLOBAL RETURNING PARAMETERS):


REPORT Z730AMOOPS9. data ob type ref to z730amclass4. create object ob. data lv_r type i. CALL METHOD ob->m1 EXPORTING x = 10 y = 20 receiving z = lv_r. write :/ lv_r.

Z730AMCLASS4: METHODS: PARAMETERS: DOUBLE CLICK ON METHOD M1:


method m1. z = x + y. endmethod. REPORT

PROGRAM10(HANDLING STANDARD EXCEPTIONS):


Z730AMOOPS10. class abc definition. public section. methods m1 importing x type i y type i exporting z type i. endclass. class abc implementation. method m1. try. z = x / y. * catch cx_sy_zerodivide. catch cx_root. message 'Cannot divide by zero' type 'I'. endtry. endmethod. endclass. start-of-selection. data ob type ref to abc. create object ob.

parameters : p_x type i, p_y type i. data lv_r type i. call method ob->m1 exporting x = p_x y = p_y importing z = lv_r. write :/ 'Division is ',lv_r. write :/ 'End of program'.

PROGRAM11(HANDLING STANDARD EXCEPTIONS):


REPORT Z730AMOOPS11. data k type ref to cx_sy_zerodivide. data str type string. data : prgname type sy-repid, incname type sy-repid, pos type i. class abc definition. public section. methods m1 importing x type i y type i exporting z type i. endclass. class abc implementation. method m1. try. z = x / y. catch cx_sy_zerodivide into k. CALL METHOD k->if_message~get_text receiving RESULT = str. write :/ 'Short text is ',str. clear str. CALL METHOD k->if_message~get_longtext receiving RESULT = str. write :/ 'Long text is ',str. CALL METHOD k->get_source_position IMPORTING PROGRAM_NAME = prgname INCLUDE_NAME = incname SOURCE_LINE = pos.

write :/ 'Program is :',prgname, / 'Include is :',incname, / 'Line no is :',pos. endtry. endmethod. endclass. start-of-selection. data ob type ref to abc. create object ob. parameters : p_x type i, p_y type i. data lv_r type i. call method ob->m1 exporting x = p_x y = p_y importing z = lv_r. write :/ 'Division is ',lv_r. write :/ 'End of program'.

PROGRAM12(RAISING KEYWORD):
REPORT Z730AMOOPS12. class abc definition. public section. methods m1 importing x type i y type i exporting z type i raising cx_sy_zerodivide. endclass. class abc implementation. method m1. z = x / y. endmethod. endclass. start-of-selection. data ob type ref to abc. create object ob. parameters : p_x type i, p_y type i. data : lv_r type i. try. call method ob->m1 exporting

x = p_x y = p_y importing z = lv_r. catch cx_sy_zerodivide. write :/ 'Exception raised'. endtry. write :/ 'Division is ',lv_r. write :/ 'End'.

PROGRAM13(USER DEFINED EXCEPTIONS IN LOCAL CLASSES):


REPORT Z730AMOOPS13. class abc definition. public section. methods m1 importing x type i y type i exporting z type i exceptions myexception. endclass. class abc implementation. method m1. if y eq 0. raise myexception. else. z = x / y. endif. endmethod. endclass. start-of-selection. data ob type ref to abc. create object ob. parameters : p_x type i, p_y type i. data lv_r type i. call method ob->m1 exporting x = p_x y = p_y importing z = lv_r exceptions myexception = 1 others = 2. if sy-subrc eq 0. write :/ 'division is ',lv_r. elseif sy-subrc eq 1. write :/ 'Cannot divide by zero'. elseif sy-subrc eq 2. write :/ 'Unknown error'. endif.

PROGRAM14(ACCESS GLOBAL USER DEFINED EXCEPTIONS):


REPORT Z730AMOOPS14 . parameters : p_x type i, p_y type i. data lv_z type i. data ob type ref to z730amclass5. create object ob. CALL METHOD OB->M1 EXPORTING X = p_x Y = p_y IMPORTING Z = lv_z EXCEPTIONS MYEXCEPTION = 1 others = 2. if sy-subrc eq 0. write :/ 'division is ',lv_z. elseif sy-subrc eq 1. message 'Exception raised' type 'I'. elseif sy-subrc eq 2. message 'Unknown exception' type 'I'. endif.

Z730AMCLASS5: METHODS: PARAMETERS: DOUBLE CLICK ON METHOD M1:


method m1 . if y eq 0. raise myexception. else. z = x / y. endif. endmethod.

PROGRAM15(INSTANCE AND STATIC ATTRIBUTES):


REPORT Z730AMOOPS15. class abc definition. public section. data x type i. class-data y type i. endclass. data ob1 type ref to abc. create object ob1. write :/ 'Object ob1'. write :/ ob1->x,

ob1->y, abc=>y. ob1->x = 10. ob1->y = 20. write :/ 'object ob1'. write :/ ob1->x, ob1->y. data ob2 type ref to abc. create object ob2. write :/ 'object ob2'. write :/ ob2->x, ob2->y. ob2->y = 30. write :/ 'object ob1'. write :/ ob1->x, ob1->y, ob2->x.

PROGRAM16(INSTANCE AND STATIC METHODS):


REPORT Z730AMOOPS16 class abc definition. public section. methods m1. class-methods m2. protected section. data x type i. class-data y type i. endclass. class abc implementation. method m1. x = 10. y = 20. endmethod. * method m2. x = 12. y = 23. endmethod. endclass. start-of-selection. data ob type ref to abc. create object ob. call method ob->m1. call method ob->m2. call method abc=>m2. . .

PROGRAM17(INSTANCE AND STATIC):


REPORT Z730AMOOPS17 class abc definition. public section. methods constructor. class-methods class_constructor. endclass. class abc implementation. method constructor. write :/ 'instance const'. endmethod.

method class_constructor. write :/ 'static const'. endmethod. endclass. start-of-selection. data ob1 type ref to abc. create object ob1. data ob2 type ref to abc. create object ob2.

PROGRAM18(STATIC CONST EXECUTION):


REPORT Z730AMOOPS18 class abc definition. public section. class-data x type i. class-methods class_constructor. endclass. class abc implementation. method class_constructor. write :/ 'inside static const'. endmethod. endclass. start-of-selection. abc=>x = 10. data ob1 type ref to abc. create object ob1. REPORT Z730AMOOPS19 class abc definition. public section. methods : display, constructor. protected section. data : empno type i, ename(20) type c. endclass. class abc implementation. method display. write :/ empno, ename. endmethod. method constructor. empno = 1. ename = 'abc'. endmethod. endclass. start-of-selection. data ob type ref to abc. create object ob. call method ob->display. .

PROGRAM19(INITIALIZING ATTRIBUTES OF THE CLASS):


.

PROGRAM20(PARAMETERS TO CONSTRUCTORS):
REPORT Z730AMOOPS20. class abc definition. public section. methods : constructor importing x type i y type c, display. protected section. data : empno type i, ename(20) type c. endclass.

class abc implementation. method constructor. empno = x. ename = y. endmethod. method display. write :/ empno,ename. endmethod. endclass. start-of-selection. parameters : p_x type i, p_y(20) type c. data ob type ref to abc. create object ob exporting x = p_x y = p_y. call method ob->display.

PROGRAM21(SINGLE INHERITANCE):
REPORT Z730AMOOPS21 . class cycle definition. public section. methods : setcycle, display. protected section. data : wheels type i, brakes type i, colour(20) type c. endclass. class cycle implementation. method setcycle. wheels = 2. brakes = 2. colour = 'green'. endmethod. method display. write :/ wheels,brakes,colour. endmethod. endclass. class scooter definition inheriting from cycle. public section. methods setscooter. endclass. class scooter implementation. method setscooter. wheels = 2. brakes = 4. colour = 'red'. endmethod. endclass. start-of-selection. data ob1 type ref to cycle. create object ob1.

call method : ob1->setcycle, ob1->display. data ob2 type ref to scooter. create object ob2. call method ob2->setscooter. call method ob2->display.

PROGRAM22(MULTILEVEL INHERITANCE):
REPORT Z730AMOOPS22 . class cycle definition. public section. methods : setcycle, display. protected section. data : wheels type i, brakes type i, colour(20) type c. endclass. class cycle implementation. method setcycle. wheels = 2. brakes = 2. colour = 'green'. endmethod. method display. write :/ wheels,brakes,colour. endmethod. endclass. class scooter definition inheriting from cycle. public section. methods setscooter. endclass. class scooter implementation. method setscooter. wheels = 2. brakes = 4. colour = 'red'. endmethod. endclass. class car definition inheriting from scooter. public section. methods setcar. endclass. class car implementation. method setcar. wheels = 4. brakes = 5. colour = 'blue'. endmethod. endclass. start-of-selection.

data ob1 type ref to cycle. create object ob1. call method : ob1->setcycle, ob1->display. data ob2 type ref to scooter. create object ob2. call method ob2->setscooter. call method ob2->display. data ob3 type ref to car. create object ob3. call method ob3->setcar. call method ob3->display.

PROGRAM23(ACCESS GLOBAL INHERITED COMPONENTS):


REPORT Z730AMOOPS23 data ob1 type ref to z730amcycle. create object ob1. call method : ob1->setcycle, ob1->display. data ob2 type ref to z730amscooter. create object ob2. call method : ob2->setscooter, ob2->display. data ob3 type ref to z730amcar. create object ob3. call method : ob3->setcar, ob3->display. .

SE24: Z730AMCYCLE: ATTRIBUTES: METHODS: DOUBLE CLICK ON METHOD SETCYCLE:


method setcycle . wheels = 2. brakes = 2. colour = 'red'. endmethod.

DOUBLE CLICK ON METHOD DISPLAY:


method display . write :/ wheels,brakes,colour. endmethod.

Z730AMSCOOTER: ATTRIBUTES:

METHODS: DOUBLE CLICK ON METHOD SETCYCLE:


method setcycle . wheels = 2. brakes = 2. colour = 'red'. endmethod.

DOUBLE CLICK ON METHOD DISPLAY:


method display . write :/ wheels,brakes,colour. endmethod.

DOUBLE CLICK ON METHOD SETSCOOTER:


method setscooter . wheels = 2. brakes = 4. colour = 'black'. endmethod.

Z730AMCAR: ATTRIBUTES: METHODS: DOUBLE CLICK ON METHOD SETCYCLE:


method setcycle . wheels = 2. brakes = 2. colour = 'red'. endmethod.

DOUBLE CLICK ON METHOD DISPLAY:


method display . write :/ wheels,brakes,colour. endmethod.

DOUBLE CLICK ON METHOD SETSCOOTER:


method setscooter . wheels = 2. brakes = 4. colour = 'black'. endmethod.

DOUBLE CLICK ON METHOD SETSCAR:


method setcar . wheels = 4. brakes = 5. colour = 'cyan'. endmethod.

PROGRAM24(LOCAL FINAL CLASSES):


REPORT Z730AMOOPS24 . class abc definition final. endclass. class pqr definition inheriting from abc. endclass.

PROGRAM25(METHOD OVERLOADING):
REPORT Z730AMOOPS25 . class abc definition. public section. methods m1. methods m1 importing x type i. endclass.

PROGRAM26(METHOD OVERLOADING):
REPORT Z730AMOOPS26 . class abc definition. public section. methods m1. endclass. class abc implementation. method m1. write :/ 'inside super class m1'. endmethod. endclass. class pqr definition inheriting from abc. public section. methods m1 redefinition. endclass. class pqr implementation. method m1. write :/ 'inside sub class method m1'. call method super->m1. endmethod. endclass. start-of-selection. data ob1 type ref to pqr. create object ob1. call method ob1->m1.

PROGRAM27(ACCESS GLOBAL REDEFINED METHODS):


REPORT Z730AMOOPS27 data ob1 type ref to z730amclass7. create object ob1. call method ob1->m1. .

Z730AMCLASS7: METHODS: DOUBLE CLICK ON METHOD M1:


method m1 . write :/ 'inside sub class m1'. call method super->m1. endmethod.

PROGRAM28(HIERARCHY OF CONST EXECUTION):


REPORT Z730AMOOPS28 class abc definition. .

public section. methods constructor. class-methods class_constructor. endclass. class abc implementation. method constructor. write :/ 'inside super class instance const'. endmethod. method class_constructor. write :/ 'inside super class static const'. endmethod. endclass. class pqr definition inheriting from abc. public section. class-methods class_constructor. endclass. class pqr implementation. method class_constructor. write :/ 'inside sub class static const'. endmethod. endclass. start-of-selection. data ob1 type ref to pqr. create object ob1.

PROGRAM29(HIERARCHY OF CONST EXECUTION):


REPORT Z730AMOOPS28 . class abc definition. public section. methods constructor. class-methods class_constructor. endclass. class abc implementation. method constructor. write :/ 'inside super class instance const'. endmethod. method class_constructor. write :/ 'inside super class static const'. endmethod. endclass. class pqr definition inheriting from abc. public section. methods constructor. class-methods class_constructor. endclass. class pqr implementation. method constructor. write :/ 'inside sub class instance const'. call method super->constructor. endmethod.

method class_constructor. write :/ 'inside sub class static const'. endmethod. endclass. start-of-selection. data ob1 type ref to pqr. create object ob1.

PROGRAM30(PUBLIC CLASSES):
REPORT * Z730AMOOPS30. class abc definition. class abc definition create public. public section. data x type i. endclass. class pqr definition inheriting from abc. endclass. start-of-selection. data ob type ref to abc. create object ob. data ob1 type ref to pqr. create object ob1.

PROGRAM31(PROTECTED CLASSES):
REPORT Z730AMOOPS31 class abc definition create protected. public section. data x type i. endclass. class pqr definition create public inheriting from abc. public section. methods m1. endclass. class pqr implementation. method m1. data ob type ref to abc. create object ob. endmethod. endclass. start-of-selection. data ob1 type ref to pqr. create object ob1. .

PROGRAM32(PRIVATE CLASSES):
REPORT Z730AMOOPS32 class pqr definition deferred. . class abc definition create private friends pqr. public section. data x type i. endclass. class pqr definition create public inheriting from abc.

public section. methods m1. endclass. class pqr implementation. method m1. data ob type ref to abc. create object ob. endmethod. endclass. start-of-selection. data ob1 type ref to pqr. create object ob1.

PROGRAM33(SECOND USAGE OF FRIENDS KEYWORD):


REPORT Z730AMOOPS33 . class pqr definition deferred. class abc definition friends pqr. public section. methods m1. protected section. methods m2. private section. methods m3. endclass. class abc implementation. method m1. write :/ 'inside public method m1'. endmethod. method m2. write :/ 'inside protected method m2'. endmethod. method m3. write :/ 'inside private method m3'. endmethod. endclass. class pqr definition. public section. methods m4. endclass. class pqr implementation. method m4. write :/ 'inside m4 of pqr'. data ob type ref to abc. create object ob. call method ob->m1. call method ob->m2. call method ob->m3. endmethod. endclass. start-of-selection. data k type ref to pqr.

create object k. call method k->m4.

PROGRAM34(LOCAL ABSTRACT CLASSES):


REPORT Z730AMOOPS34. class restaurant definition abstract. public section. methods : set, "concrete method display, "concrete method payment abstract. "nonconcrete method protected section. data : tableno type i, steward(20) type c. endclass. class restaurant implementation. method set. tableno = 1. steward = 'abc'. endmethod. method display. write :/ tableno,steward. endmethod. endclass. class cheque definition inheriting from restaurant. public section. methods payment redefinition. protected section. data : cqno type i, amt type i, bank(20) type c. endclass. class cheque implementation. method payment. cqno = 122. amt = 321. bank = 'RBS'. write :/ cqno,amt,bank. endmethod. endclass.

class creditcard definition inheriting from restaurant. public section. methods payment redefinition. protected section. data : ccno type i, amount type i, bankname(20) type c. endclass. class creditcard implementation. method payment. ccno = 5555. amount = 444. bankname = 'xyz'. write :/ ccno,amount,bankname. endmethod. endclass. start-of-selection. data r type ref to restaurant. data cq type ref to cheque. create object cq. write :/ 'CHEQUE Class'. call method : cq->set, cq->display, cq->payment. write :/ ' CHEQUE --> RESTAURANT'. r = cq. call method : r->set, r->display, r->payment. data cc type ref to creditcard. create object cc. write :/ 'CREDITCARD Class'. call method : cc->set, cc->display, cc->payment. write :/ ' CREDITCARD --> RESTAURANT'. r = cc.

call method : r->set, r->display, r->payment.

PROGRAM35(ACCESS GLOBAL ABSTRACT CLASSES):


REPORT Z730AMOOPS35. data cq type ref to zcheque. create object cq. call method : cq->set, cq->display, cq->payment.

ZCHEQUE(SE24): ATTRIBUTES:
METHODS: DOUBLE CLICK ON METHOD SET:
method set . tableno = 1. steward = 'abc'. endmethod.

DOUBLE CLICK ON METHOD DISPLAY:


method display . *CALL METHOD SUPER->DISPLAY * . endmethod.

DOUBLE CLICK ON METHOD PAYMENT:


method payment . cqno = 11. amt = 333. bank = 'sbi'. write :/ cqno,amt,bank. endmethod. PROGRAM37 ( INTERFACES ):
SELEcTiON-SCREEN:BEGIN OF BLOCK B1 WITH Frame tITLE PaRAMETER: RB_SALES RADIOBUTToN GROuP G1, RB_CUST RADIOBUTToN GROuP G1. SELECTION-SCREEN END OF BLOCK B1. TEXT-000.

SELECTION-SCREEN: BEGIN OF BLOCK B2 WITH frame TITLE PaRAMETER: RB_CRET RADIOBUTToN GROuP G2, RB_CHANG RADIOBUTToN GROuP G2, RB_DISP RADIOBUTToN GROuP G2. SELECTION-SCREEN END OF BLOCK B2. Interface I_data. Methods: create, change, display. endInterface. Class LCL_customer definition. public section. Interfaces:I_data. endclass. Class LCL_customer Implementation. method I_data~create. call transaction 'XD01'. endmethod. method I_data~change. call transaction 'XD02'. endmethod. method I_data~display. call transaction 'XD03'. endmethod. endclass. Class LCL_sales_order definition. public section. Interfaces:I_data. endclass. Class LCL_sales_order Implementation. method I_data~create. call transaction 'VA01'. endmethod. method I_data~change. call transaction 'VA02'. endmethod. method I_data~display. call transaction 'VA03'. endmethod. ENDClaSS. DATA:o_CUSTOMER TYPE REF TO LCL_customer, o_sorder type Ref to LCL_sales_order, IRef_data type ref to I_data. start-of-selection. create object o_customer.

TEXT-001.

create object o_sorder. if rb_cust = 'X'. IRef_data = o_customer. elseif RB_sales = 'X'. IRef_data = o_sorder. endif. if Rb_cret ='X'. call method IRef_data->create. elseif RB_chang = 'X'. CALL METHOD IRef_data->change. elseif RB_disp = 'X'. CALL METHOD IRef_data->display. endif.

PROGRAM36(LOCAL INTERFACES):
REPORT Z730AMOOPS36 interface rectangle. constants : length type i value 10, breadth type i value 5. methods : area, perimeter. endinterface. interface square. constants : side type i value 7. methods : area, perimeter. endinterface. class abc definition. public section. data r type i. interfaces : rectangle, square. endclass. class abc implementation. method rectangle~area. r = rectangle~length * rectangle~breadth. write :/ 'Area of rectangle is ',r. endmethod.

method rectangle~perimeter. r = 2 * ( rectangle~length + rectangle~breadth ). write :/ 'perimeter of rectangle is ',r.

endmethod. method square~area. r = square~side * square~side. write :/ 'Area of square is ',r. endmethod. method square~perimeter. r = 4 * square~side. write :/ 'perimeter of square is ',r. endmethod. endclass. start-of-selection. data ob type ref to abc. create object ob. call method : ob->rectangle~area, ob->rectangle~perimeter, ob->square~area, ob->square~perimeter.

PROGRAM37(IMPLEMENTING INTERFACES PARTIALLY):


*&---------------------------------------------------------------------* *& Report Z730AMOOPS37 *& *&---------------------------------------------------------------------* *& *& *&---------------------------------------------------------------------* REPORT Z730AMOOPS37.

interface abc. methods : m1, m2, m3. endinterface. class pqr definition abstract. public section. interfaces abc abstract methods m2 m3. endclass. class pqr implementation. method abc~m1. write :/ 'inside m1'. endmethod.

endclass. class xyz definition inheriting from pqr. public section. methods : abc~m2 redefinition, abc~m3 redefinition. endclass. class xyz implementation. method abc~m2. write :/ 'inside m2'. endmethod. method abc~m3. write :/ 'inside m3'. endmethod. endclass. start-of-selection. data ob type ref to xyz. create object ob. call method : ob->abc~m1, ob->abc~m2, ob->abc~m3.

PROGRAM38(LOCAL ALIASES):
REPORT Z730AMOOPS38. interface abc. methods : m1, m2. endinterface. class pqr definition. public section. interfaces abc. aliases a1 for abc~m1. protected section. aliases a2 for abc~m2. endclass. class pqr implementation. method a1. write :/ 'inside m1'. call method a2. endmethod. method a2. write :/ 'inside m2'. endmethod. endclass. start-of-selection. data ob type ref to pqr. create object ob.

call method : ob->a1.

PROGRAM39(ACCESS GLOBAL INTERFACE COMPONENTS):


*&---------------------------------------------------------------------* *& Report Z730AMOOPS39 *& *&---------------------------------------------------------------------* *& *& *&---------------------------------------------------------------------* REPORT Z730AMOOPS39. data ob type ref to z730impl. create object ob. call method : ob->a1.

Z30IMP1(SE24): INTERFACES: DOUBLE CLICK ON INTERFCES: METHODS: DOUBLE CLICK ON METHOD ZINTER~M1:
method zinter~m1. write :/ 'inside m1'. call method a2. endmethod. method zinter~m2. write :/ 'inside m2'. endmethod.

DOUBLE CLICK ON METHOD ZINTER~M2: PROGRAM40(PERSISTENCE SERVICE USING BUSINESS KEY IDENTITY):
REPORT Z730AMOOPS40. parameters : p_dno type Zdept-deptno, p_dname type zdept-deptname, p_loc type zdept-loc. parameters : r1 radiobutton group g1, r2 radiobutton group g1, r3 radiobutton group g1. data actor type ref to zca_8dept. data pers type ref to zcl_8dept.

start-of-selection. actor = zca_8dept=>agent. if r1 = 'X'. TRY. call method actor->create_persistent exporting I_DEPTNAME = p_dname i_deptno = p_dno I_LOC = p_loc receiving result = pers. if pers is not initial. commit work. endif. CATCH CX_OS_OBJECT_EXISTING . message 'Exception' type 'I'. ENDTRY. elseif r2 = 'X'. TRY. call method actor->delete_persistent exporting i_deptno = p_dno. commit work. CATCH CX_OS_OBJECT_NOT_EXISTING . message 'Object not found' type 'I'. ENDTRY. endif.

PROGRAM40(PERSISTENCE SERVICE USING BUSINESS KEY IDENTITY 08-09-2011):


REPORT Z730AMOOPS40. parameters : p_dno type Zdept-deptno, p_dname type zdept-deptname, p_loc type zdept-loc. parameters : r1 radiobutton group g1, r2 radiobutton group g1, r3 radiobutton group g1. data actor type ref to zca_8dept. data pers type ref to zcl_8dept. start-of-selection. actor = zca_8dept=>agent. if r1 = 'X'. TRY. call method actor->create_persistent exporting I_DEPTNAME = p_dname i_deptno = p_dno I_LOC = p_loc receiving result = pers.

if pers is not initial. commit work. endif. CATCH CX_OS_OBJECT_EXISTING . message 'Exception' type 'I'. ENDTRY. elseif r2 = 'X'. TRY. call method actor->delete_persistent exporting i_deptno = p_dno. commit work. CATCH CX_OS_OBJECT_NOT_EXISTING . message 'Object not found' type 'I'. ENDTRY. elseif r3 = 'X'. clear pers. TRY. call method actor->get_persistent exporting i_deptno = p_dno receiving result = pers. if pers is not initial. clear : p_dname, p_loc. p_dname = pers->get_deptname( ). p_loc = pers->get_loc( ). write :/ 'Department name :',p_dname, / 'Location :',p_loc. endif. CATCH CX_OS_OBJECT_NOT_FOUND . message 'object not found' type 'I'. ENDTRY. endif.

PROGRAM41(ACCESS TRANSACTION SERVICE FROM EXECUTABLE PROGRAMS):


REPORT Z730AMOOPS41. data ob type ref to z8trans. create object ob. call method ob->m1.

Z8TRANS(SE24): METHODS: DOUBLE CLICK ON METHOD M1:


method m1. data : trans_mng type ref to if_os_transaction_manager, trans type ref to if_os_transaction.

call method cl_os_system=>get_transaction_manager receiving result = trans_mng. call method trans_mng->create_transaction receiving result = trans. try. call method trans->start. * perform the operation call method m2. catch cx_os_transaction . message 'Exception in starting transaction' type 'I'. endtry. * end the transaction try. call method trans->end. catch cx_os_check_agent_failed . catch cx_os_transaction . call method trans->undo. endtry. endmethod.

DOUBLE CLICK ON METHOD M2:


method m2. data : actor type ref to zca_8dept, pers type ref to zcl_8dept. try. actor = zca_8dept=>agent.

call method actor->create_persistent exporting i_deptname = 'HR' i_deptno = 46 i_loc = 'Hyderabad' receiving result = pers. catch cx_os_object_existing . message 'Exception in create' type 'I'. endtry. endmethod.

PROGRAM42:
REPORT

Z730AMOOPS42.

parameters : p_guid type zmemp-guid, p_empno type zmemp-empno, p_ename type zmemp-ename. parameters : r1 radiobutton group g1,

r2 radiobutton group g1, r3 radiobutton group g1. data : actor type ref to zca_8emp, pers type ref to zcl_8emp, ob type ref to object. start-of-selection. actor = zca_8emp=>agent. if r1 = 'X'. TRY. call method actor->create_persistent EXPORTING I_EMPNO = p_empno I_ENAME = p_ename receiving result = pers. if pers is not initial. commit work. endif. CATCH CX_OS_OBJECT_EXISTING . message 'Exception' type 'I'. ENDTRY. elseif r3 = 'X'. TRY. call method actor->if_os_ca_persistency~get_persistent_by_oid exporting i_oid = p_guid receiving result = ob. clear : pers, p_empno, p_ename. pers ?= ob. p_empno = pers->get_empno( ). p_ename = pers->get_ename( ). write :/ 'Employee no is :',p_empno, 'Employee name is :',p_ename. CATCH CX_OS_OBJECT_NOT_FOUND . CATCH CX_OS_CLASS_NOT_FOUND . message 'not found' type 'I'. ENDTRY. elseif r2 = 'X'. * Check for existence of object call method actor->if_os_ca_persistency~get_persistent_by_oid exporting i_oid = p_guid receiving result = ob. if ob is not initial. clear pers. pers ?= ob. endif.

TRY. call method actor->if_os_factory~delete_persistent exporting i_object = pers. commit work. CATCH CX_OS_OBJECT_NOT_EXISTING . message 'not found' type 'I'. ENDTRY. endif.

PROGRAM43:
report z730amoops43. class abc definition create private. public section. class-data ob type ref to abc. "static reference class-methods class_constructor. "static const class-methods m2 returning value(k) type ref to abc. "static method methods m1. endclass. class abc implementation. method class_constructor. create object ob. endmethod. method m1. write :/ 'inside instance method'. endmethod. method m2. k = ob. endmethod. endclass. start-of-selection. data r type ref to abc. r = abc=>m2( ). call method r->m1.

RTTS PROGRAM:
REPORT ZRTTS. parameters : p_tab type dd02l-tabname. field-symbols : <fstab> type any table, <fswa> type any,

<fsfield> type any. data : ref_rowtype type ref to cl_abap_structdescr, ref_tabletype type ref to cl_abap_tabledescr. data : ref_tab type ref to DATA, ref_wa type ref to DATA. start-of-selection. * Dynamic instantiation ref_rowtype ?= cl_abap_typedescr=>describe_by_name( p_name = p_tab ).

tRY. call method cl_abap_tabledescr=>create exporting p_line_type = ref_rowtype receiving p_result = ref_tabletype. CATCH CX_SY_TABLE_CREATION . message 'Error in creating internal table' type 'I'. ENDTRY. * Create the object create data ref_wa type handle ref_rowtype. create data ref_tab type handle ref_tabletype. * Value assignment (MAPPING DBTABLE STRUCTURE TO FIELDSYMBOLS) assign ref_wa->* to <fswa>. assign ref_tab->* to <fstab>. * Data retrieval select * from (p_tab) into table <fstab> UP TO 5 ROWS. * Data Display loop at <fstab> into <fswa>. do. assign component sy-index of structure <fswa> to <fsfield>. if sy-subrc eq 0. write : <fsfield>. else. NEW-LINE. exit. endif. enddo. endloop.

PROGRAM44(CUSTOM EVENT 1):


REPORT Z730AMOOPS44. class abc definition. public section.

events e1. "instance event methods : m1 for event e1 of abc, "instance event handler method m2. "instance normal method endclass. class abc implementation. method m1. write :/ 'inside instance event handler m1'. endmethod. method m2. write :/ 'inside m2'. raise event e1. endmethod. endclass. start-of-selection. data ob type ref to abc. create object ob. call method ob->m2.

PROGRAM45(CUSTOM EVENT 1):

REPORT Z730AMOOPS44. class abc definition. public section. events e1. "instance event methods : m1 for event e1 of abc, "instance event handler method m2. "instance normal method endclass. class abc implementation. method m1. write :/ 'inside instance event handler m1'. endmethod. method m2. write :/ 'inside m2'. raise event e1. endmethod. endclass. start-of-selection. data ob type ref to abc. create object ob. call method ob->m2. set handler ob->m1 for ob.

PROGRAM46(CUSTOM EVENT 1):


REPORT Z730AMOOPS44. class abc definition. public section.

events e1. "instance event methods : m1 for event e1 of abc, "instance event handler method m2. "instance normal method endclass. class abc implementation. method m1. write :/ 'inside instance event handler m1'. endmethod. method m2. write :/ 'inside m2'. raise event e1. endmethod. endclass. start-of-selection. data ob type ref to abc. create object ob. set handler ob->m1 for ob. call method ob->m2.

PROGRAM47(CUSTOM EVENT 1):


REPORT Z730AMOOPS44. class abc definition. public section. events e1. "instance event methods : m1 for event e1 of abc, "instance event handler method m2. "instance normal method endclass. class abc implementation. method m1. write :/ 'inside instance event handler m1'. endmethod. method m2. write :/ 'inside m2'. raise event e1. endmethod. endclass. start-of-selection. data ob type ref to abc. create object ob. data ob1 type ref to abc. create object ob1. set handler ob->m1 for ob1. call method ob->m2.

PROGRAM48(CUSTOM EVENT 1):


REPORT Z730AMOOPS44. class abc definition. public section. events e1. "instance event methods : m1 for event e1 of abc, "instance event handler method m2. "instance normal method endclass. class abc implementation. method m1. write :/ 'inside instance event handler m1'. endmethod. method m2. write :/ 'inside m2'. raise event e1. endmethod. endclass. start-of-selection. data ob type ref to abc. create object ob. data ob1 type ref to abc. create object ob1. set handler ob->m1 for ob1. call method ob->m2. call method ob1->m2.

PROGRAM49(CUSTOM EVENT 1):


REPORT Z730AMOOPS44. class abc definition. public section. events e1. "instance event methods : m1 for event e1 of abc, "instance event handler method m2. "instance normal method endclass. class abc implementation. method m1. write :/ 'inside instance event handler m1'. endmethod. method m2. write :/ 'inside m2'. raise event e1. endmethod. endclass.

start-of-selection. data ob type ref to abc. create object ob. data ob1 type ref to abc. create object ob1. set handler ob->m1 for ob. set handler ob->m1 for ob1. call method ob->m2. call method ob1->m2.

PROGRAM50(CUSTOM EVENT 1):


REPORT Z730AMOOPS44. class abc definition. public section. events e1. "instance event methods : m1 for event e1 of abc, "instance event handler method m2. "instance normal method endclass. class abc implementation. method m1. write :/ 'inside instance event handler m1'. endmethod. method m2. write :/ 'inside m2'. raise event e1. endmethod. endclass. start-of-selection. data ob type ref to abc. create object ob. data ob1 type ref to abc. create object ob1. set handler ob->m1 for all instances. call method ob->m2. call method ob1->m2.

PROGRAM51(STATIC EVENTS):
REPORT Z730AMOOPS51 class abc definition. public section. class-events e1. methods : m1 for event e1 of abc, m2.

endclass. class abc implementation. method m1. write :/ 'inside event handler m1'. endmethod. method m2. write :/ 'inside m2'. raise event e1. endmethod. endclass. start-of-selection. data ob type ref to abc. create object ob. data ob1 type ref to abc. create object ob1. set handler ob->m1. call method ob->m2. call method ob1->m2.

PROGRAM52(STATIC EVENTS):
REPORT Z730AMOOPS51 class abc definition. public section. events e1. methods : m1 for event e1 of abc, m2. endclass. class abc implementation. method m1. write :/ 'inside first event handler m1'. endmethod. method m2. write :/ 'inside m2'. raise event e1. endmethod. endclass. class pqr definition. public section. methods m3 for event e1 of abc. endclass. class pqr implementation. method m3. write :/ 'second event handler method m3'. endmethod.

endclass. start-of-selection. data ob type ref to abc. create object ob. data ob1 type ref to pqr. create object ob1. set handler ob1->m3 for ob. set handler ob->m1 for ob. call method ob->m2.

PROGRAM53(EVENTS WITH PARAMETERS):


report z730amoops53 . class abc definition. public section. events e1 exporting value(p1) type i optional. methods : m1 for event e1 of abc importing p1, m2. endclass. class abc implementation. method m1. write :/ 'inside event handler m1'. write :/ 'parameter received is ',p1. endmethod. method m2. write :/ 'inside m2'. raise event e1 exporting p1 = 10. endmethod. endclass. start-of-selection. data ob type ref to abc. create object ob. set handler ob->m1 for ob. call method ob->m2.

PROGRAM54(ACCESS GLOBAL EVENTS):


REPORT Z730AMOOPS54 data ob type ref to z730class10. create object ob. set handler ob->m1 for ob. call method ob->m2.

Z730CLASS10: METHODS:

PARAMETER M1: DOUBLE CLICK ON METHOD M1:


method m1 . write :/ 'inside event handler m1'. write :/ 'parameter received is ',p1. endmethod.

DOUBLE CLICK ON METHOD M2:


method m2 . write :/ 'inside method m2'. raise event e1 exporting p1 = 10. endmethod.

EVENTS: PARAMETERS OF EVENT E1: PROGRAM55: PROGRAM56: PROGRAM57: PROGRAM58: PROGRAM59: PROGRAM60:

Potrebbero piacerti anche