Showing results for 
Search instead for 
Did you mean: 

Using BAPI_XBP_JOB_START_ASAP doesn't start the job in C# using SapNwRfc RFC

0 Kudos

Hi Team,

I have a requirement where I need to run an existing job, and wait for it to finish. As per, I have added the SapNwRfc package and added the required dlls as the project reference.

I'm able to set-up the connection as .Connect() and .Ping() are returning true, but when I'm trying to run a job in SAP, it is not performing any action.
I'm using the below code to trigger the Job.

<code>ISapFunction something = connection.CreateFunction("BAPI_XBP_JOB_START_ASAP");
something.Invoke(new JobParameters
    JobName= "JOBNAME",

This doesn't throw any error but when I look at the client, no operation is performed as well even after multiple refresh.

Is this the right way to do it? or is there something else we need to add here?

Active Contributor
0 Kudos

It throws a functional error (parameter RETURN) but you don't read it. XBP is one of the XMI applications, so you must log into XMI first (BAPI_XMI_LOGON). See other answers in the forum.

0 Kudos

Hi sandra.rossi

I tried looking at the other answers and the ones I found is not matching the language or package I'm using here. I tried to use login first with the below code and still I don't see the parameter RETURN in my evaluations. Where exactly I'll see this parameter?
Invoke() is void so it doesn't return anything.

var login = connection.CreateFunction("BAPI_XMI_LOGON");
ISapFunction something = connection.CreateFunction("BAPI_XBP_JOB_START_ASAP"); something.Invoke(new JobParameters { JobName= "JOBNAME", });

I'm new to the system and understand very little of SAP, don't understand SAP coding as well and still have this question if this is the right way to do it.

It would be great, if you could help me with some documentations or a example which I can refer.

View Entire Topic
Product and Topic Expert
Product and Topic Expert

I recommend using SAP's official .NET Connector (written in C#), instead of an unofficial project based on a C/C++ library. At least then you can get support from SAP in case something doesn't work.

0 Kudos


I understand the point here and I actually started with sapnco, but it failed with TypeInitializationException. When looked online in stackoverflow and sap answers, most of the solutions where to use .NET 4 as the target environment. We are using 6 as our target environment, so downgrading it doesn't make sense, so switched to SapNwRfc.

Do you have any suggestion here?

Product and Topic Expert
Product and Topic Expert
0 Kudos

It depends on your timeline (meaning how fast you need to go productive). At the moment, SAP NCo does not yet support .NET Core, only .NET Framework. But sooner or later, a version for .NET Core can be expected. So there would be the following options:

  • Create your project in .NET Framework 4.8 as a proof of concept. You can do the implementation, gain experience, make sure the creation of jobs works from remote, etc. And then hope that by the time you have finished this process successfully, a .NET Core version of NCo will be available. Then just switch the target framework back to 6.
  • Start with SapNwRfc. Find out, how SapNwRfc allows you to read the RETURN structure after the Invoke(), and then read the error message contained in it, fix it and make it work... Once it works, you can either keep it that way (if you are satisfied with performance, stability, etc.), or switch to NCo later, when a .NET Core version becomes available.
    However, it looks like SapNwRfc works differently to NCo in two points:
    a) How it provides access to the EXPORTING parameters of the function module (like in this case the RETURN structure). If you haven't found out yet, how you can read the exports after the call, it may be a bit difficult. In NCo, you would simply get it like this:
    IRfcStructure return_struc = login.getStructure("RETURN");
    String errorMessage = return_struc.getString("MESSAGE");
    And similarly you would set IMPORTING parameters (e.g. for passing the SESSIONID returned from BAPI_XMI_LOGON as input to BAPI_XBP_JOB_START_ASAP, if that is necessary - I don't know these BAPIs and how they work, so I can't say, whether something like this would be necessary to make it work.)
    b) How it allows using a "stateful" connection.
    I am pretty sure, that these XMI BAPIs need to be called via a stateful connection: the name "LOGIN" suggests that on ABAP side a stateful user session is initialized, which the following BAPI calls (like "CREATE", "MODIFY", etc.) then continue to use. And I assume there is then also a BAPI called "LOGOUT", which closes the session on ABAP side. So one possible reason, why your scenario currently doesn't work, is that you are not calling it on a stateful connection. (E.g. if the SapNwRfc framework makes a RESET_SERVER_CONTEXT after every call, the stateful session created by the "LOGIN" will automatically be cleaned up by SapNwRfc, before the Invoke() has even returned... 🙂
    So you need to read the documentation and what it has to say about stateful/stateless connections. SapNwRfc seems to be "connection-oriented" like the underlying NW RFC Library, while NCo is "destination-oriented", so the concepts for handling statefulness will definitely be different between these two frameworks.
0 Kudos


Thank you for your suggestion. I have started with using SapNwRfc as the timeline to demonstrate the POC is near and integration with current framework is required too.

I got the the error message in RETURN, and it was related to BAPI_XMI_LOGON, which is same as suggested by sandra.rossi in the above answer. I have fixed it with correct parameters and the correct order of functions


Now the issue I'm facing is with the 3rd function. Here the RETURN works as expected but the other export parameters of BAPI_XBP_JOB_STATUS_GET, STATUS and HAS_CHILD throws the conversion error RFCTYPE_CHAR cannot be converted to type RFC_STRUCTURE_HANDLE, even though I'm using the same model like RETURN.

Product and Topic Expert
Product and Topic Expert
0 Kudos

STATUS and HAS_CHILD are apparently no structures, but plain CHAR parameters. Use GetString() instead of GetStructure() (or how it is called in SapNwRfc) for these.