ycvodzf 发表于 2015-9-17 13:47:15

SAP vs. Non: Using RFC and .Net Connector

  Requirement:
  1,SAP.Connector.dll
2,SAP.Connector.Rfc.dll
  C# Console Demo:

1   using using SAP.Connector;
2
3   static void Main(string[] args)
4
5   {
6    // build the connection string
7    string cs = "ASHOST=IWDF9087 SYSNR=00 CLIENT=800 USER=C5022230 PASSWD=mysapcom";
8
9    // construct the proxy with connection string
10    SAPProxy1 proxy = new SAPProxy1(cs);
11
12    // create a SAP Table variable
13    BRFCKNA1Table tblCust = new BRFCKNA1Table();
14
15    // call the RFM method on the proxy
16    proxy.Rfc_Customer_Get("","A*", ref tblCust);
17
18    // output results to console
19    foreach (BRFCKNA1 row in tblCust)
20    {
21   Console.WriteLine("Customer Name: " + row.Name1);
22    }
23    // wait to end
24    Console.WriteLine("press enter to end");
25    Console.ReadLine();
26
27   } //main  VB ASP.NET Demo:

1         Dim proxy As New SAPProxy1
2         Dim oPRItems As New BAPIEBANCTable
3         Dim oPRItem As New BAPIEBANC
4         Dim oReturn As New BAPIRETURNTable
5         Dim oPRItemsAcct As New BAPIEBKNTable
6         Dim oPRItemAcct As New BAPIEBKN
7         Me.Destination1.Client = "420"
8         Me.Destination1.Username = "milesdunn"
9         Me.Destination1.Password = "thinkpad"
10         Me.Destination1.AppServerHost = "10.187.0.150"
11         Me.Destination1.SystemNumber = "00"
12         'Connect the SAP server
13         proxy.Connection = SAP.Connector.SAPConnection.GetConnection(Me.Destination1.ConnectionString)
14
15         Dim stbPRItems As DataTable
16         Dim row As DataRow
17         stbPRItems = Session("stbPRItems")
18         For Each row In stbPRItems.Rows
19
20             With oPRItem
21               .Acctasscat = row.Item("AcctAssignment")
22               .Doc_Type = Me.DLstDocType.SelectedValue
23               .Created_By = Me.txtUserName.Text
24               .Plant = Me.DLstPlant.SelectedValue
25               .Unit = row.Item("UM")
26               .Quantity = row.Item("Qty")
27               .Short_Text = row.Item("Description")
28               .Preq_Item = row.Item("LineNbr")
29               .Deliv_Date = row.Item("DeliveryDate")
30               .Preq_Date = row.Item("RequestDate")
31             End With
32             With oPRItemAcct
33               .Cost_Ctr = row.Item("CostCenter")
34               .Preq_Item = row.Item("LineNbr")
35             End With
36             oPRItems.Add(oPRItem)
37             oPRItemsAcct.Add(oPRItemAcct)
38         Next
39         proxy.Bapi_Requisition_Create(Requisition_Items:=oPRItems, Return0:=oReturn,Requisition_Account_Assignment:=oPRItemsAcct, skip_Items_With_Error:=True)
40
41         'Response.Write(oReturn.Item(1).Type & oReturn.Item(1).Message)
42         If oReturn.Count <> 0 Then
43             dgError.DataSource = oReturn
44             dgError.DataBind()
45         Else
46             dgError.DataSource = Nothing
47             dgError.DataBind()
48         End If
页: [1]
查看完整版本: SAP vs. Non: Using RFC and .Net Connector