VS2010+NCO3.0调用SAP BAPI获得定义的公司名单(源代码)


程序目的:检索SAP里定义的公司名单,然后获取每家公司的详细资料当用户选中一家公司时,在列表框中显示该公司的详细属性。最下面有源码下载地址。

 try
            {
                //提供必要的登录参数和获得RfcDestination对象对应到SAP系统中,你要调用的fm。
                RfcDestination SapRfcDestination = RfcDestinationManager.GetDestination("DEV");

                //使用RfcDestination对象的repository属性创建一个IRfcFunction对象为fm提供调用
                RfcRepository SapRfcRepository = SapRfcDestination.Repository;

                IRfcFunction BapiGetCompanyList = SapRfcRepository.CreateFunction("BAPI_COMPANY_GETLIST");
                IRfcFunction BapiGetCompanyDetail = SapRfcRepository.CreateFunction("BAPI_COMPANY_GETDETAIL");

                // 得到SAP定义的公司列表
                BapiGetCompanyList.Invoke(SapRfcDestination);

                IRfcTable CompanyTable = BapiGetCompanyList.GetTable("Company_List");

                IRfcStructure RfcReturn = BapiGetCompanyList.GetStructure("RETURN");

                // 遍历返回公司列表
                for (int CompanyPtr = 0; CompanyPtr < CompanyTable.RowCount; CompanyPtr++)
                {
                    CompanyTable.CurrentIndex = CompanyPtr;
                    string CompanyNumber = CompanyTable.GetString("COMPANY");
                    string Name1 = CompanyTable.GetString("NAME1");

                    BapiGetCompanyDetail.SetValue("COMPANYID", CompanyNumber);

                    // SAP定义公司的详细信息
                    BapiGetCompanyDetail.Invoke(SapRfcDestination);

                    IRfcStructure RfcReturnDetail = BapiGetCompanyDetail.GetStructure("RETURN");

                    IRfcStructure CompanyDetail = BapiGetCompanyDetail.GetStructure("COMPANY_DETAIL");

                    Company myCompany = new Company();

                    myCompany.CompanyNumber = CompanyNumber;
                    myCompany.Name1 = Name1;
                    myCompany.Name2 = CompanyDetail.GetString("Name2");
                    myCompany.City = CompanyDetail.GetString("City");
                    myCompany.Street = CompanyDetail.GetString("Street");
                    myCompany.PoBox = CompanyDetail.GetString("PO_BOX");
                    myCompany.PostalCode = CompanyDetail.GetString("POSTL_Cod1");
                    myCompany.Country = CompanyDetail.GetString("Country");

                    listBox1.Items.Add(myCompany);

                }
                if (listBox1.Items.Count > 0)
                {
                    listBox1.SelectedIndex = 0;
                    propertyGrid1.SelectedObject = listBox1.SelectedItem;
                }
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(string.Concat("RfcDestinationManager exception: ", ex.Message), "RFC 客户示例出错", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }


VS2010+NCO3.0调用SAP BAPI获得定义的公司名单(源代码)_第1张图片

下载地址:http://download.csdn.net/detail/szlaptop/4635341


你可能感兴趣的:(exception,list,String,SAP,2010)