C # uses SAP NCO3.0 to invoke the SAP RFC function interface

Source: Internet
Author: User
Tags rfc

C # uses SAP NCO3.0 to invoke the SAP RFC function interface

Recently, the SAP RFC function was called using C #, and SAP provided the NCO3.0 component.

Download the component installation, and then refer to the "Sapnco.dll" and "Sapnco_utils.dll" two files.

Using SAP in the program. Middleware.connector;

See the following code specifically

Registering a client connection using the App. Config file configuration

 <?xml version= "1.0"?><configuration> <configSections> <sectiongroup name= "SAP. Middleware.connector "> <sectiongroup name=" clientsettings "> <section name=" destinationconfiguratio N "type=" SAP. Middleware.connector.rfcdestinationconfiguration,sapnco "/> </sectionGroup> </sectionGroup> </co Nfigsections> <sap.          middleware.connector> <ClientSettings> <DestinationConfiguration> <destinations> <add name= "Conn" user= "ky_pg01" passwd= "[email protected]" client= "002" sysnr= "ten" ashost= "192.168.0.22" LANG     = "ZH" group= "Public" max_pool_size= "5" ></add> </destinations> </DestinationConfiguration> </ClientSettings> </sap. Middleware.connector></configuration> 
Private Rfcdestination _rfcdestination = null;public DataTable DTR = new DataTable ();p ublic void registerdestination ()//                    Register Client {try {if (_rfcdestination = = null) {                _rfcdestination = Rfcdestinationmanager.getdestination ("Conn"); }} catch (Exception ex) {MessageBox.Show (ex).            Message); }} public string Invokerfcfunctiongetcompanyid (string datebegin, String dateend) {Irfcfunction            function = null; String str = string.            Empty;                try {function = _rfcdestination.repository.createfunction ("zky_fm_zm005b");//Call server function function. SetValue ("So_fkdat_b", datebegin);//incoming parameter function. SetValue ("So_fkdat_e", dateend);//incoming parameter function.                Setparameteractive (0, true); function. Invoke (_rfcdestination);//The function that executes the server call IRFCTable myrfctable = function.                GetTable ("it_zm005b");//RFC server function return value table struct name int lielement = 0; for (lielement = 0; lielement <= myrfctable.elementcount-1; lielement++) {Rfceleme                    Ntmetadata metadata = Myrfctable.getelementmetadata (lielement); Dtr. Columns.Add (metadata.                    Name);//Loop Create column} foreach (Irfcstructure dr in myrfctable)//Cyclic table structure Table { DataRow row = DTR.                    NewRow ();//Create New line for (lielement = 0; lielement <= myrfctable.elementcount-1; lielement++)                        {Rfcelementmetadata metadata = Myrfctable.getelementmetadata (lielement); Row[metadata. Name] = Dr. GetString (metadata. Name).                    Trim (); } DTR.                Rows.Add (row);            } This.dataGridView1.DataSource = DTR; } catch (Exception ex) {MessageBox.Show (ex.            ToString ());        } return str; }//call this in an event or method. Registerdestination (); This. Invokerfcfunctiongetcompanyid ("20120401", "20120901");

C # calls the SAP RFC function interface using SAP NCO3.0

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.