cancel
Showing results for 
Search instead for 
Did you mean: 

Access via 'NULL' object reference not possible.

Former Member
0 Kudos

hi all,

i am getting the following error in my application(getting data from 2 data base table and kept in internal table and binding that 2 internal table to two context)

in st22 i have this.

Error analysis

An exception occurred that is explained in detail below.

The exception, which is assigned to class 'CX_SY_REF_IS_INITIAL', was not

caught in

procedure "PARSE_XML_DATA" "(METHOD)", nor was it propagated by a RAISING

clause.

Since the caller of the procedure could not have anticipated that the

exception would occur, the current program is terminated.

The reason for the exception is:

You attempted to use a 'NULL' object reference (points to 'nothing')

access a component.

An object reference must point to an object (an instance of a class)

before it can be used to access components.

Either the reference was never set or it was set to 'NULL' using the

CLEAR statement.

gettong error at line 52.

24 data: parseerror type ref to if_ixml_parse_error,

25 str type string, "#EC NEEDED

26 i type i, "#EC NEEDED

27 count type i,

28 index type i.

29 count = parser->num_errors( ).

30 * write: count, ' parse errors have occured:'.

31 index = 0.

32 while index < count.

33 parseerror = parser->get_error( index = index ).

34 i = parseerror->get_line( ).

35 * write: 'line: ', i.

36 i = parseerror->get_column( ).

37 * write: 'column: ', i.

38 str = parseerror->get_reason( ).

39 * write: str.

40 index = index + 1.

41 endwhile.

42 endif.

43 endif.

44

45 data l_ref_ixml_elem type ref to if_ixml_element.

46 l_ref_ixml_elem = l_ref_doc->get_root_element( ).

47

48 data l_ref_node_list type ref to if_ixml_node_list.

49 data l_ref_child type ref to if_ixml_node.

50 data nodes_index type i value 0.

51 data l_count type i.

>>>> l_ref_node_list = l_ref_ixml_elem->get_children( ).

53 while nodes_index < l_ref_node_list->get_length( ).

54 l_ref_child = l_ref_node_list->get_item( nodes_index ).

55 nodes_index = nodes_index + 1.

56 l_count = l_ref_child->num_children( ).

57 if l_count > 0.

58 me->parse_xml_subnode( subnode = l_ref_child index = 0

59 with_initial_attributes = with_initial_attributes ).

60 elseif with_initial_attributes = abap_true.

61 me->parse_xml_subnode( subnode = l_ref_child index = 0

62 with_initial_attributes = with_initial_attributes ).

pls help me

regards,

vinoth.

Accepted Solutions (0)

Answers (3)

Answers (3)

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos

That block of code that you posted from ST22, is that your coding from the inner processing of the SAP context APIs? Please post your coding where you are building the internal tables and building the context.

Former Member
0 Kudos

hi thomas,

thanks for ur reply.

this is my scenario:

my context:

>contract(root node with cardinality 1:1)

>mandt_ekko( 1:1)

ebeln

>disp_ekko(o:n)

bstyp

lifnr

...

>disp_ekpo(o:n)

ebelp

txz01

....

based on ebeln fetched at run time. i have to display ekko and ekpo table details in form.i have fetched values based on that ebeln and put it in 2 internal table from ekko and ekpo table and binded that to context.but getting error.

my code:

method ONACTIONSUBMIT .

  DATA lo_nd_contract TYPE REF TO if_wd_context_node.
  DATA lo_nd_mandt_ekko TYPE REF TO if_wd_context_node.
  DATA lo_el_mandt_ekko TYPE REF TO if_wd_context_element.
  DATA ls_mandt_ekko TYPE wd_this->element_mandt_ekko.
* navigate from <CONTEXT> to <CONTRACT> via lead selection
  lo_nd_contract = wd_context->get_child_node( name = wd_this->wdctx_contract ).

* navigate from <CONTRACT> to <MANDT_EKKO> via lead selection
  lo_nd_mandt_ekko = lo_nd_contract->get_child_node( name = wd_this->wdctx_mandt_ekko ).

* get element via lead selection
  lo_el_mandt_ekko = lo_nd_mandt_ekko->get_element(  ).

* get all declared attributes
  lo_el_mandt_ekko->get_static_attributes(
    IMPORTING
      static_attributes = ls_mandt_ekko ).

  DATA lo_nd_disp_ekko TYPE REF TO if_wd_context_node.
  DATA lo_el_disp_ekko TYPE REF TO if_wd_context_element.
  DATA ls_disp_ekko TYPE wd_this->element_disp_ekko.
* navigate from <CONTEXT> to <CONTRACT> via lead selection
  lo_nd_contract = wd_context->get_child_node( name = wd_this->wdctx_contract ).

* navigate from <CONTRACT> to <DISP_EKKO> via lead selection
  lo_nd_disp_ekko = lo_nd_contract->get_child_node( name = wd_this->wdctx_disp_ekko ).

* @TODO handle not set lead selection
  IF lo_nd_disp_ekko IS INITIAL.
  ENDIF.

* get element via lead selection
  lo_el_disp_ekko = lo_nd_disp_ekko->get_element(  ).

* @TODO handle not set lead selection
  IF lo_el_disp_ekko IS INITIAL.

   lo_el_disp_ekko = lo_nd_disp_ekko->create_element( ).

  ENDIF.

data: IT_EKKO TYPE standard table of  EKKO,
      lo_nd_snode_1 TYPE REF TO if_wd_context_node.

select * from EKKO into table it_EKKO WHERE EBELN = ls_mandt_ekko-EBELN.
   if sy-subrc eq 0.


    lo_nd_snode_1 = wd_context->path_get_node( 'CONTRACT.DISP_EKKO' ).

    lo_nd_snode_1->bind_table( it_EKKO ).

 endif.



  DATA lo_nd_disp_ekpo TYPE REF TO if_wd_context_node.
  DATA lo_el_disp_ekpo TYPE REF TO if_wd_context_element.
  DATA ls_disp_ekpo TYPE wd_this->element_disp_ekpo.
* navigate from <CONTEXT> to <CONTRACT> via lead selection
  lo_nd_contract = wd_context->get_child_node( name = wd_this->wdctx_contract ).

* navigate from <CONTRACT> to <DISP_EKPO> via lead selection
  lo_nd_disp_ekpo = lo_nd_contract->get_child_node( name = wd_this->wdctx_disp_ekpo ).

* @TODO handle not set lead selection
  IF lo_nd_disp_ekpo IS INITIAL.
  ENDIF.

* get element via lead selection
  lo_el_disp_ekpo = lo_nd_disp_ekpo->get_element(  ).

* @TODO handle not set lead selection
  IF lo_el_disp_ekpo IS INITIAL.
    lo_el_disp_ekpo = lo_nd_disp_ekpo->create_element( ).
  ENDIF.

data: lo_nd_snode_2 TYPE REF TO if_wd_context_node,
      IT_EKPO TYPE standard table of  EKPO.


select * from EKPO into table it_EKPO WHERE EBELN = ls_mandt_ekko-EBELN.
   if sy-subrc eq 0.


    lo_nd_snode_2 = wd_context->path_get_node( 'CONTRACT.DISP_EKPO' ).

    lo_nd_snode_2->bind_table( it_EKPO ).


  ENDIF.


endmethod.

****************************************************

when i execute got that error.any help highly appreciated.

regards,

vinoth.

Edited by: Thomas Jung on Aug 10, 2009 8:10 AM

abhimanyu_lagishetti7
Active Contributor
0 Kudos

Hi

DISP_EKKO and DISP_EKPO are Nodes Under the CONTRACT node.

Remove the stmt

lo_nd_snode_1 = wd_context->path_get_node( 'CONTRACT.DISP_EKKO' ).

lo_nd_snode_1->bind_table( it_EKKO ).

And get lo_nd_snode_1 from lo_el_contract using get_child_node method.

lo_el_contract = lo_nd_contract->get_element( ).

lo_nd_snode_1 = lo_el_contract->get_child_node( wd_this->wdctx_disp_ekko ).

Abhi

Edited by: Abhimanyu Lagishetti on Aug 10, 2009 8:17 AM

Former Member
0 Kudos

hi,

i dont have any elements in my root node(contract). i hav only sub nodes in that. so getting error when using ur code.

the error is "lo_el_contract does not exist. Similar existence is lo_nd_contract.."

my context:

> contract(1:1)(root node)

>mandt_ekko(1:1)

>disp_ekko(0:n)

>disp_ekpo(0:n)

i have 2 internal table and have to bind that to disp_ekko and disp_ekpo.

gettin error: "acess via null object reference not possible"

regards,

vinoth.

Edited by: SAP_TECHY04 on Aug 10, 2009 10:37 AM

abhimanyu_lagishetti7
Active Contributor
0 Kudos

you can directly use

lo_nd_snode_1 = lo_nd_contract->get_child_node( wd_this->wdctx_disp_ekko ).

Former Member
0 Kudos

This message was moderated.

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos

Please tell us exactly where the error is being triggered from. What is the initial object? Is it lo_nd_contract? Or lo_nd_mandt_ekko?

Please tell us more about your context structuree as well. What are the Singleton values for each node?

Former Member
0 Kudos

hi thomas,

my context:

> contract(root node, 1:1)

>mandt_ekko(node,0:n ,singleton = yes)

ebeln(element)

>disp_ekko(node,0:n,singleton =yes)

elements...from ekko table

>disp_ekpo(node,0:n,singleton= yes)

elements..from ekpo table

based on ebeln(node mandt_ekko) entered .i have to fetch two database table ekko and ekpo and put in internal table and bind that to disp_ekko and disp_ekpo.

internal table:

it_ekko type standard table of ekko.

select * from ekko into table it_ekko where ebeln = ls_mandt_ekko-EBELN.

and binded it_ekko to context disp_ekko.

similarly for ekpo.

expecting help ful answer.

regards,

vinoth.

Former Member
0 Kudos

Hi,

Are you showing the purchase orders (EBELN) in a dropdown or it's just an input field with any standard SH.

Regards,

Lekha.

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos

You still haven't said where the null object occurs. When you debug, which object is null. I don't like looking for a neddle in a haystack (and the SDN Forum loss of formatting and line breaks on long posts doesn't help any).

uday_gubbala2
Active Contributor
0 Kudos

Try go through this [pdf |https://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/60730016-dbba-2a10-8f96-9754a865b814]for more information about how you can work with context nodes and attributes. Its a very small document but it does help equip you with all the basic fundamentals for working with context.

Regards,

Uday

Former Member
0 Kudos

hi all,

i am still facing the problem.pls help me out.

uday_gubbala2
Active Contributor
0 Kudos

Hi,

Have you actually fetched the reference of your context node properly? You need to have obtained the reference of your context node using GET_CHILD_NODE & then use the BIND_TABLE method up on this fetched reference. Just check if you are obtaining the reference correctly. Is it something like you are trying to bind an internal table which is not directly present under the root node but as a subnode of another node? If this is the case then ensure that you obtain the reference of your subnode correctly.

You can follow 2 approaches for retrieving your subnodes reference:

DATA lo_nd_node1 TYPE REF TO if_wd_context_node,
           lo_nd_snode_2 TYPE REF TO if_wd_context_node.
 
 lo_nd_node1 = wd_context->get_child_node( name = 'NODE_1' ).
 
lo_nd_snode_2 = lo_nd_node1->get_child_node( name = 'NODE_2' ).

Or

lo_nd_snode_2 = wd_context->path_get_node( 'NODE_1.NODE_2' ).

Regards,

Uday