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

Rgarding oops report

Former Member
0 Likes
513

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

4 REPLIES 4
Read only

Former Member
0 Likes
493

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.

Read only

Former Member
0 Likes
493

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

Read only

former_member69765
Contributor
0 Likes
493

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.

Read only

Former Member
0 Likes
493

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