cancel
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 https://github.com/huysentruitw/SapNwRfc, 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?

Sandra_Rossi
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");
login.Invoke();
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.

Accepted Solutions (0)

Answers (2)

Answers (2)

Sandra_Rossi
Active Contributor

I don't know the unofficial library you are mentioning (huysentruitw/SapNwRfc: SAP NetWeaver RFC library for .NET 5, .NET Core and .NET Framework (github.co...). It doesn't say what it adds to the official library... (but maybe it will obvious to .NET experts)

It's based on official library that you can use directly (SAP NetWeaver Remote Function Call (RFC) Software Development Kit (SDK)). There's also the SAP .NET Connector (SAP Connector for Microsoft .NET).

For the BAPI you mention, you can find some answers in the forum concerning the parameters that you need to pass and the ones you need to read. You can also find them via the metadata you can query via the libraries.

If you call BAPI_XBP_JOB_START_ASAP without first calling BAPI_XMI_LOGON (because XBP is part of XMI, i.e. among other possible XMI applications), it returns a functional error in the parameter RETURN. You need to read it. You can find explanations in the SAP .NET Connector documentation.

You must log into XMI via BAPI_XMI_LOGON with these parameters:

  • EXTCOMPANY: any name (your company)
  • EXTPRODUCT: any name (your software name)
  • INTERFACE: the ID of the XMI application that you want to use ("XBP" in your case)
  • VERSION: the version of the XMI application that you want to use (it could be "1.0", "2.0" or "3.0" for XBP, I recommend to use the latest version)
  • BAPI_XMI_LOGON returns these parameters:

    • SESSIONID
    • RETURN: error message if any

    BAPI_XBP_JOB_START_ASAP expects these parameters:

    • JOBNAME: the name of the job to start
    • JOBCOUNT: the number of the job to start
    • EXTERNAL_USER_NAME: any name
    • + optional ones

    BAPI_XBP_JOB_START_ASAP returns the parameter:

    • RETURN: error message if any

    Hi sandra.rossi

    Thank you for the information, I followed your suggestion of using BAPI_XMI_LOGON first, then using the BAPI_XBP_JOB_START_ASAP, with the required parameters and it worked. Now the issue that I'm facing is with BAPI_XBP_JOB_STATUS_GET. Using this function throws conversion error for STATUS and HAS_CHILD, whereas it works for RETURN.

    Sandra_Rossi
    Active Contributor
    0 Kudos

    Both STATUS and HAS_CHILD parameters are scalar types of 1 character, while RETURN is a structured variable. Maybe you use the wrong methods.

    Ulrich_Schmidt
    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

    Hi ulrich.schmidt

    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?

    Ulrich_Schmidt
    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

    Hi ulrich.schmidt

    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

    1. BAPI_XMI_LOGON
    2. BAPI_XBP_JOB_START_ASAP
    3. BAPI_XBP_JOB_STATUS_GET

    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.

    Ulrich_Schmidt
    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.