2007 Dec 21 11:21 AM
Hi,
I have used this code in my prog.I got "Cref is not an object reference" error..how to rectify it..please help if u know...
data:cref type ref to c1.
create object cref.
2007 Dec 21 12:43 PM
Hi Kavitha,
Will you problem solved or not. if not please tell me.
Regards
Manoj Kumar
2007 Dec 21 11:31 AM
Hi Kavitha,
For this u have to create a class with name zaccountMA in the
se24 class builder
or u have to define it locally in your program.
check this code .
In this i define the class locally.
*********************************************************************
L C L _ E M P L O Y E E
*********************************************************************
*---- LCL Employee - Definition
CLASS lcl_employee DEFINITION.
PUBLIC SECTION.
*----
The public section is accesible from outside
*----
TYPES:
BEGIN OF t_employee,
no TYPE i,
name TYPE string,
END OF t_employee.
METHODS:
constructor
IMPORTING im_employee_no TYPE i
im_employee_name TYPE string,
display_employee.
Class methods are global for all instances
CLASS-METHODS: display_no_of_employees.
PROTECTED SECTION.
*----
The protecetd section is accesible from the class and its subclasses
*----
Class data are global for all instances
CLASS-DATA: g_no_of_employees TYPE i.
PRIVATE SECTION.
*----
The private section is only accesible from within the classs
*----
DATA: g_employee TYPE t_employee.
ENDCLASS. "lcl_employee DEFINITION
*--- LCL Employee - Implementation
CLASS lcl_employee IMPLEMENTATION.
METHOD constructor.
g_employee-no = im_employee_no.
g_employee-name = im_employee_name.
g_no_of_employees = g_no_of_employees + 1.
ENDMETHOD. "constructor
METHOD display_employee.
WRITE:/ 'Employee', g_employee-no, g_employee-name.
ENDMETHOD. "display_employee
METHOD display_no_of_employees.
WRITE: / 'Number of employees is:', g_no_of_employees.
ENDMETHOD. "display_no_of_employees
ENDCLASS. "lcl_employee IMPLEMENTATION
************************************************************************
R E P O R T
*********************************************************************
DATA: g_employee1 TYPE REF TO lcl_employee,
g_employee2 TYPE REF TO lcl_employee.
START-OF-SELECTION.
CREATE OBJECT g_employee1
EXPORTING im_employee_no = 1
im_employee_name = 'John Jones'.
CREATE OBJECT g_employee2
EXPORTING im_employee_no = 2
im_employee_name = 'Sally Summer'.
CALL METHOD g_employee1->display_employee.
CALL METHOD g_employee2->display_employee.
CALL METHOD g_employee2->display_no_of_employees.
Regards
Manoj Kumar
2007 Dec 21 12:43 PM
Hi Kavitha,
Will you problem solved or not. if not please tell me.
Regards
Manoj Kumar
2007 Dec 21 12:50 PM
my prog code is this..i am getting run time error .please chk and correct me.I got error in at selection screen statements.
parameters:add Radiobutton group RG1,
sub Radiobutton group RG1,
Multi Radiobutton group RG1,
Div Radiobutton group RG1.
Class c1 definition.
public section.
data:a type i,b type i,c type i.
methods:add importing a type i b type i exporting c type i,
sub importing a type i b type i exporting c type i,
multi importing a type i b type i exporting c type i,
div importing a type i b type i exporting c type i.
endclass.
class c1 implementation.
method add.
c = a + b.
endmethod.
method sub.
c = a - b.
endmethod.
method multi.
c = a * b.
endmethod.
method div.
c = a / b.
endmethod.
endclass.
start-of-selection.
data:a type i,
b type i.
data:c type i,
result type i.
data:cref type ref to c1.
create object cref .
At selection-screen.
If add = 'X'.
call method cref->add exporting a = 10 b = 5 .
elseif sub = 'x'.
call method cref->sub exporting a = 10 b = 5 .
elseif multi = 'x'.
call method cref->multi exporting a = 10 b = 5 .
elseif div = 'x'.
call method cref->div exporting a = 10 b = 5 .
endif.
write:c.
2007 Dec 21 1:28 PM
Hi Kavitha,
Now i have modified your program little bit.
Now its working fine.Check it.
DATA oref TYPE REF TO cx_root.
DATA text TYPE string.
PARAMETERS:add RADIOBUTTON GROUP rg1,
sub RADIOBUTTON GROUP rg1,
multi RADIOBUTTON GROUP rg1,
div RADIOBUTTON GROUP rg1.
----
CLASS c1 DEFINITION
----
*
----
CLASS c1 DEFINITION.
PUBLIC SECTION.
DATA:a TYPE i,b TYPE i,c TYPE i.
METHODS: add IMPORTING a TYPE i
b TYPE i
RETURNING value(c) TYPE i.
METHODS: sub IMPORTING a TYPE i
b TYPE i
RETURNING value(c) TYPE i.
METHODS: multi IMPORTING a TYPE i
b TYPE i
RETURNING value(c) TYPE i.
METHODS: div IMPORTING a TYPE i
b TYPE i
RETURNING value(c) TYPE i.
ENDCLASS. "c1 DEFINITION
----
CLASS c1 IMPLEMENTATION
----
*
----
CLASS c1 IMPLEMENTATION.
METHOD add.
c = a + b.
ENDMETHOD. "add
METHOD sub.
c = a - b.
ENDMETHOD. "sub
METHOD multi.
c = a * b.
ENDMETHOD. "multi
METHOD div.
c = a / b.
ENDMETHOD. "div
ENDCLASS. "c1 IMPLEMENTATION
START-OF-SELECTION.
DATA :result TYPE i.
DATA:cref TYPE REF TO c1.
CREATE OBJECT cref .
TRY.
IF add = 'X'.
CALL METHOD cref->add
EXPORTING
a = 10
b = 5
RECEIVING
c = result.
ELSEIF sub = 'X'.
CALL METHOD cref->sub
EXPORTING
a = 10
b = 5
RECEIVING
c = result.
ELSEIF multi = 'X'.
CALL METHOD cref->multi
EXPORTING
a = 10
b = 5
RECEIVING
c = result.
ELSEIF div = 'X'.
CALL METHOD cref->div
EXPORTING
a = 10
b = 5
RECEIVING
c = result.
ENDIF.
CATCH cx_root INTO oref. "Here i am catching an exception
text = oref->get_text( ).
ENDTRY.
IF NOT text IS INITIAL.
WRITE / text.
ELSE.
WRITE:result.
ENDIF.
Reward Points, if useful.
Regards,
Manoj Kumar
2007 Dec 21 1:34 PM