Skip to Content
-2
Former Member
Dec 14, 2018 at 12:23 PM

Getting error for null object reference, while implementing class in module pool ?

113 Views

Hello everyone,

Please help me eliminate this error, I am new to abap. Would be very thankful for that.

SPAN { font-family: "Courier New"; font-size: 10pt; color: #000000; background: #FFFFFF; } .L0S31 { font-style: italic; color: #808080; } .L0S33 { color: #4DA619; } .L0S52 { color: #0000FF; } .L0S55 { color: #800080; } .L0S70 { color: #808080; }

class ZCL_NB_CLASS definition
public
create public .

public section.
*"* public components of class ZCL_NB_CLASS
*"* do not include other source files here!!!

methods DEPOSIT
importing
value(AMOUNT) type DMBTR
returning
value(NEW_BALANCE) type DMBTR .
methods SET_BALANCE
importing
value(AMOUNT) type DMBTR
returning
value(NEW_BALANCE) type DMBTR .
methods WITHDRAW
importing
value(AMOUNT) type DMBTR
returning
value(NEW_BALANCE) type DMBTR
exceptions
INSUFFICIENT_FUNDS .
methods MESSAGE
exporting
!MESS type BAPIRET2 .
protected section.
*"* protected components of class ZCL_NB_CLASS
*"* do not include other source files here!!!
private section.
*"* private components of class ZCL_NB_CLASS
*"* do not include other source files here!!!

class-data BALANCE type DMBTR .
ENDCLASS.



CLASS ZCL_NB_CLASS IMPLEMENTATION.


* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Instance Public Method ZCL_NB_CLASS->DEPOSIT
* +-------------------------------------------------------------------------------------------------+
* | [--->] AMOUNT TYPE DMBTR
* | [<-()] NEW_BALANCE TYPE DMBTR
* +--------------------------------------------------------------------------------------</SIGNATURE>
method DEPOSIT.

BALANCE = balance + AMOUNT.
new_balance = balance.

endmethod.


* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Instance Public Method ZCL_NB_CLASS->MESSAGE
* +-------------------------------------------------------------------------------------------------+
* | [<---] MESS TYPE BAPIRET2
* +--------------------------------------------------------------------------------------</SIGNATURE>
method MESSAGE.

MESS-message = 'Message has been called'.
MESS-type = 'S'.

endmethod.


* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Instance Public Method ZCL_NB_CLASS->SET_BALANCE
* +-------------------------------------------------------------------------------------------------+
* | [--->] AMOUNT TYPE DMBTR
* | [<-()] NEW_BALANCE TYPE DMBTR
* +--------------------------------------------------------------------------------------</SIGNATURE>
method SET_BALANCE.

balance = new_balance.

endmethod.


* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Instance Public Method ZCL_NB_CLASS->WITHDRAW
* +-------------------------------------------------------------------------------------------------+
* | [--->] AMOUNT TYPE DMBTR
* | [<-()] NEW_BALANCE TYPE DMBTR
* | [EXC!] INSUFFICIENT_FUNDS
* +--------------------------------------------------------------------------------------</SIGNATURE>
method WITHDRAW.

IF balance GE AMOUNT.
balance = balance - AMOUNT.
NEW_BALANCE = BALANCE.
ELSE.
RAISE INSUFFICIENT_FUNDS.
ENDIF.
endmethod.
ENDCLASS.