Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass multiple tables to SAP using IRFC functions from .Net

I am passing 3 tables to an IRfcFunction which creates an order on SAP. When I try to debug this program it is not giving any error messages, but this is not creating any order on SAP.

I am looking for any kind of help or tips in solving this issue. Thank you for your time.

IRfcFunction orderDetails = _rfcDest.Repository.CreateFunction(strBapi);

RfcStructureMetadata metaData = _rfcDest.Repository.GetStructureMetadata("ZBAPI_A_STRU_ORDER_CREATE_PART");

IRfcStructure structPartners = metaData.CreateStructure();
            structPartners.SetValue("PARTN_ROLE", "SP");
            structPartners.SetValue("PARTN_NUMB", "110024");

            IRfcTable tblPartner = orderDetails.GetTable("PARTNERS");
            tblPartner.Append(structPartners);

            structPartners = metaData.CreateStructure();
            structPartners.SetValue("PARTN_ROLE", "SH");
            structPartners.SetValue("PARTN_NUMB", "110005");


            tblPartner.Append(structPartners);
            orderDetails.SetValue("PARTNERS", tblPartner);



            metaData = _rfcDest.Repository.GetStructureMetadata("ZBAPI_A_STRU_ORDER_CREATE_COND");
            IRfcStructure structConditions = metaData.CreateStructure();
            structConditions.SetValue("ITM_NUMBER", "10");
            structConditions.SetValue("COND_TYPE", "PR00");
            structConditions.SetValue("COND_VALUE", "30");
            structConditions.SetValue("CURRENCY", "USD");

            IRfcTable tblConditions = orderDetails.GetTable("CONDITIONS");
            tblConditions.Append(structConditions);
            orderDetails.SetValue("CONDITIONS", tblConditions);

            metaData = _rfcDest.Repository.GetStructureMetadata("ZBAPI_A_STRU_ORDER_CREATE_ITEM");
            IRfcStructure structItems = metaData.CreateStructure();
            structItems.SetValue("MATERIAL", "F500");
            structItems.SetValue("TARGET_QTY", "3");

            IRfcTable tblItems = orderDetails.GetTable("ITEMS");
            tblItems.Append(structItems);
            orderDetails.SetValue("ITEMS", tblItems);

            RfcSessionManager.BeginContext(_rfcDest);
            orderDetails.Invoke(_rfcDest);

            IRfcStructure bapiTable = orderDetails.GetStructure("RETURN");

            RfcSessionManager.EndContext(_rfcDest);
like image 365
Venky Avatar asked Nov 16 '11 19:11

Venky


1 Answers

IRfcFunction orderDetails = _rfcDest.Repository.CreateFunction(strBapi);

RfcStructureMetadata metaData = _rfcDest.Repository.GetStructureMetadata  ("ZBAPI_A_STRU_ORDER_CREATE_PART");

IRfcStructure structPartners = metaData.CreateStructure();
        structPartners.SetValue("PARTN_ROLE", "SP");
        structPartners.SetValue("PARTN_NUMB", "0011001234");

        IRfcTable tblPartner = orderDetails.GetTable("PARTNERS");
        tblPartner.Append(structPartners);

        structPartners = metaData.CreateStructure();
        structPartners.SetValue("PARTN_ROLE", "SH");
        structPartners.SetValue("PARTN_NUMB", "0011567890");


        tblPartner.Append(structPartners);
        orderDetails.SetValue("PARTNERS", tblPartner);



        metaData = _rfcDest.Repository.GetStructureMetadata("ZBAPI_A_STRU_ORDER_CREATE_COND");
        IRfcStructure structConditions = metaData.CreateStructure();
        structConditions.SetValue("ITM_NUMBER", "10");
        structConditions.SetValue("COND_TYPE", "PR00");
        structConditions.SetValue("COND_VALUE", "30");
        structConditions.SetValue("CURRENCY", "USD");

        IRfcTable tblConditions = orderDetails.GetTable("CONDITIONS");
        tblConditions.Append(structConditions);
        orderDetails.SetValue("CONDITIONS", tblConditions);

        metaData = _rfcDest.Repository.GetStructureMetadata("ZBAPI_A_STRU_ORDER_CREATE_ITEM");
        IRfcStructure structItems = metaData.CreateStructure();
        structItems.SetValue("MATERIAL", "F500");
        structItems.SetValue("TARGET_QTY", "3");

        IRfcTable tblItems = orderDetails.GetTable("ITEMS");
        tblItems.Append(structItems);
        orderDetails.SetValue("ITEMS", tblItems);

        RfcSessionManager.BeginContext(_rfcDest);
        orderDetails.Invoke(_rfcDest);

        IRfcStructure bapiTable = orderDetails.GetStructure("RETURN");

        RfcSessionManager.EndContext(_rfcDest);
like image 185
Venky Avatar answered Oct 10 '22 15:10

Venky