Skip to Content
avatar image
Former Member

Getting null reference when i declare element?

HI,

When i am declaring node and its element i am not getting proper reference. so when i use that element to access any method , it give null pointer error.

like,

my context got through service call , is like:

ZBAPI_FORWARD_WOR_1->node

IMPORTING_1 ->node

PERNR -> attribute

CHANGING_1 ->node

TT_WWID ->node

wi_id -> attribute

TT_WWID is table in bapi having cardianality 0..N

when i declare in code:

DATA:

NODE_ZBAPI_FORWARD_WOR_1 TYPE REF TO IF_WD_CONTEXT_NODE,

NODE_CHANGING_1 TYPE REF TO IF_WD_CONTEXT_NODE,

NODE_TT_WIID TYPE REF TO IF_WD_CONTEXT_NODE,

ELEM_TT_WIID TYPE REF TO IF_WD_CONTEXT_ELEMENT,

STRU_TT_WIID TYPE IF_MAIN=>ELEMENT_TT_WIID .

NODE_ZBAPI_FORWARD_WOR_1 =

WD_CONTEXT->GET_CHILD_NODE( NAME = IF_MAIN=>WDCTX_ZBAPI_FORWARD_WOR_1 ).

NODE_CHANGING_1 =

NODE_ZBAPI_FORWARD_WOR_1->GET_CHILD_NODE( NAME = IF_MAIN=>WDCTX_CHANGING_1 ).

NODE_TT_WIID =

NODE_CHANGING_1-GET_CHILD_NODE( NAME = IF_MAIN=>WDCTX_TT_WIID ).

ELEM_TT_WIID = NODE_TT_WIID->GET_ELEMENT( ).

CALL METHOD ELEM_TT_WIID->SET_ATTRIBUTE

EXPORTING

VALUE = ITEM_WI_ID

NAME = 'WI_ID'.

I am not getting any refrence in elem_tt_wiid.....so i am getting error when access method set_attribute......

any idea?

thanks,

saurin shah.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

3 Answers

  • avatar image
    Former Member
    Sep 25, 2008 at 09:45 AM

    Hi saurin,

    Since u made the cardinality 0..n, the element will not be instantiated. So use create element method instead of get_element. First create a element and try to set the value to the created element.

    Regards...

    Arun.

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      hi saurin,

      Check the child_node declaration part.

      The code seems to be gud. I couldn't see any problem in that.

      Check the table properties in the layout.

      it is not required to pass as STRU_C_WORKITEM[].

      NODE_WORKITEM->BIND_TABLE( STRU_C_WORKITEM ).

      Regards...

      Arun.

  • avatar image
    Former Member
    Sep 25, 2008 at 09:27 AM

    Hi Saurin,

    NODE_ZBAPI_FORWARD_WOR_1 =

    WD_CONTEXT->GET_CHILD_NODE( NAME = IF_MAIN=>WDCTX_ZBAPI_FORWARD_WOR_1 ).

    instead writing like ablove you can use node name directly.

    NODE_ZBAPI_FORWARD_WOR_1 = 
    WD_CONTEXT->GET_CHILD_NODE( ' ZBAPI_FORWARD_WOR_1' ).

    if you want to read the sub node tt_wid directly you can use this method.

    NODE_TT_WIID = wd_context->path_get_node('NODE_ZBAPI_FORWARD_WOR_1.NODE_CHANGING_1.NODE_TT_WIID').

    thanks

    Suman

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      Hi Saurin,

      ELEM_TT_WIID = NODE_TT_WIID->GET_ELEMENT( ).
      
      CALL METHOD ELEM_TT_WIID->SET_ATTRIBUTE
      EXPORTING
      VALUE = ITEM_WI_ID
      NAME = 'WI_ID'.

      your code is correct nothing wrong there.I want to know how many attributes you have under the node node_tt_wiid.

      you can also write like this ...

      if you want to set the value to first attribute of node.

      ELEM_TT_WIID = NODE_TT_WIID->GET_ELEMENT( 1 ).

      CALL METHOD ELEM_TT_WIID->SET_ATTRIBUTE

      EXPORTING

      VALUE = ITEM_WI_ID

      NAME = 'WI_ID'.

      ( OR )

      l_node = wd_context->get_child_node( 'NODE1' ).

      l_node->set_static_attributes( static_attributes = l_my_struc ).

      thanks

      Suman

  • avatar image
    Former Member
    Oct 10, 2008 at 06:58 AM

    by self

    Add comment
    10|10000 characters needed characters exceeded