cancel
Showing results for 
Search instead for 
Did you mean: 

Getting null reference when i declare element?

Former Member
0 Kudos

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.

Accepted Solutions (0)

Answers (3)

Answers (3)

Former Member
0 Kudos

by self

Former Member
0 Kudos

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.

Former Member
0 Kudos

Hi arun,

i did as u said.

Very helpful u r answer was...

will u tell me one thing pleaze , when i am having table with selection mode - multi . and the context node which binds to table having property , Cardinality 0...N & Selection 0...N to have multi selection on table.. but when i execute application, i can make multiple selection and data also comes to table bt it doesnt disply on table. at the end of table it shows no. of rows, there it shows how many data r there... so is there any idea........

Thanks,

saurin

Former Member
0 Kudos

Hi saurin,

whether u r using bind_table method to bind the elements to the table? If not do that.

Provide ur code, which would be easy to find out the problem.

Regards....

Arun.

Former Member
0 Kudos

HI ARUN,

METHOD EXECUTE_ZBAPI_CREATE_WORKITEML .

  • declarations for context navigation

DATA:

NODE_ZBAPI_CREATE_WORKITE TYPE REF TO IF_WD_CONTEXT_NODE.

DATA:

NODE_CHANGING TYPE REF TO IF_WD_CONTEXT_NODE.

DATA:

NODE_WORKITEM TYPE REF TO IF_WD_CONTEXT_NODE.

DATA:

NODE_IMPORTING TYPE REF TO IF_WD_CONTEXT_NODE.

DATA:

LRI_ELEMENT TYPE REF TO IF_WD_CONTEXT_ELEMENT,

LOA_ELEMENTS TYPE WDR_CONTEXT_ELEMENT_SET.

  • declarations for fuba parameters

DATA:

ATTR_PERNR TYPE PA0001-PERNR.

DATA:

COPY_C_WORKITEM TYPE IF_COMPONENTCONTROLLER=>ELEMENTS_WORKITEM,

STRU_C_WORKITEM TYPE IF_COMPONENTCONTROLLER=>ELEMENTS_WORKITEM,

ITAB_C_WORKITEM LIKE LINE OF STRU_C_WORKITEM.

  • get all involved child nodes

NODE_ZBAPI_CREATE_WORKITE = WD_CONTEXT->GET_CHILD_NODE( `ZBAPI_CREATE_WORKITE` ).

NODE_CHANGING = NODE_ZBAPI_CREATE_WORKITE->GET_CHILD_NODE( `CHANGING` ).

NODE_WORKITEM = NODE_CHANGING->GET_CHILD_NODE( `WORKITEM` ).

NODE_IMPORTING = NODE_ZBAPI_CREATE_WORKITE->GET_CHILD_NODE( `IMPORTING` ).

CLEAR LOA_ELEMENTS. REFRESH LOA_ELEMENTS.

  • get input from context

NODE_IMPORTING->GET_ATTRIBUTE(

EXPORTING

NAME = `PERNR`

IMPORTING

VALUE = ATTR_PERNR ).

******THIS IS MY BAPI GIVE ME OUTPUT************

CALL FUNCTION 'ZBAPI_CREATE_WORKITEMLIST'

EXPORTING

PERNR = ATTR_PERNR

TABLES

WORKITEM = STRU_C_WORKITEM .

NODE_WORKITEM->BIND_TABLE( STRU_C_WORKITEM[] ).

ENDMETHOD.

THANKS,

SAURIN SHAH

Former Member
0 Kudos

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.

Former Member
0 Kudos

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

Former Member
0 Kudos

HI SUMAN,

when i declare node as u asked i am getting right reference in that bt when i decalre element for that through get_element( ) , i am not getting right reference so i cant use it further . i am getting null object reference error.

thanks,

saurin shah

Former Member
0 Kudos

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