cancel
Showing results for 
Search instead for 
Did you mean: 

Getting the return values from the backend BAPI

Former Member
0 Kudos

Hi,

I am very new to Web Dynpro for Java programming. I need some help with the following.

Our ABAP developers developed a BAPI which accepts input value in the form of a structure and returns the output in the form of a structure.

I am developing an application using Web Dynpro for Java, to call the custom BAPI . I don't know how to send the input field values in the form of a structure. If it is just an input field I know how to set the input field values before calling the execute method on the model.

Could any one of you please provide me a piece of sample code to set the input values to the bapi import parameters.

And also please let me know how to read the values of the output which was returned in the form of a structure (not the tables).

Thanks in advance.

Regards

Srini

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

Context

Bapibank_getList

Bapibank_getList_Input

_BankKey

_MaxRows

|_Bapi_bank_getList_Output

|_BankName

|_BankCountry

Create a local node in the same structure as of RFC node imported

public void ExecuteBankDetails( )
{
  Bapi_bank_getList  list = new bapi_bank_getlist();
   
   bapi_bank_getlist_input input = new bapi_bank_getlist_input();
   input.setbankkey(wdcontext.currentvninputelement().getbankkey);
   input.setmaxrows(wdcontext.currentvninputelement().getrows);
   list.setbapi_bank_getlist_input(input);
  
   wdcontext.nodeBapi_bank_getList().bind(list);

  wdcontext.currentBapi_bank_getListElement().modelObject().execute();
  wdcontext.nodebapi_bank_getlist_output().invalidate();
  wdContext.currentBapi_bank_getListElement().modelObject().modelInstance().disconnectIfAlive();
  
  //copying the RFC output to local node binded to view table
  if(!wdContext.nodebapi_bank_getlist_output().isEmpty())
  {
	WDCopyService.copyElements(wdContext.nodebapi_bank_getlist_output(),wdContext.nodevnBankListOutput());
  }

Regards,

Bala Baskaran.S

Answers (5)

Answers (5)

Former Member
0 Kudos

Thanks, the issue was resolved.

Regards

Srini

Former Member
0 Kudos

Getting runtime errors while executing.

0 Kudos

Hi Srini,

if you are sending the input values from a single view to bapi structure use the following code in particular button action under View Controller.

1. cut the code available in component controller wdDoInint() method and paste in the view controller action

<Bapi node name> input = new <Bapi node name>();

wdContext.node<Bapi node name>_Input.bind(input);

2. Take the structure name of the Bapi input node, which you have to send the input values and write the following code.

<StructureName> ele = new <StructureName>();

ele.set<AttributeName>(wdContext.current<NodeName>Element().get<AttributeNAme>());

.

.

.

ele.set<AttributeName>(wdContext.current<NodeName>Element().get<AttributeNAme>());

input.set<NodeName>(ele);

wdThis.wd<ComponentControllerName>.execute(); // this method is avialable in component controller and it will have the

model execute code

3. for reading the output you can simply use the following code after executing the Bapi.

wdContext.current<Bapi Node Name>Element().get<AttributeName>();

or

<StructureName> Outele = new <StructureName>();

Outele.get<AttributeName>();

Thanks & Regards,

Bhargava

Former Member
0 Kudos

Thanks guys!

Regards

Srini

Former Member
0 Kudos

Hi Bharghav / Bala,

I thought issue was resolved. But while runtime I am getting Null Pointer exception.

I think I haven't project the correct issue.

The issue is I have a custom BAPI and it has bapi_input structure. Under the BAPI_Input structure one of the input field is again a structure. Your solution works for BAPI_Input structure. My issue is how to refer to the inner input structure?

When I tried to set the values for the inner structure I was getting Null pointer exception during the runtime.

For example, if the input inner structue is: innerStructure, then I was trying to set the values for the innerStructure as follows:

wdContext.currentInnerStructure.setField1(....);

wdContext.currentInnerStructure.setField2(....);

The runtime is throwing the error on currentInnerStructure.

How to initialize the innerStructure first and then assign the values.

Please help me out.

Regards

Srini

Former Member
0 Kudos

HI Srini,

You can extend the example given by Bala to second level structure as below :


Bapi_bank_getList  list = new bapi_bank_getlist();
bapi_bank_getlist_input input = new bapi_bank_getlist_input();
input.setbankkey(wdcontext.currentvninputelement().getbankkey);
input.setmaxrows(wdcontext.currentvninputelement().getrows);
//for example if inner structure is bapi_bank_getlist_input1 
bapi_bank_getlist_input1 input1 = new bapi_bank_getlist_input1();
input1.set..(..value..);
input.set..attribute...(input1);//set inner structure value attribute of type bapi_bank_getlist_input1

list.setbapi_bank_getlist_input(input);//set main input

Regards

Deepak

chinna_babu2
Active Participant
0 Kudos

Hi Srini,

If you have already imported the BAPI to your model then you need to perform the following steps.

Initialize the BAPI

Bind the instance to the Model Node

Execute

Get the output in structure.

Below is the link to acces the ABAP functions from Web Dynpro java.

[http://www.sdn.sap.com/irj/scn/index?rid=/library/uuid/355b9c90-0201-0010-d2a8-89fece426526]

Regards

junwu
Active Contributor
0 Kudos

you should use the wizard, which generate everything for you.

right click the component controller and select apply template

you should also search in sdn to get some basic material regarding the web dynpro bapi call.