您的位置:首页 > 编程语言 > C#

C# 实现调用 SAP Com组件 与 SAP数据的乱码问题

2009-09-01 16:01 513 查看
  C# 实现调用 SAP Com组件 收藏
 /// <summary>
        /// 登陆SAP系统
        /// </summary>
        /// <returns>登陆状态</returns>
        public LoginStatus LoginSAP()
        {
            try
            {
                SAPLogonCtrl.SAPLogonControlClass logon = new SAPLogonCtrl.SAPLogonControlClass();
                logon.ApplicationServer = ApplicationServer;     //SAP系统IP
                logon.Client = Client;                           //SAP客户端号
                logon.Language = Language;                       //SAP登陆语言
                logon.User = User;                               //用户帐号
                logon.Password = Password;                       //用户密码
                logon.SystemNumber = SystemNumber;               //SAP系统编号
                Conn = (SAPLogonCtrl.Connection)logon.NewConnection();

                if (Conn.Logon(0, true))
                {
                    Status = LoginStatus.Success;                //登陆成功
                }
                else
                {
                    Status = LoginStatus.Fail;                   //登陆失败
                }
                return Status;
            }
            catch (Exception exc)
            {
                throw(new Exception(exc.Message));
            }
        }

        /// <summary>
        /// 调用SAP系统函数模块
        /// </summary>
        /// <param name="strFunName">函数名称</param>
        /// <param name="strArgs">输入参数字典</param>
        /// <param name="strRetTabs">返回表结果字典</param>
        /// <param name="strResult">返回程序运行结果</param>
        /// <returns>返回表结果集</returns>
        public DataSet InvokSAPFun(string strFunName, ListDictionary strArgs, ListDictionary strRetTabs, ref ListDictionary strResult)
        {
            try
            {
                DataSet retDST = new DataSet();
                string[] array = new string[strResult.Count];
                strResult.Keys.CopyTo(array, 0);
                if (Status == LoginStatus.Success)
                {

                    SAPFunctionsOCX.SAPFunctionsClass func = new SAPFunctionsOCX.SAPFunctionsClass();
                    func.Connection = Conn;
                    //(1)
                    SAPFunctionsOCX.IFunction ifunc = (SAPFunctionsOCX.IFunction)func.Add(strFunName);               //调用函数模块
                    foreach (string arg in strArgs.Keys)
                    {
                        SAPFunctionsOCX.IParameter gclient = (SAPFunctionsOCX.IParameter)ifunc.get_Exports(arg);     //取得输入参数
                        gclient.Value = strArgs[arg];                                                                //设置参数值              
                    }
                    ifunc.Call(); //调用函数模块
                    //(2)
                    foreach (string ret in array)
                    {
                        SAPFunctionsOCX.IParameter NUMBER = (SAPFunctionsOCX.IParameter)ifunc.get_Imports(ret);      //返回程序运行结果
                        strResult[ret] = NUMBER.Value;
                    }
                    //(3)
                    SAPTableFactoryCtrl.Tables ENQs = (SAPTableFactoryCtrl.Tables)ifunc.Tables;                      //获取所有Tables
                    foreach (string tab in strRetTabs.Keys)
                    {
                        SAPTableFactoryCtrl.Table ENQ = (SAPTableFactoryCtrl.Table)ENQs.get_Item(tab);               //返回指定Tables
                        DataTable dat = ConvertTable(ENQ);
                        retDST.Tables.Add(dat);
                    }

                }
                return retDST;
            }
            catch (Exception exc)
            {
                throw (new Exception(exc.Message));
            }
        }

 

本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/Peak915/archive/2009/02/05/3863337.aspx

SAPFunctionsOCX.SAPFunctionsClass func = new SAPFunctionsOCX.SAPFunctionsClass();
                func.Connection = sapConn;
                SAPFunctionsOCX.IFunction ifunc = (SAPFunctionsOCX.IFunction)func.Add("ZCSB_WB_SBSC_CREATE_CHANGE");

SAPFunctionsOCX.IParameter piModiType = (SAPFunctionsOCX.IParameter)ifunc.get_Exports("PI_MODI_TYPE");
                piModiType.Value = "M";
                SAPFunctionsOCX.IParameter piSave = (SAPFunctionsOCX.IParameter)ifunc.get_Exports("PI_SAVE");
                piSave.Value = "Y";
                SAPFunctionsOCX.IParameter piBukrs = (SAPFunctionsOCX.IParameter)ifunc.get_Exports("PI_BUKRS");
                piBukrs.Value = "C6V0";
                SAPFunctionsOCX.IParameter piSpras = (SAPFunctionsOCX.IParameter)ifunc.get_Exports("PI_SPRAS");
                piSpras.Value = "1";
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息