cancel
Showing results for 
Search instead for 
Did you mean: 

.NET Connector 3.0 Return Structures not being Populated

Former Member
0 Kudos

Hello Gurus.

I'm an experienced BAPI user and am now trying to use the .NET connector. We're seeing an issue we cannot seem to resolve with regard to the BAPIRETURNx structures. In many cases it is NOT being returned after the call so we have no way of knowing if the call succeeded or failed. The return struct is simply initialized and does not receive anything back from the SAP server. In some cases an explicit commit is called and yet the update fails. As there is nothing in the return structure we have no way to know why.

Not sure if our SAP server needs a service pack or what. We've tried both 32 and 64 bit on VS2010.

Please advise.

Thanks!

Accepted Solutions (0)

Answers (1)

Answers (1)

former_member197445
Contributor
0 Kudos

Please include your code for troubleshooting, if you don't mind.

Your code should be similar to the following. 

IRfcFunction sapFunction = SAPConnection.Repository.CreateFunction("BAPI_WHATEVER");

sapFunction.SetValue("PLANT", branchNumber);  //... or whatever your input parameters are

sapFunction.Invoke(SAPConnection);

IRfcStructure sapErrors = sapFunction.GetStructure("MESSAGE");

if (sapErrors != null && sapErrors.GetString("TYPE").Equals("E")) {

          string errorMsg = sapErrors.GetString("MESSAGE");

          if (errorMsg.Trim.Length > 0) {

          // report the error in whatever manner is appropriate to your application

          }

} else {

     //successful... continue processing

}

Former Member
0 Kudos

Hello here it is.

           

//-----------------------------------------------------------

// HYDRATE STRUCTURES

//-----------------------------------------------------------

IRfcFunction func = this.GetFunction("BAPI_EQUI_CREATE");

IRfcStructure strucDS = func.GetStructure("DATA_SPECIFIC");

IRfcStructure strucRtn = func.GetStructure("RETURN");


strucDS.SetValue("MATERIAL", matNumberSAP);

strucDS.SetValue("SERIALNO", equip.SerialNumberSAP);

strucDS.SetValue("EQUICATGRY", TypeHelper.ToEquipmentCategoryCode, equip.Category));


           

//-----------------------------------------------------------

// MAKE THE CALL

//-----------------------------------------------------------

           

RfcSessionManager.BeginContext(this._destination);


func.Invoke(this._destination);

           

// TYPE COMES BACK AS AN EMPTY STRING

if (strucRtn.GetString("TYPE") == "E")

{

}


former_member197445
Contributor
0 Kudos

Could it be the need, perhaps, to invoke the BAPI_TRANSACTION_COMMIT also?  Or else you could also try hydrating the RETURN structure after the Invoke, though I'm not usre that's necessary.  I'm only suggesting it because I've always done that in my code.

Former Member
0 Kudos

Yes I've tried moving this statement to after the call:

func.Invoke(this._destination);

IRfcStructure strucRtn = func.GetStructure("RETURN");

It had no impact the entire return structure is empty.

Also if this call fails I would NOT want to call a commit so I need to have the resposne first right?

It almost looks like the return structure XML is not being returned from the server. On other calls it does work like when I'm doing a simple READ operation.

former_member197445
Contributor
0 Kudos

Yeah, you're right.  COMMIT should not be necessary.

What about the fact that you're using "GetFunction" instead of "CreateFunction" on the first line of your code snippet above?

Former Member
0 Kudos

That is a .CreateFunction() it's just in a separate function.

Also once you have an address to the structure in memory:

IRfcStructure strucRtn = func.GetStructure("RETURN");

I believe it really doesn't matter if the funtion.Invoke() comes before or after. It is simply hydrating the structure.

I assume BAPI calls should ALWAYS return a BAPIRETURNx structure correct?

Where do we go from here?

Thanks!

former_member197445
Contributor
0 Kudos

Yes, normally the BAPI should always return a success OR error.  But I took a glance at BAPI_EQUI_CREATE and it looks as though perhaps that particular BAPI only returns errors.

I suppose if your equipment is created successfully in the called system, then you should treat blank as a success.

Former Member
0 Kudos

I see. I am also having an issue with the BAPI_QUALNOT_CREATE function call.

After the call I execute a BAPI_TRANSACTION_COMMIT call.

In both cases the BAPIRETURNx structure has no values AND the record is NOT created in SAP.

former_member197445
Contributor
0 Kudos

I have confirmed with my coworkers that there are many BAPIs that return blank RETURN structures for success. 

In the case of BAPI_QUALNOT_CREATE, something else is happening.  Many SM-related BAPIS must be called in sequence to work.  I believe this may be the case here.  Try calling BAPI_QUALNOT_SAVE after the create THEN call the commit after that.  Let me know if that helps.

Former Member
0 Kudos

Okay I'll give it a try. Using the older .OCX files I could always count on BAPI_TRANSACTION_COMMIT returning a return struct.

Is that still the case with the .NET connector?

former_member197445
Contributor
0 Kudos

The .NET Connector should ALWAYS return whatever the function module itself would return if you were running it in SAP.  This is why I tend to wrap standard FM within "Z" function modules for external Apps, so that I can test the code in SE37 using the same inputs as my connected App and also control what the error messages are.

Former Member
0 Kudos

The .NET Connector should ALWAYS return whatever the function module itself would return if you were running it in SAP.

I agree but it appears that is NOT the case. How can we proceed witht his issue?

former_member197445
Contributor
0 Kudos

I disagree, Chris... it IS the case.  My earlier statement is true.

If you call BAPI_TRANSACTION_COMMIT in SE37 by itself, you will get an empty return structure, which is what you are seeing.  If you call BAPI_QUALNOT_SAVE between the create and the commit, you should get a message.  Give it a shot.

Former Member
0 Kudos

Hello Case,

As good as your word the BAPI_QUALNOT_SAVE resolved the issue!

Q: If a function has already been created how does one walk the repository to get access to it rather than create a new one?

former_member197445
Contributor
0 Kudos

I'm not 100% sure, but it sounds like you might be looking for the Enterprise Services Explorer.

Former Member
0 Kudos

Sorry I meant in code once the function "BAPI_xxx" has been created the meta data for that function is now in teh repository. How in the .NET cod ecan I find the created function as to avoid creating ti again?

IRfcFunction = Repository.Functions["BAPI_xxx"];

or something like that?

former_member197445
Contributor
0 Kudos

Do you mind if we mark this thread answered and open up a new thread, please?  Thanks.