‎2008 Oct 29 5:31 AM
Hi,
i'm getting this abap dump "Access via 'NULL' object reference not possible"...
i'm not familiar with Badi Implementation. Can some one help me? thanks.
This is my source code:
METHOD if_ex_me_process_po_cust~check.
Data declaration for GET_HEADER()
DATA: lo_po_order TYPE REF TO if_purchase_order_mm,
ls_header TYPE mepoheader.
Data declaration for GET_ITEMS() method
DATA: lo_po_orderitem TYPE REF TO if_purchase_order_item_mm,
lt_items TYPE STANDARD TABLE OF purchase_order_item,
ls_item LIKE LINE OF lt_items.
Data declaration for PO line item data
DATA: ls_mepoitem TYPE mepoitem,
ls_mepoitem_persistent TYPE mepoitem.
Data declaration for GET_ACCOUNTINGS()
DATA: lo_po_account TYPE REF TO if_purchase_order_account_mm,
lt_accountings TYPE STANDARD TABLE OF purchase_order_accounting, "line type
ls_accounting LIKE LINE OF lt_accountings.
Data declaration for accounting assignment data
DATA: ls_mepoaccounting TYPE mepoaccounting.
Data declaration for persistent item indicator
DATA: l_persistent TYPE c.
Get PO header
ls_header = im_header->get_data( ). " header details
Get PO items
lo_po_order ?= im_header. " casting to purchase document
lt_items = lo_po_order->get_items( ).
LOOP AT lt_items INTO ls_item.
lo_po_orderitem ?= ls_item-item.
ENDLOOP.
ls_mepoitem = lo_po_orderitem->get_data( ).
IF sy-subrc = 0.
"Material number is not allowed to blank if item category is D (ext) = 9 (int), refer to SPRO->Material Management->Purchasing->Define External Representation of Item Categories
IF ( ls_mepoitem-pstyp NE 'D' AND ls_mepoitem-pstyp NE '9' ) AND ls_mepoitem-matnr EQ ''.
ch_failed = 'X'.
ENDIF.
ENDIF.
IF ls_header-ebeln NE space.
CALL METHOD lo_po_orderitem->is_persistent
RECEIVING
re_persistent = l_persistent.
IF l_persistent = 'X'. "If posted
CALL METHOD lo_po_orderitem->get_persistent_data
IMPORTING
ex_data = ls_mepoitem_persistent.
IF sy-subrc = 0.
IF ls_header-frgke = 'Z' "Changing to material number & material text are not allowed if PO has been released.
AND ( ls_mepoitem-ematn NE ls_mepoitem_persistent-ematn OR ls_mepoitem-txz01 NE ls_mepoitem_persistent-txz01 ).
ch_failed = 'X'.
ENDIF.
ENDIF.
ENDIF.
*Get accountings
IF ls_mepoitem-knttp NE space.
IF ( ls_mepoitem-pstyp NE 'D' AND ls_mepoitem-pstyp NE '9' ) and ls_mepoitem-knttp NE 'U'.
lt_accountings = lo_po_orderitem->get_accountings( ).
LOOP AT lt_accountings INTO ls_accounting.
lo_po_account ?= ls_accounting-accounting.
ENDLOOP.
ls_mepoaccounting = lo_po_account->get_data( ).
"Check GL/Account in account assignment
IF ls_mepoaccounting-sakto EQ space. "Posting is not allowed if GL Account in account assignment is blank.
ch_failed = 'X'.
ENDIF.
ENDIF.
ENDIF.
ENDMETHOD.
‎2008 Oct 29 5:55 AM
Hello
The most important information is (again) missing: which object reference is initial ("NULL")?
The ABAP dump will tell you.
Below I show an example how this can happen (and be avoided):
LOOP AT lt_accountings INTO ls_accounting.
lo_po_account ?= ls_accounting-accounting.
ENDLOOP.
" QUESTION: Are you sure that lo_po_account hold an instance ???
" If LO_PO_ACCOUNT is empty the following statement will give you the dump.
ls_mepoaccounting = lo_po_account->get_data( ).
" And that is how to avoid this (at least the dump. Whether your logic is still ok is another matter...)
CHECK ( lo_po_account IS BOUND ).
ls_mepoaccounting = lo_po_account->get_data( ).
Regards
Uwe
‎2008 Oct 29 5:55 AM
Hello
The most important information is (again) missing: which object reference is initial ("NULL")?
The ABAP dump will tell you.
Below I show an example how this can happen (and be avoided):
LOOP AT lt_accountings INTO ls_accounting.
lo_po_account ?= ls_accounting-accounting.
ENDLOOP.
" QUESTION: Are you sure that lo_po_account hold an instance ???
" If LO_PO_ACCOUNT is empty the following statement will give you the dump.
ls_mepoaccounting = lo_po_account->get_data( ).
" And that is how to avoid this (at least the dump. Whether your logic is still ok is another matter...)
CHECK ( lo_po_account IS BOUND ).
ls_mepoaccounting = lo_po_account->get_data( ).
Regards
Uwe