goenning / SharpSapRfc

Making SAP RFC calls even easier with .NET
MIT License
84 stars 27 forks source link

BAPI_TRANSACTION_COMMIT #47

Closed PeteDurst closed 6 years ago

PeteDurst commented 6 years ago

Hello,

first of all thank you very much for your great work.

Is there a possibility to integrate RfcTransactions? I wanted to call a BAPI called BAPI_PR_CREATE. However, this requires a BAPI_TRANSACTION_COMMIT. Do you know a way to use this in conjunction with SharpRfc?

One day later... you just need to wrap the two function calls in a context

using (var conn = new PlainSapRfcConnection(config.Destination))
{
    RfcSessionManager.BeginContext(conn.Destination);

    var createResult = conn.ExecuteFunction("BAPI_PR_CREATE",
        new RfcParameter("PRHEADER", new {PR_TYPE = "NB"}),
        new RfcParameter("PRHEADERX", new {PR_TYPE = true}),
        new RfcParameter("PRITEM", requisitionItems),
        new RfcParameter("PRITEMX", requisitionItemsX),
        new RfcParameter("PRACCOUNT", requisitionAccountAssignments),
        new RfcParameter("PRACCOUNTX", requisitionAccountAssignmentsX),
        new RfcParameter("PRADDRDELIVERY", requisitionDeliveryAddresses)
    );
    conn.ExecuteFunction("BAPI_TRANSACTION_COMMIT");

    RfcSessionManager.EndContext(conn.Destination);

    var requisitionId = createResult.GetOutput<string>("NUMBER");
    var returnals = createResult.GetTable<BapiReturn>("RETURN");

    if (!int.TryParse(sapRequisitionId, out var requisitionId)) requisitionId = 0;
    return (requisitionId, returnals);
}