. NET using NCO to connect SAP from RFC query data code configuration connect SAP information

Source: Internet
Author: User
Tags rfc

Keywords: setting SAP connection information in code, parsing from RFC query data into a DataTable

1. Environment:

A. win7+64-bit operating system B. VS2012

C. nco3.0, a dedicated component of SAP for. NET development (64bit download URL: http://www.dllbang.com/dll/sapnco_dll)
D. (may be used) Microsoft Visual C + + 2005 Service Pack 1 for DLL files that are shipped nco3.0
Download URL: http://www.microsoft.com/en-us/download/details.aspx?id=14431
E. After installing NCO3.0, there will be Sapnco_utils.dll Sapnco.dll Rscp4n.dll under the C:\Program files\sap\sap_dotnetconnector3_x86 directory Libicudecnumber.dll Four DLL files, add references to the first two DLL files in the project (you can create a folder in the project, place the two DLLs, and then refer to the two DLLs in the folder), and the project. NET target platform changed to 4.0.

2. Purpose: an RfC that connects a query data from SAP, invokes and parses the returned data into a DataTable

3.RFC Structure: Structure of the zcp3_mmif002zbzz125:

1) input parameter import:input, such as:


The specific structure of input is as follows:

2) input/output parameters Tables: There are many, each of the following lines is one (in the code below, Jhnum and Jhtyp for example), such as:


The structure of Jhnum is as follows:

The structure of the Jhtyp is the same as the structure of the above jhnum.

3) Output Parameters-query results, is the HEADER in the input/output parameter tables, such as:

The header is structured as follows: (in the following C # code, the fields in the header are queried)

4. Test query conditions:

The bukrs:k999 in input
The werks:x666 in input

Tables Jhnum:sign:i Option:eq low:00000001 High: (Empty string "")

Jhtyp:sign:i option:bt low:1 high:2 in tables

5. Code

<span style= "Font-family:microsoft yahei;font-size:14px;" >//c# code to create the SAP Connection object class Sapconnectionpublic class Sapconnection:idestinationconfiguration {public RFCCONFIGP            Arameters getparameters (String destinationname) {rfcconfigparameters conf = new Rfcconfigparameters (); if (Destinationname = = "NSP")//to the object connected to SAP name {conf.                Add (rfcconfigparameters.appserverhost, "SAP Server IP Address"); Conf.                ADD (Rfcconfigparameters.systemnumber, "SAP instance number 00"); Conf.                ADD (Rfcconfigparameters.systemid, ""); Conf.                ADD (Rfcconfigparameters.user, "Login to SAP account"); Conf.                ADD (Rfcconfigparameters.password, "password"); Conf.                ADD (rfcconfigparameters.client, "SAP's Client number"); Conf.            ADD (Rfcconfigparameters.language, "en or en");        } return conf;        } public bool Changeeventssupported () {return true; } public Event RFcdestinationmanager.configurationchangehandler configurationchanged; }//a custom call to the RfC class public class NCOQUERYRFC {//Create an instance of the SAP Connection object class Sapconnection Global_dest, singleton mode private St                Atic rfcdestination global_dest; public static Rfcdestination Sapconninfo () {if (global_dest = = null) {Sapcon Nection con = new sapconnection ();//sapconnection class definition see code at the end Rfcdestinationmanager.registerdestinationconfigura            tion (con);            } global_dest = Rfcdestinationmanager.getdestination ("NSP");        return global_dest; }//Query RfC method public static string Getheadersfromsap () {rfcdestination dest = Ncoqu            Eryrfc.sapconninfo (); Rfcrepository Rfcrep = dest.            Repository; Irfcfunction myfun = Rfcrep. Createfunction ("zcp3_mmif002zbzz125"); The name of the RFC//incoming structure input irfcstructure input = myfun.            Getstructure ("INPUT"); InpUt.            SetValue ("Bukrs", "K999"); Input.            SetValue ("Werks", "X666"); Myfun.             SetValue ("input", input); The jhnum irfctable table = Myfun in the incoming tables tables.            GetTable ("Jhnum"); the table irfcstructure import = null for the jhnum to be passed in//RFC; var Structmeta = Rfcrep.            Getstructuremetadata ("Zcp3mmif002zbzz125_s05");//Is the structure of the Jhnum table reference in SAP import = Structmeta.createstructure (); Import.            SetValue ("sign", "I"); Import.            SetValue ("OPTION", "EQ"); Import.            SetValue ("Low", "00000001"); Import.            SetValue ("High", ""); Table.            Insert (import); Jhtyp irfctable table2 = myfun in the incoming tables table.            GetTable ("Jhtyp");            Irfcstructure import2 = null; var Structmeta = Rfcrep.            Getstructuremetadata ("Zcp3mmif002zbzz125_s05");            Import2 = Structmeta.createstructure (); Import2.            SetValue ("sign", "I"); Import2.            SetValue ("OPTION", "BT"); ImporT2.            SetValue ("Low", "1"); Import2.            SetValue ("High", "2"); Table2.                       Insert (IMPORT2); Myfun. Invoke (dest);//Call irfctable headtable = myfun.            GetTable ("header");//RFC return header structure Collection DataTable DT2 = new DataTable (); String[] Rfcheaderkeys = {"Jhnum", "Bukrs", "Butxt", "Werks", "NAME1", "Jhtyp"};//the column name in the DataTable to be returned foreach (str ing key in Rfcheaderkeys) {DT2.            Columns.Add (key);                }//loop puts the data inside the irfctable into the table for (int i = 0; i < (headtable.count); i++) {                Headtable.currentindex = i; for (int j = 0; j < dt. Rows.Count; J + +) {DataRow Dr = Dt2.                    NewRow ();                    foreach (string key in Rfcheaderkeys) {Dr[key] = headtable.getstring (key); } DT2.                Rows.Add (DR); }            }            return DT2; }}<span style= "White-space:normal;" ></span></span>

. NET using NCO to connect SAP from RFC query data code configuration connect SAP information

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.