cancel
Showing results for 
Search instead for 
Did you mean: 

calling Context node method in Implementation class mtethod

Former Member
0 Kudos

Hi Experts

I have created a new method(not attribute method) in the context node class to have some common code for my requirement. Now I want call this method in Event Handler of the IMPL class.  My code in Event Handler is below

DATA: lr_node TYPE REF TO ZL_BP_HEAD1_MAINSEARCH_IMPL.


CALL METHOD lr_node->zcustom_method

*  EXPORTING

*    attribute_path =  attribute_path

*    iterator       =

         RECEIVING

           value          = lv_value  

I am not getting the value in lv_value.

Please help me to call  Context node Zmethod in Implementation class mtethod.

Thanks

Dinesh Sing

Accepted Solutions (1)

Accepted Solutions (1)

VishnAndr
Active Contributor
0 Kudos

Hello, Dinesh Sing.

Do you get a dump or an exception with your code? Because I think that lr_node should be not bound as far as you do nothing to initialize (bound) it.

Do you want to call an instance method or a static one?

Former Member
0 Kudos

I want to call an instance method.

VishnAndr
Active Contributor
0 Kudos

So does lr_node have any values in debugger? Or is it just initial?

Former Member
0 Kudos

It is initial in debug at event handler method. But the same zcontext method is returning value in the methods of the same context class.

I want this context custom methods return value to be available in event handler.

VishnAndr
Active Contributor
0 Kudos

Right, because in context node class you are in instance itself. And everything is fine there.

Actually why is lr_node TYPE REF TO some ...._IMPL class? In general ..._IMPL class is a class of view controller. And context node class is with _CNyy postfix (where yy - some digits).

I'd suggest to try such a code:

METHOD EH_ONSOMEEVENT. "your event handler method

     DATA: lr_node TYPE REF TO Zxxxxxx_CN01. "reference to your context node class. CN01 is just an example.

     lr_node ?= me->typed_context->name_of_context_node->collection_wrapper->get_current( ).

* you can try this. Instead of name_of_context_node put your context node name

* if it's still initial try me->ztyped_context....

     CALL METHOD lr_node->zcustom_method 

      *  EXPORTING 

      *    attribute_path =  attribute_path 

      *    iterator       =

         RECEIVING 

           value          = lv_value   .

ENDMETHOD.

Hope this will help you.

Former Member
0 Kudos

ztyped_context is suitable I think. I have tried with above code, I am getting an Exception (CX_SY_NO_HANDLER occured) at the below  line in debug.

lr_node ?=  me->ztyped_context->node->collection_wrapper->get_current( ).

what observed is I think only Context node attribute methods can be accessed in the IMPL class methods. If it is true then I have to replace my custom method with any GET method of the existing/new attribute in the Node.

VishnAndr
Active Contributor
0 Kudos

Actually, Dinesh, I've made a mistake. My bad.

If you need to get context node class itself (not the entity of a collection there) then simply use:

lr_node ?= me->ztyped_context->node.

Former Member
0 Kudos

Great.  Thats true. Thanks Andrei

Answers (0)