on 08-11-2012 3:56 PM
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!
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
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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")
{
}
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.
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!
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.
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.
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.
I'm not 100% sure, but it sounds like you might be looking for the Enterprise Services Explorer.
User | Count |
---|---|
93 | |
10 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.