cancel
Showing results for 
Search instead for 
Did you mean: 

Problem calling Bapi

Former Member
0 Kudos

Hello all,

Until now I've been able to call simple bapis (with simple import parameters, such as String or int), such as employee_getdata with no problems.

Now, I try to call a bapi (Zbapi_Trip_Change) with a structure as import parameter. This structure is actually the result of a first (and successful) call to another bapi (Bapi_Trip_Get_Details).

There I get into troubles: the structure arriving in Zbapi_Trip_Change BAPI itself (SAP side) is empty (it contains no data, but exists), while simple parameters are OK (String and int).

Here is a piece of my java code:

    Zbapi_Trip_Change_Input tripChangeInput = new Zbapi_Trip_Change_Input();
    wdContext.nodeZBapi_Trip_Change_Input().bind(tripChangeInput);
    
    wdContext.currentZBapi_Trip_Change_InputElement().setEmployeenumber(empNb);
    wdContext.currentZBapi_Trip_Change_InputElement().setTripno(tripNb);
    
    Bapitrmain curFrameData = wdContext.currentFramedataElement().modelObject();
    wdContext.nodeZBapi_Trip_Change_Framedata().bind(wdContext.currentFramedataElement().modelObject());

Is there something that I miss ? Should I do another step to fullfill my binding (such as linking nodeZBapi_Trip_Change_Framedata node to nodeZBapi_Trip_Change_Input node ?

Any help would be greatly appreciated !

Caroline

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi

Well everyone seems to face the problem when dealing with structures in SAP.

It would be useful if you can tell us the "Z" bapi structures . We can give you a exact code.

Anyway See the following code :

Zbapi_Trip_Change_Input tripChangeInput = new Zbapi_Trip_Change_Input();

wdContext.nodeZBapi_Trip_Change_Input().bind(tripChangeInput);

//Pass input to the Bapi

tripChangeInput.setEmployeeNumber(empNB);

tripChangeInput.setTripno(tripNb);

//If you have to pass some value to a Table in a BAPI then

//Change the following in your code accordingly.

Bapitrmain curFrameData = new Bapitrmain();

curFrameData.set<attribute>(value);

curFrameData.set<attribute>(value);

tripChangeInput.set<TabNam>(curFrameData);

try

{

wdContext.currentZbapi_Trip_Change_Input().modelObject().execute();

}

catch(Exception e)

{

}

Well thats about some pseudo code that should help you in your scenario. I dont know how you have done model binding and all that. But Assuming everything is fine this code should work. Check for the syntax. The above is just a sample code. It need not work as it is. It will just give you a idea as to how to go about implementing it.

Hope that helps you. Let me know if you require further clarifications.

If the above doesnt help, Give me the exact structure of the BAPI and also the scenario. I could give you the exact code :).

regards

Ravi

Former Member
0 Kudos

Thanks Ravi for your help.

Actually, I tried to do what you are recommending, not being more successful... But: reading more carefully your pseudo-code, I noticed this line:

tripChangeInput.set<TabNam>(curFrameData);

What I don't understand is that I don't have such a method for instances of Zbapi_Trip_Change_Input !!!

This bapi needs two import simple (int) parameters (tripNb and empNb), and several import structures, one being this framedata, whose structure type is Bapitrmain.

For each import simple (int) parameter, I have setter method. For more complex (structures), I don't !!

Whatever, one of the constraints I have it to give <i>Zbapi_Trip_Change</i> bapi the <i>framedata</i> structure I got from previous call to <i>Bapi_Trip_Get_Details</i>.

So I would really prefer copy / paste values from received framedata to framedata to be sent

Former Member
0 Kudos

Hi

Well if you see the proxies generated when you create the model you will notice that all The Table parameters in ABAP are generated as classes.

so the Information that you are looking for is within these table parameters. You can do a setter method only using the instance of table class generated

For example BAPITRMAIN would be generated as a class.

So BAPITRMAIN ts = new BAPITRMAIN();

using this object ref

ts.set<table attribute name>(value to be set);

you have to set values using this way.

Now in your case when you say

tripChangeInput.

what are all the methods that get shown. Can you tell me the list. As far as i know you should have something like add<attribute> or set<attribute> and the parameter would be a Abstract list or the object ref.

Just send me the list of setter and add methods which get displayed when you say "tripChangeInput."

I should be able to tell u what to use. Moreover the Z bapi is it a copy of some standard bapi. Can you tell me the standard bapi from which you copied. I should be able to help you.

regards

ravi

Former Member
0 Kudos

Hi,

Thank you for your fast answer...

I checked my classes, but I don't have the setter method for table parameters

When I look at my IZBapi_Trip_Change_InputElement (by calling currentZBapi_Trip_Change_InputElement() method), the list of setter methods is the following:

- setEmployeenumber

- setTripno

- setAttributeValue

And I don't have add methods...

When I look at my IZBapi_Trip_Change_InputNode (by calling nodeZBapi_Trip_Change_Input() method), I have those standards addElement() methods, and no setter methods.

By the way, if you could quickly explain me the purpose of (and the difference between) those two differents instance types (Node and Element), I would be very glad ! I've read a lot about those, but still use them just by looking which one is having the method I need

Thank you very much in advance,

Caroline

Former Member
0 Kudos

I just noticed that, when I look at my tripChangeInput (instance of Zbapi_Trip_Change_Input), I have setter method for framedata.

I thought this piece of code was correct:

    Zbapi_Trip_Change_Input tripChangeInput = new Zbapi_Trip_Change_Input();
    wdContext.nodeZBapi_Trip_Change_Input().bind(tripChangeInput);
    
    wdContext.currentZBapi_Trip_Change_InputElement().setEmployeenumber(empNb);
    wdContext.currentZBapi_Trip_Change_InputElement().setTripno(tripNb);

... but doing this way, I don't have setter method nor add method to set the value of framedata.

However, doing so:

    Bapitrmain curFrameData = wdContext.currentFramedataElement().modelObject();
    
    Zbapi_Trip_Change_Input tripChangeInput = new Zbapi_Trip_Change_Input();
    
    tripChangeInput.setEmployeenumber(empNb);
    tripChangeInput.setTripno(tripNb);
    tripChangeInput.setFramedata(curFrameData);

    wdContext.nodeZBapi_Trip_Change_Input().bind(tripChangeInput);

... everything works...

So definitively I miss something: what's the difference between setting value to nodes / elements, or to instance before binding ?

Any help on this would be greatly appreciated

Message was edited by: TWM

Former Member
0 Kudos

When u say currentZBapi_Trip_Change_InputElement() that means u r accessing a lead selection node element of nodeZBapi_Trip_Change_InputElement().

The import/export table and structures are created as inner nodes.U can directly access those nodes and set the values.

wdContext.currentFramedata().set<<>>.

When u r accessing Zbapi_Trip_Change_Input object it is the proxy class generated and it will conatin all the import and export parameters as getter and setter methods .That is the reason why u r getting setter method in the second case.U can do it this way.

Zbapi_Trip_Change_Input tripChangeInput = new Zbapi_Trip_Change_Input();

wdContext.nodeZBapi_Trip_Change_Input().bind(tripChangeInput);

wdContext.currentZBapi_Trip_Change_InputElement().setEmployeenumber(empNb);

wdContext.currentZBapi_Trip_Change_InputElement().setTripno(tripNb);

Bapitrmain curFrameData =new curFrameData();

curFrameData.set<<>>;

tripchangeInput.set(cureFrameData);

Hope this helps.

Regards,

Sowjanya.

Former Member
0 Kudos

Thank you very much both of you, it's now clearer