cancel
Showing results for 
Search instead for 
Did you mean: 

Get the return value of an RFC function / BAPI

Former Member
0 Kudos

Hello,

I'm a Web Dynpro Java beginner and I try to get the return value (domain: NUMC6) of an RFC function without success.

Here is what I do, could you please tell me what is wrong?

First, here is my context:

Context
|
|---- ZMy_Bapi
	|
	|---- MyOutputResult
	|	|
	|	|---- MyReturnValue
	|
	|---- MyInput

My model:


MyModel
|
|---- ZMy_Bapi_Input
	|
	|---- Output
	|	|
	|	|---- ZMy_Bapi_Output
	|		|
	|		|---- Return_Value
	|
	|---- Input_Value

The mapping between them:

- MyInput is mapped to Input_Value

- MyReturnValue is mapped to Return_Value

And my code:


ZMy_Bapi_Input bapiInput = new ZMy_Bapi_Input();
wdContext.nodeZMy_Bapi().bind(bapiInput);

bapiInput.setInput_Value("A value");

executeZMy_Bapi();

ZMy_Bapi_Output bapiOutput = new ZMy_Bapi_Output();
wdContext.nodeMyOutputResult().bind(bapiOutput);
IMyOutputResultElement outputElement = wdContext.nodeMyOutputResult().currentMyOutputResultElement();

String result = outputElement.getMyReturnValue();

Finally, here is the code of the executeZMy_Bapi() function:


try {
	wdContext.currentZMy_BapiElement().modelObject().execute();
	wdContext.nodeMyOutputResult().invalidate();
} catch (Exception ex) {
	ex.printStackTrace();
}

My problem is that "result" keeps being empty

Thanks in advance for your help!

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

HI.

I assume this is your model node structure.

MyModel

|


ZMy_Bapi_Input


Output


ZMy_Bapi_Output


Return_Value

|---- Input_Value

for(int i=0; i<wdContext.nodeZMy_Bapi_Output().size();i++)

{

String result = wdContext.nodeZMy_Bapi_Output().getZMy_Bapi_OutputElementAt(i).getReturn_Value();

}

and your execute method:

try {

wdContext.currentZMy_Bapi_Input().modelObject().execute();

wdContext.nodeZMy_Bapi_Output().invalidate();

} catch (Exception ex) {

ex.printStackTrace();

}

Regards,

Murtuza

Former Member
0 Kudos

Thanks again for your help.

If I use wdContext.nodeZMy_Bapi_Output().getZMy_Bapi_OutputElementAt(i), I have access to the getInput_Value method, but not the getReturn_Value one.

I don't understand why, it doesn't sound not logical for me.

Former Member
0 Kudos

HI,

I would request you to send me the exact context strucure once again that you get when you drag the input model node to your controller. Send me the exact context strucute once again so that I can help you.

Regards,

Murtuza

Former Member
0 Kudos

Here are my context and model again, but maybe I don't understand what you want me to send you?


Context
|
|---- ZMy_Bapi
	|
	|---- MyOutputResult
	|	|
	|	|---- MyReturnValue
	|
	|---- MyInput


MyModel
|
|---- ZMy_Bapi_Input
	|
	|---- Output
	|	|
	|	|---- ZMy_Bapi_Output
	|		|
	|		|---- Return_Value
	|
	|---- Input_Value

Edited by: Franis Pignon on Oct 17, 2008 8:59 PM

Former Member
0 Kudos

HI,

Could you see one more level or hierarchy in your model compared to your cotext. If you keep your context names same to that of the model nodes name then you need to loop through the ZMy_BAPI_Output node and use the code as mentioned above.

NOTE: Goto the last level of node under the ouput node within the input node(ie within. ZMy_Bapi_Input node) and loop through it as this is the node that contains the output result.

Regards,

Murtuza

Former Member
0 Kudos

I don't really understand what's wrong with my context or modelu2026 I know there is one more level hierarchy in my model, I just followed [this tutorial|https://www.sdn.sap.com/irj/sdn/adobe?rid=/library/uuid/a00f7103-6790-2a10-ac9c-fcac7c5b18a3], so I guess that is the way it should beu2026

The other thing I don't understand is why if I use wdContext.nodeZMy_Bapi_Output().getZMy_Bapi_OutputElementAt(i), I have access to the getInput_Value method, but not the getReturn_Value one.

Edited by: Franis Pignon on Oct 17, 2008 9:59 PM

Former Member
0 Kudos

HI,

If you go to your data modeler and select the link between model and the controller and drag ZMy_Bapi_Input from model to controller then what all nodes have you mapped? I guess that you have mapped something wrong. If possible then remap this thing and select all the nodes that you find under ZMy_Bapi_input node and then follow the steps.

Regards,

Murtuza

Former Member
0 Kudos

Hi,

Here is the detailed mapping:


ZMy_Bapi	--> ZMy_Bapi_Input
MyOutputResult	--> Output
MyReturnValue	--> Return_Value
MyInput		--> Input_Value

And the ZMy_Bapi_Output Node of the model is NOT mapped to anything in the context. Maybe the problem comes from this?

I really appreciate your help.


Context
|
|---- ZMy_Bapi
	|
	|---- MyOutputResult
	|	|
	|	|---- MyReturnValue
	|
	|---- MyInput


MyModel
|
|---- ZMy_Bapi_Input
	|
	|---- Output
	|	|
	|	|---- ZMy_Bapi_Output
	|		|
	|		|---- Return_Value
	|
	|---- Input_Value

Edited by: Franis Pignon on Oct 17, 2008 10:34 PM

Former Member
0 Kudos

Yes sir,

Now you got me correctly, you have not mapped the node that is holding the data

Regards,

Murtuza

Former Member
0 Kudos

It still doesn't work, I'm gonna turn crazy!

But there is one good point: I get the method you mentioned: getZMy_Bapi_OutputElementAt and getMyReturnValue without casting, just as you said first.

Here are the updated context, model, mapping and code.

Context:


MyContext
|
|---- ZMy_Bapi
	|
	|---- MyOutputResult
	|	|
	|	|---- ZMy_Bapi_Output
	|		|
	|		|---- MyReturnValue
	|
	|---- MyInput

Model:


MyModel
|
|---- ZMy_Bapi_Input
|	|
|	|---- Output
|	|	|
|	|	|---- ZMy_Bapi_Output
|	|		|
|	|		|---- Return_Value
|	|
|	|---- Input_Value
|
|
|---- ZMy_Bapi_Output
	|
	|---- Return_Value

Mapping


ZMy_Bapi	--> ZMy_Bapi_Input
MyOutputResult	--> Output
ZMy_Bapi_Output	--> ZMy_Bapi_Output
MyReturnValue	--> Return_Value
MyInput		--> Input_Value

Code


ZMy_Bapi_Input bapiInput = new ZMy_Bapi_Input();
wdContext.nodeZMy_Bapi().bind(bapiInput);

bapiInput.setInput_Value("A value");

executeZMy_Bapi();

ZMy_Bapi_Output bapiOutput = new ZMy_Bapi_Output();
wdContext.nodeMyOutputResult().bind(bapiOutput);

String result = "";

for (int i = 0; i < wdContext.nodeZMy_Bapi_Output().size(); i++) {
	IZMy_Bapi_OutputElement resultElem = wdContext.nodeZMy_Bapi_Output().getZMy_Bapi_OutputElementAt(i);
	if (resultElem.getMyReturnValue() != "" && resultElem.getMyReturnValue() != null) {
		result = resultElem.getMyReturnValue();
	}
}

Edited by: Franis Pignon on Oct 17, 2008 11:16 PM

Former Member
0 Kudos

Hi,

Hope in your execution method, you are executing ZMy_Bapi.

You can print the input that you are giving to the bapi using the following statement:

wdComponentAPI.getMessageManager().reportSuccess(wdContext.nodeZMy_Bapi().modelObject().toString());

Regards,

Murtuza

Former Member
0 Kudos

Here is my executeZMy_Bapi method:


try {
	wdContext.currentZMy_BapiElement().modelObject().execute();
	wdContext.nodeMyOutputResult().invalidate();
} catch (Exception ex) {
	ex.printStackTrace();
}

And here is the result of the reportSuccess method:


 mypackage.model.ZMy_Bapi_Input@377445b8

Edited by: Franis Pignon on Oct 18, 2008 2:12 AM

Former Member
0 Kudos

The problem is that wdContext.nodeZMy_Bapi_Output() is empty: wdContext.nodeZMy_Bapi_Output().size() = 0

Any idea of the reason why it is empty?

Answers (3)

Answers (3)

Former Member
0 Kudos

what error you are getting? while executing the RFC...

Former Member
0 Kudos

No Need to write these 2 lines

ZMy_Bapi_Output bapiOutput = new ZMy_Bapi_Output();

wdContext.nodeMyOutputResult().bind(bapiOutput);

Former Member
0 Kudos

Thanks, I deleted these lines.

But it still doesn't work: I still have wdContext.nodeZMy_Bapi_Output().size() = 0

Former Member
0 Kudos

I check and my BAPI is NOT called. What could be the reason?

Former Member
0 Kudos

Hi,

In order to get the output, you have to loop around your output node:

for(int i=0; i<wdContext.nodeMyOutputResult().size();i++)

{

String result = wdContext.nodeMyOutputResult().getMyOutputResultElementAt(i).getMyReturnValue();

}

Regards,

Murtuza

Former Member
0 Kudos

Thank you for your help.

Unfortunately, it didn't work.

There isn't any method "getMyOutputResultElementAt" for wdContext.nodeMyOutputResult(), but I guessed I had to use getElementAt(i) and then cast the result.

I also changed what was inside the loop, because the way it was done made the result being reinitialized at each iteration. And to get sure I got the right value (and not the last one), I added a check so the value is set only if it is not empty or null.

Why do I have to loop at my output node? Shouldn't there be a single result element?

Here is how I changed the code


IMyOutputResultElement resultElem = null;

for (int i = 0; i < wdContext.nodeMyOutputResult().size(); i++) {
	resultElem = (IMyOutputResultElement)wdContext.nodeMyOutputResult().getElementAt(i);
	if (resultElem.getMyReturnValue() != "" && resultElem.getMyReturnValue() != null) {
		month = resultElem.getMyReturnValue();
	}
}

Former Member
0 Kudos

Hi,

If you didn't find that method then let me know is getMyReturnValue a node or an attribute. It should be a node. If it's a node then you need to loop through this node instead of the nodeMyOutputResult node. If it is the last level node then you should get the method as mentioned above.

Regards,

Murtuza

Former Member
0 Kudos

Sorry, my previous reply was not clear enough.

MyReturnValue is an attribute, and after using getElementAt (instead of getMyOutputResultElementAt) and casting I get the method getMyReturnValue.

But the result is still empty.