cancel
Showing results for 
Search instead for 
Did you mean: 

Getting values from a function module called in a WDA method

Former Member
0 Kudos

Friends,

I am trying to execute a function module from WDA.

I have created a service call for the function module. The function module takes values from the user, looks up the corresponding values of another field and returns the values in an internal table.

I am using the "Method Call in Used Controller" of WD Code wizard to call the function module.

When the event handler method containing the call to the function module is executed, nothing happens.

I am not sure how to pass values to the function module and to get the return values from the function module.

I am new to using function modules from WDA. Please help me out.

Thanks and Regards.

Accepted Solutions (1)

Accepted Solutions (1)

alejandro_bindi
Active Contributor
0 Kudos

Lets see, I think you're mixing a few things up.

Using function modules from WDA is no different that normal ABAP.

First, when you went through the service call wizard you specified a function module...in there, you were given the option to choose whether the function parameters should be either a) context attributes b) controller attributes or c) method parameters.

From the coding you posted I can assume a few things: You either chose options a) or b), and chose the COMPONENTCONTROLLER as the controller to hold the service call.

So, you should go to the COMPONENTCONTROLLER and look for the FN_MODULE_NAME method coding, where the actual function module call should be. In the same controller you should have either some Context nodes or controller Attributes for each corresponding function parameters.

So, the calling order is:

Event handler -> Component controller's Method ("service call") -> Function module

What you may be lacking, is the mapping of the COMPONENTCONTROLLER's context to the VIEW with the event you're calling the service from, that way there's no need to pass parameters as they flow from the view context (what the user has on screen) to the controller's context.

You could also add parameters yourself to method FN_MODULE_NAME and then specify them in the calling.

Whoa, wrote a bit. I hope you got it.

You have this tutorial also which does a service call:

https://www.sdn.sap.com/irj/sdn/nw-development?rid=/library/uuid/9cb5d345-0801-0010-6a8e-fc57c23fd60...

Regards

Edited by: Alejandro Bindi on Oct 10, 2008 2:32 AM

Former Member
0 Kudos

Alejandro,

I have created a service call to a function module using the exising component controller of the WDA. I am calling a function module that fills a context node with a table of values.

I have done context mapping of this node to another node in a view context.

I am unable to read the table of values from the view context node that is mapped to the node in the component controller. I am only able to read the first value.

Please let me know what is missing.

Thanks and Regards

Former Member
0 Kudos

Alejandro,

Another way to ask this question is:

How to bind a set of values from one context to another using context mapping. I know how to do for a single value for a single attribute. I dont know how to do for a set of values for a single attribute.

Please let me know what is missing.

Thanks and Regards.

Former Member
0 Kudos

Hi,

How did you map the view context to componentcontroller context ??

You can drag and drop the componentcontroller context onto view context and map so that you should see all the values in the componentcontroller context in viewcontext.

Anil

Edited by: Anilkumar Vippagunta on Oct 14, 2008 1:11 AM

alejandro_bindi
Active Contributor
0 Kudos

As Anilkumar said, stepping into the view context, drag a component controller's context node to the left, and it should be mapped including properties as cardinality. That is, if the node is defined e.g. 1..n in the component controller, by mapping it this way to the view it will inherit the 1..n cardinality also...

Binding refers to the relation between UI elements and the context in the same controller. The relationship between contexts is called mapping not binding.

Please, use the debugger in the Web Dynpro mode to debug the context values...

Former Member
0 Kudos

Thank you for your replies. I am aware of the difference between context mapping and data binding.

My question is how to map a table of values from one context to another. I have created identical context nodes and mapped them ie from view context to component controller context.

I am not able to define attributes as types of table types.i can only define them as types of structures. Let me know if changing the cardinality will help in this issue.

Thanks and Regards.

Former Member
0 Kudos

I am assuming a couple of things here

1)There is a method in the component controller which is actually making a call to the function module (This exactly what the service call does)

2)The service calls also creates nodes corresponding to the input and output parameters

I understand that the output/return parameter pertaining to the function module is a table. The node is always associated with a structure. If the node would hold a single row or multiple is determined by its cardinality. In this case verify that the cardinality of the corresponding node is either 0:n or 1:n

3)You mapped the context nodes thus created from the component controller to the view controller

Now your issue is that, when you try to read the context node in the view controller, you are getting only a single row

Verify a couple of things:

1) As I mentioned, check the cardinality of the node in the component controller

2) Verify if you are binding the internal table returned by the internal table to the results node as


node->set_static_attributes_table( it_result ).

Hope this helps

Best Regards,

Rashmi.

Former Member
0 Kudos

Rashmi,

1) I have changed the cardinality of the nodes in component controller to 1:n

2) The internal table is being bound to the node as:

lo_i_grde->bind_table( lt_c_i_grde[] ).

Is this code correct.

The main issue is in reading the table of values from the view context attribute.

Is there any way i can loop the context attribute, reading the values one by one. or is there an alternate way.

Does the 'selection' value help in any way. I have set the values for selection to '1:n' similar to cardinality.

Thanks and Regards.

Former Member
0 Kudos

The paranthesis [] is not required while providing the internal table as a parameter to the bind_table method. I am not sure if that will make a difference though.

Put a breakpoint in the method of the component controller which calls the function module and verify the value of lt_c_i_grde. (Again I am assuming that its in the component controller method that you are calling lo_i_grde->bind_table( lt_c_i_grde[] ). )

Also, I believe the above component controller method is being called from some method in the view controller. In this method, put a breakpoint at the call of the comp controller method. After the execution of the comp controller method call , put the code

lt_2 = <<view_controller_node>> ->get_static_attributes_table( )

(code}

and verify the value of the resulting internal table.

Verify if lt_c_i_grde = lt_2.

alejandro_bindi
Active Contributor
0 Kudos

With method IF_WD_CONTEXT_NODEBIND_TABLE you're binding a set of entries in an internal table to a node with multiple cardinality. So, with method IF_WD_CONTEXT_NODEGET_STATIC_ATTRIBUTES_TABLE you can do the opposite: retrieve that set of values into an internal table. You can then loop that table, which will have all the node attributes including the one you want the values from...is that what you need?

Edited by: Alejandro Bindi on Oct 14, 2008 3:24 PM

Answers (3)

Answers (3)

Former Member
0 Kudos

Resolved

Former Member
0 Kudos

Friends,

I am trying to pass input value back to the function module as its input parameter.

The context node is mapped to the component controller node from where i get a table of values and am able to read the values using get_static_attributes_table method.

Since the input parameter is defined as a context node, i am setting the value to the context attribute using set_attribute method.

But the input value is not getting passed from view context to component controller context.

Let me know what is missing.

Thanks and Regards.

Former Member
0 Kudos

I am a little confused as to what you are trying to achieve.

Is this what you are trying :

Is the function module intended to collect input data from the UI and process it?

If yes, then the input (importing parameter) to the Function Module is a table of values (which should be ideally from the context mapped to the Table UI Element). Now this table UI Element is bound to the view controller context , which in turn is mapped to the component controller context. And you are indeed being able to read the value of this internal table in the component controller method where the function module is being called by means of get_static_attributes_table (Is this right? Or are you being able to read it in the event handler method of the view controller and not being able to read it in the component controller method)

Now I am completely clueless as to what the set_attribute is doing? Are you calling this on an element of the context node? This would just set the value of one of the attributes of the context element.

(As an analogy, what you are trying to do is trying to set a value for a column in the internal table , for a single record of the table) Do correct me if my interpretation of the issue is wrong.

Former Member
0 Kudos

Rashmi,

Is the function module intended to collect input data from the UI and process it? - Yes

If yes, then the input (importing parameter) to the Function Module is a table of values (which should be ideally from the context mapped to the Table UI Element). - The importing parameter is a single value NOT a table and is mapped to the view context.

Now this table UI Element is bound to the view controller context , which in turn is mapped to the component controller context. And you are indeed being able to read the value of this internal table in the component controller method where the function module is being called by means of get_static_attributes_table (Is this right? - Yes, I am able to read the table of values that is passed from the component controller view to form view context by using get_static_attributes_table.

Or are you being able to read it in the event handler method of the view controller and not being able to read it in the component controller method) -

The function module takes a single value as import parameter and returns a table of values as return value.

It works fine when no importing parameter is being used and returns the table of values that is getting passed from component controller context to form view context when i am able to read it using get_static_attributes_table.

Now the question is: how to pass the import parameter value to the function module. I assumed since the importing parameter is a context node (like the return values are), i should set the value ( captured when the user enters the value in the form) to the importing parameter context attribute using set_attribute method. Since it is mapped to the component controller context, i assumed it will get passed and the method will take it as input parameter.

Let me know if my assumptions are correct regarding passing the import parameters and what is missing here.

Thanks and Regards.

Former Member
0 Kudos

I get you now.

You need not do anything towards 'setting' the value in the context node attribute corresponding to the input.

The moment you bind the context node attrubute to value of the UI Element , as soon as the user inputs a value in this UI Element in the form, the same is automatically set/captured in the context element attribute. Now your task is just to read the value thats associated with the context element attribute and pass it on as the importing parameter to the function module.

Just before you call the Function Module in the Component Controller method, do this:


lo_nd = wd_context->get_child_node( name = wd_this-><<context node corresponding attribute bound to the UI Element>> ).
lo_el = lo_nd->get_element(  ).

  lo_el->get_attribute(
    EXPORTING
      name =  `<<attribute name bound to the UI Element>>`
    IMPORTING
      value = lv_value).

Pass the lv_value to the importing parameter of the Function Module .

Former Member
0 Kudos

This is the code to call the function module from the event handler method:

DATA lo_COMPONENTCONTROLLER TYPE REF TO IG_COMPONENTCONTROLLER .

lo_COMPONENTCONTROLLER = wd_this->get_componentcontroller_ctr( ).

lo_componentcontroller->fn_module_name(

).

Thanks and Regards.