RFC call input-output tables Case SAP interface program of 2

      c # interface calls RFC interfaces tutorial series 2, the use of this 2.0 interface. Haha, the world is constantly learn martial arts, exercisers out of the technology is the same.

       

String str111 = "" ;      // Material document number 
        String str222 = "" ;      // annual 
        IDestinationConfiguration ID = new new RfcConfig (); 
        RfcDestinationManager.RegisterDestinationConfiguration (ID); 
        RfcDestination prd = RfcDestinationManager.GetDestination ( " PRD_000 " ); // official environment region 000 
        RfcDestinationManager.UnregisterDestinationConfiguration (ID); 
        RfcRepository the repo = prd.Repository; 
        IRfcFunction companyBapi = repo.CreateFunction ( "ZM_PURCHASE_GOOD01");   //调用函数名

        try
        {
            IRfcTable tableSAP = companyBapi.GetTable("IT_POGO");   //表体
            for (int i = 0; i < gvlist1.Rows.Count; i++)     //  1 sapdt.Rows.Count
            {
                // TextBox txtnum = (TextBox)gvlist1.Rows[i].FindControl("txtnum");
                HiddenField hfQYA24 = (HiddenField)gvlist1.Rows[i].FindControl("hfQYA24");

                IRfcStructure st =tableSAP.Metadata.LineType.CreateStructure (); 
                st.SetValue ( " EBELN " , gvlist1.Rows [I] .Cells [ . 9 ] .Text.Trim ());            // purchasing only number "3020092357" 
                st.SetValue ( " EBELP " , gvlist1.Rows [I] .Cells [ 10 ] .Text.Trim ());                // PO single item numbers" 10 " 
                st.SetValue ( " Menge " , gvlist1.Rows [I] .Cells [ . 7 ] .Text.Trim ());         // purchase order number "1" 
                st.SetValue ( " REF_DOC_YR ", lblQY23.Text.Trim());                    //sap收货单号
                st.SetValue("REF_DOC", lblQY22.Text.Trim());                       //sap收货年度
                st.SetValue("REF_DOC_IT", hfQYA24.Value);
                tableSAP.Append(st);
            }

            companyBapi.SetValue("I_BWART", "105");
            companyBapi.SetValue("I_BUDAT", DateTime.Now.ToString("yyyyMMdd"));
            companyBapi.SetValue("ZFORM", "800");
            companyBapi.SetValue("ZOABH", model.QY02);    //单号

            companyBapi.SetValue("IT_POGO", tableSAP);
            companyBapi.Invoke(prd);   //执行函数

            str111 = companyBapi.GetString("E_MBLNR");
            str222 = companyBapi.GetString("E_MJAHR");
            IRfcTable OPTIONS = companyBapi.GetTable("RETURN");    //返回表格值
            bool IsFail = false;
            StringBuilder strMsg = new StringBuilder();
            for (int i = 0; i < OPTIONS.RowCount; i++)
            {
                OPTIONS.CurrentIndex = i;
                if (OPTIONS.GetString("TYPE").Equals("E"))
                {
                    IsFail = to true ; 
                    strMsg.Append (OPTIONS.GetString ( " the MESSAGE " )); 
                    strMsg.Append ( " <br> " ); 
                } 
            } 

            IF (IsFail) 
            { 
                SystemTools.displayTips ( " the SAP introduction details on exceptions:! " + strMsg. the ToString (), 0 , lblInfoMsg);
                 return ; 
            } 
        } 
        the catch (RfcAbapException EX)   // this exception specifically configured to obtain a user-defined exception information! ! ! ! 
        {
            twMsgbox.AjaxAlert (companyBapi.Metadata.GetAbapException (ex.Key) .Documentation); 
        } 
        the catch (RfcAbapRuntimeException EX)    // This Exception dedicated to acquiring operation exception during execution RFC! ! ! ! 
        { 
            TwMsgbox.AjaxAlert (companyBapi.Metadata.GetAbapException (ex.Key) .Documentation); 
        } 
        the catch (RfcBaseException EX)   // This is the total Exception Exception class, retrieves all exception if there is a plurality of the Catch, can not put The first one! ! ! ! 
        { 
            TwMsgbox.AjaxAlert ( " work order number does not exist or SAP database connection error message as follows:! " + Ex.Message); 
        }

 

Guess you like

Origin www.cnblogs.com/shuilong/p/11307050.html