DatRid
DatRid

Reputation: 1169

Call a SAP transaction/program with the SAP 3.0 .NET Connector

I am aware of the option to call RFC-functions with .NCo 3.0 but is it possible to call transactions/programs directly with the SAP Connector? (Like using the fields defined in SAP as parameters and fill them, or use a variation, something like this?).

This answer provides a workaround that I am aware of, and sure - I could call a VBScript from my C# code but that is not what I want to do. I also checked all of the 64 Questions tagged with sap-connector but there was nowhere a direct answer if it is possible or not.

Also the SAP documentations I got from the SAP marketplace aren't mentioning transactions/programs at all. Does this mean it is not wanted/possible ?

If so, why is it possible to do it with macros/pre-recorded VBScripts but not with the .NET-Connector ? Or am I just doing something wrong ?

When I try to call a program/transaction with the standart-code:

SAPHandle.ECCDestinationConfig cfg = new SAPHandle.ECCDestinationConfig();

RfcDestinationManager.RegisterDestinationConfiguration(cfg);

RfcDestination dest = RfcDestinationManager.GetDestination("QP2");

dest.Ping(); //works fine -> Connection is OK

RfcRepository repo = dest.Repository;

IRfcFunction zzmkalzzm23fnc = repo.CreateFunction("ZMZKALZZM23");

it gives me the following (expectable) error:

metadata for function ZMZKALZZM23 not available: FU_NOT_FOUND: function module ZMZKALZZM23 is not available

Upvotes: 1

Views: 4010

Answers (1)

Dirk Trilsbeek
Dirk Trilsbeek

Reputation: 6033

CreateFunction, as the name already suggests, creates a proxy to call a remote-enabled function module in the SAP system. You can't call a transaction or program this way. I am not aware of any way to call a report with SAP .Net Connector. The solution you linked uses SAP Gui, which provides the SAP system with a UI to display graphical elements. AFAIK, SAP NCo doesn't provide such an interface and you can't call reports from NCo.

However, there are products that allow you to execute transactions and catch their output. We are using the product Theobald Xtract to extract SAP ERP data for BI purposes, but they also have a more generic .Net library (Theobald ERPConnect) available that may be able to provide this functionality. It won't be as simple as calling a function and extracting the strongly typed data, but with some filtering you should be able to get the output you need. Those products are not cheap, but they do provide a nice set of functionality you otherwise would have to reinvent yourself.

Some example code how you could call the transaction you ended up calling through VBS-Scripts. From the Theobald ERPConnect Knowledgbase:

private void button1_Click(object sender, System.EventArgs e)
{
    // Reset the batch steps
    transaction1.BatchSteps.Clear();

    // fill new steps
    transaction1.ExecutionMode =    ERPConnect.Utils.TransactionDialogMode.ShowOnlyErrors;
    transaction1.TCode = "MMBE";
    transaction1.AddStepSetNewDynpro("RMMMBEST","1000");
    transaction1.AddStepSetOKCode("ONLI");
    transaction1.AddStepSetCursor("MS_WERKS-LOW");
    transaction1.AddStepSetField("MS_MATNR-LOW",textBox1.Text);
    transaction1.AddStepSetField("MS_WERKS-LOW",textBox2.Text);

    // connect to SAP
    r3Connection1.UseGui = true;

   R3Connection r3Connection1= new R3Connection("SAPServer",00,"SAPUser","Password","EN","800");
     r3Connection1.Open(false);
     // Run
     transaction1.Execut e();

}

Upvotes: 1

Related Questions