‎2008 Jun 12 8:04 AM
Hi firends,
I have created simple ooops report . its going dump . It is saying that "Access via 'NULL' object reference not possible." Please rectify this code.
The copde is below:
&----
*& Report YCLASS_OOPS_BANK
*&
&----
*&
*&
&----
REPORT yclass_oops_bank.
DATA: act TYPE REF TO zaccountaa.
DATA: bal TYPE i.
SELECTION-SCREEN BEGIN OF BLOCK a. .
PARAMETERS: p_amnt TYPE dmbtr,
p_dep TYPE dmbtr,
p_witd TYPE dmbtr.
SELECTION-SCREEN END OF BLOCK a.
START-OF-SELECTION.
clear act.
CALL METHOD act->set_balance( p_amnt ).
WRITE:/ 'SET BALANCE', p_amnt.
bal = act->deposit( p_dep ).
write:/ 'Deposited ', p_dep ,' bucks making balance to ', bal.
bal = act->withdraw( p_witd ).
write:/ 'Withdrew ', p_witd ,' bucks making balance to ', bal.
thnaks
vvv
‎2008 Jun 12 8:13 AM
hi,
DATA: act TYPE REF TO zaccountaa.
this act is reference to class but it has only null value
it donot point the class
when u
create object act.
then it points to the class
add the create object statment.
Reward points if helpful
Regards,
priya.
‎2008 Jun 12 8:24 AM
Check the code below:
REPORT yclass_oops_bank.
DATA: act TYPE REF TO zaccountaa.
DATA: bal TYPE i.
SELECTION-SCREEN BEGIN OF BLOCK a. .
PARAMETERS: p_amnt TYPE dmbtr,
p_dep TYPE dmbtr,
p_witd TYPE dmbtr.
SELECTION-SCREEN END OF BLOCK a.
START-OF-SELECTION.
TRY.
CREATE OBJECT act
EXPORTING
class_name = 'zaccountaa'
* logical_port_name =
.
CATCH (Exception Name).
ENDTRY.clear act.
CALL METHOD act->set_balance( p_amnt ).
WRITE:/ 'SET BALANCE', p_amnt.
bal = act->deposit( p_dep ).
write:/ 'Deposited ', p_dep ,' bucks making balance to ', bal.
bal = act->withdraw( p_witd ).
write:/ 'Withdrew ', p_witd ,' bucks making balance to ', bal.
Regards
Kannaiah
‎2008 Jun 12 8:26 AM
Of course it will dump !!
Because you have not created a object of the class.
If you know C++ or JAVA..
In C++ and JAVA we do act = new zaccountaa.
similar to that you need to create a object in ABAP by statement
CREATE_OBJECT act type zaccountaa.
If your constructor is expecting some parameters then you need to pass them else this will suffuice.
‎2008 Jun 12 8:55 AM
hi,
sine u have not created an object the short dump is being raised.
so use the following code.
if not acc is bound.
create object acc.
(note: pass the values to the signature of the constructor if u have defined any instance constructor in the class).
endif.
reward points if useful