cancel
Showing results for 
Search instead for 
Did you mean: 

How to display a structure returned from bapi?

Former Member
0 Kudos

Hi,

I created a project that is accessing r/3.

On execution of my bapi its returning messages which is a structure.

I tried displaying it in my view using this code:

IWDMessageManager msgmgr = wdComponentAPI.getMessageManager();

msgmgr.reportSuccess(wdContext.currentReturnElement().getMessage());

but its throwing an exception

Can any one please suggest in this regard.

Regards,

Aparna.

Accepted Solutions (0)

Answers (3)

Answers (3)

sridhar_k2
Active Contributor
0 Kudos

Hi,

"Null Pointer Exception", will raise when you point to a Null Object.

in your code, first check

if(wdContext.currentReturnElement() != null){

msgmgr.reportSuccess(wdContext.currentReturnElement().getMessage());

msgmgr.reportSuccess("Size : "+wdContext.currentReturnElement().size());

}else{

msgmgr.reportSuccess("Null");

}

// if it is coming to else(null), it means "wdContext.currentReturnElement()" is containing null.

Regards,

Sridhar

Former Member
0 Kudos

Hi Sridhar,

As per our earlier discussion i tried this.

It is giving null. But actually bapi is returning a message, which i am able capture in webdynpro when it is sent as a table.

Now when the same 'return' is changed to structure i am unable to display.

Problem is though there is some data in my return its showing null.

Please suggest a way to handle structures returned from bapi in webdynpro.

Regards,

Aparna .P

Former Member
0 Kudos

Hi

I think it returns the null pointer exception because you mention the getMessage is not returning null value.

can you check the value is coming or not?

Other wise post ur issues.

Thanks

Lohi.

Former Member
0 Kudos

Hi

try this

try{

if(wdContext.currentReturnElement().getMessage()!=null){

IWDMessageManager msgmgr = wdComponentAPI.getMessageManager();

msgmgr.reportSuccess(wdContext.currentReturnElement().getMessage());

}

}catch(Exception e){

IWDMessageManager msgmgr = wdComponentAPI.getMessageManager();

msgmgr.reportSuccess(e.getMessage());

}

Kind Regards

Mukesh

sridhar_k2
Active Contributor
0 Kudos

Hi,

What is the Exception? I guess that is from wdContext.currentReturnElement() Statement only.

Ensure this one with not null before getting variable from it.

Regards,

Sridhar

Former Member
0 Kudos

Hi Sridhar,

I am getting "Null pointer exception".

Same code worked when the return messages are sent in a table from R/3.

This problem raised when the return messages are sent as a structure from R/3.

Mukesh,

I already tried that way also.

But using try..catch or if condition will help me in catching the exception. My requirement is to display the return message that is sent as structure from bapi.

Regards,

Aparna .P

Former Member
0 Kudos

Hi

Can you confirm that the Message text is return from which element in return node Message or Message_V1 or from other attributes.And confirm that The Return node which you are using is corressponding to the BAPI which you are execute currently.

I think in this case you try to get the other BAPI's Return Node's Message element.Please check this.

Kind Regards

Mukesh

Former Member
0 Kudos

Hi,

You can try something like this:

1. Let's say your BAPI name is Bapi_Name.


//You should have already done this.
Bapi_Name_Input input = new Bapi_Name_Input();

//After execution of the BAPI, do this
Bapi_Name_Output output = input.getOutput();

List messages = output.getReturn();
StringBuffer msgBuffer = new StringBuffer();

if(messages != null && messages.size() != 0){
for(int i = 0; i < messages.size(); i++){
Bapiret2 ret = (Bapiret2)messages.get(i);
msgBuffer.append(ret.getMessage());
}
}

Regards,

Satyajit.

Former Member
0 Kudos

Hi Satyajit,

I tried your code. Still i am getting the same exception.

Regards,

Aparna. P

Former Member
0 Kudos

Hi Satyajit,

Your code was helpful.

But instead of getting it from 'input' i used this:

wdContext.nodebapi_name_input().currentbapi_name_inputElement().modelObject().getOutput().getReturn().getMessage()

This returned my bapi message as string.

Thanks All for the help

Regards,

Aparna .P