cancel
Showing results for 
Search instead for 
Did you mean: 

How to call method of Component A in Component B

former_member222068
Active Participant
0 Kudos

Hi Friends,

I want to use Method A of Component A in Component B. Can some one tell me how to call method A on action of a button in component B.

Regards

Sankar

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Have you declared Comp A as a component usage in Comp B.

In the COMP A, make the methods as Interface methods there will be a check box.

Inside the Comp B, instantiate the Comp A, using the instance you can call those methods of Comp A inside Comp B on the button action. you can instatiate the usage usign the code wizard.

former_member222068
Active Participant
0 Kudos

Hi Lekha,

k fine thank you. Now calling method is same as calling assistance class. is it right or any other way

regards

sankar

Former Member
0 Kudos

>

> Hi Lekha,

>

> I know how to create interface node, but can you tell me whether do i find check box to mark method as a interface method.

>

>

> regards

> sankar

Hi Sankar,

Yes, only interface methods are available outside the component visible for cross component communication.

Former Member
0 Kudos

Hi Sankar,

In the component contoller, Methods tab: For each of the Method, there will be a check box to mark it as interface method.

You have to check the same for your usecase.

Best Regards,

Srilatha

gill367
Active Contributor
0 Kudos

>

> Hi Lekha,

>

> k fine thank you. Now calling method is same as calling assistance class. is it right or any other way

>

>

> regards

> sankar

yup kind of similar to that

You need to create the controller usage of the interface controller for the used comp A in view or comp controller where you

want ot use it and then call interface method by instatiating the interface controler first and then calling method using this method.

former_member222068
Active Participant
0 Kudos

Hi,

Do i need to create method A ( interface method ) in component controller-method tab or Method A can be created in View or not.

Former Member
0 Kudos

Hi Shankar,

View methods are private, you cannot see them outside the view. Create a method in component controller and check the interface checkbox.

former_member222068
Active Participant
0 Kudos

Hi,

Can you give me a sample code for calling interface method.

Former Member
0 Kudos

You have a Code generator in Webdynpro (CTRL + f7). For any place in your code call this tool, go to the second tab, select the second radio button.

Select the used component,method. It will generate code for you.

gill367
Active Contributor
0 Kudos

You can generate the code using the code wizard.

firs tyou need to add the interface controler of the comp A in the used controllers list of view or comp controler where ever

you want to call

here is the sample code

*create the usage of comp A
data lo_cmp_usage type ref to if_wd_component_usage.

lo_cmp_usage =   wd_this->wd_cpuse_COMPA( ).
if lo_cmp_usage->has_active_component( ) is initial.
  lo_cmp_usage->create_component( ).
endif.

*call the interface controller of comp A

DATA lo_INTERFACECONTROLLER TYPE REF TO ZIWCI_SSG_FEB_EXPL7 .
lo_INTERFACECONTROLLER =   wd_this->wd_cpifc_COMPA( ).

  lo_interfacecontroller->method1(
  ).

former_member222068
Active Participant
0 Kudos

Hi,



  DATA lo_cmp_usage TYPE REF TO if_wd_component_usage.

  lo_cmp_usage =   wd_this->wd_cpuse_method( ).
  IF lo_cmp_usage->has_active_component( ) IS INITIAL.
    lo_cmp_usage->create_component( ).

  ENDIF.


DATA lo_interfacecontroller TYPE REF TO yiwci_sg_method .
lo_interfacecontroller =   wd_this->wd_cpifc_method( ).

  lo_interfacecontroller->execute_method( 
  ).

i was able to do the above process successfully but how to bind data to the node of component 2.

In the component 1 : method A i defiend to get records upto 25 rows. now i tried using same method . but how to bind data using this method

Regards

sankar

Former Member
0 Kudos

Hi ,

To set the context node of used component , either make the context node as interface node and set it in the component which used it.

Or write a method which sets the data in the used component and call that method and pass the data as exporting paramaters.

Thanks,

Aditya.

former_member222068
Active Participant
0 Kudos

I thank one and all for giving me inputs,

Hence closing Thread

Regards

Sankar

Answers (0)