다음을 통해 공유


Invoking BAPI Transactions from a Workflow

When working with BAPI(s) in WCF SAP adapter, the transaction handling requires that the BAPI_TRANSACTION_COMMIT/BAPI_TRANSACTION_ROLLBACK call be issued on the same SAP connection that was used to execute the BAPI. The Windows Workflow Foundation 4.0 does not have a notion of “session” scope that can be used to club multiple LOB activities to use the same underlying WCF channel. Because of this limitation, the BAPI transaction scenario breaks if you use the LOB Activities. To get this scenario to work, you need to create a custom activity that will use the generated proxy class to make the BAPI call and then invoke the commit/rollback on the same proxy class instance. This ensures that the calls go over the same underlying WCF channel and thus the same SAP connection.

 

Here’s a code snippet that illustrates the use of custom Code Activity to execute BAPI_MATERIAL_SAVEDATA

 

    public sealed class BapiMaterialSaveDataActivity : CodeActivity<BAPIRET2>

    {

        // TODO: Expose any properties for setting the arguments

        protected override void Execute(CodeActivityContext context)

        {

            BapiBUS1001006Client client = new BapiBUS1001006Client();

            // TODO: Intialize the parameters

            BAPIPAREX[] EXTENSIONIN = new BAPIPAREX[0];

            BAPIPAREXX[] EXTENSIONINX = new BAPIPAREXX[0];

            BAPI_MEAN[] INTERNATIONALARTNOS = new BAPI_MEAN[0];

            BAPI_MAKT[] MATERIALDESCRIPTION = new BAPI_MAKT[1];

            BAPI_MLTX[] MATERIALLONGTEXT = new BAPI_MLTX[0];

            BAPI_MFHM[] PRTDATA = new BAPI_MFHM[0];

            BAPI_MFHMX[] PRTDATAX = new BAPI_MFHMX[0];

            BAPI_MATRETURN2[] RETURNMESSAGES = new BAPI_MATRETURN2[0];

            BAPI_MLAN[] TAXCLASSIFICATIONS = new BAPI_MLAN[0];

            BAPI_MARM[] UNITSOFMEASURE = new BAPI_MARM[1];

            BAPI_MARD STORAGELOCATIONDATA = new BAPI_MARD();

            BAPI_MARDX STORAGELOCATIONDATAX = new BAPI_MARDX();

            BAPI_MARMX[] UNITSOFMEASUREX = new BAPI_MARMX[1];

            BAPIMATHEAD HEADDATA = new BAPIMATHEAD();

            BAPI_MARC PLANTDATA = new BAPI_MARC();

            BAPI_MARCX PLANTDATAX = new BAPI_MARCX();

            BAPI_MARA CLIENTDATA = new BAPI_MARA();

            BAPI_MARAX CLIENTDATAX = new BAPI_MARAX();

            // Execute the BAPI

            BAPIRET2 result = client.SAVEDATA(CLIENTDATA, CLIENTDATAX, null,

                                      null, null, null, HEADDATA, null,

                                              null, null, null, PLANTDATA,

                                              PLANTDATAX, null, null,

                                              STORAGELOCATIONDATA, STORAGELOCATIONDATAX,

                                              null, null, null, null, null,

                                              null, ref EXTENSIONIN, ref EXTENSIONINX,

                                              ref INTERNATIONALARTNOS,

                                              ref MATERIALDESCRIPTION,

                                              ref MATERIALLONGTEXT, ref PRTDATA,

                                              ref PRTDATAX, ref RETURNMESSAGES,

                ref TAXCLASSIFICATIONS, ref UNITSOFMEASURE,

                                              ref UNITSOFMEASUREX);

            // Commit the BAPI

            client.BAPI_TRANSACTION_COMMIT("X");

            return result;

     }

    }

Sandeep Prabhu,

BizTalk Server Team