Net Connector PDF
Net Connector PDF
NET Connector
Purpose
The SAP .NET Connector is a development environment that enables communication
between the Microsoft. NET platform and SAP systems. This connector supports RFCs
and Web services, and allows you to write different applications such as Web form,
Windows form, or console applications in the Microsoft Visual Studio.Net. With the SAP
.NET Connector, you can use all common programming languages, such as Visual Basic.
NET, C#, or Managed C++.
Features
Using the SAP .NET Connector and SAP .NET Proxy Wizard, you can:
Write .NET Windows and Web form applications that have access to SAP business objects
(BAPIs).
1. Develop client applications for the SAP Server. Here you can use either RFCs or
HTTP/SOAP/XML (outside-in).
2. Write RFC server applications that run in a .NET environment and can be installed starting
from the SAP system (inside-out).
Further Information
6. SAP.Net Connector: Architecture
7. Creating ASP .Net Applications using the SAP .Net Connector
8. SAP.Net Client
9. SAP.Net Server
10. SAP.Net Connector: Installation
11. SAP .Net Programmers Reference
For more information on the SAP .NET Connector, see the SAP Service Marketplace at
the internet address:
service.sap.com
You can use both RFC and SOAP for the connection between the SAP.Net Connector and the
SAP system. The choice of protocol depends on the release status of your SAP system and on its
availability inside or outside of the firewall.
SAP.Net Connector: Runtime Architecture
The following example shows how to create a .NET project using Microsoft Visual
Studio .NET. In the example, a client application reads and displays customer data from
an SAP System using a search value and then displays it in a data grid.
The example uses the function module RFC_CUSTOMER_GET, which requires that
customer data exist in the target SAP System, for example, in IDES. Although it is
possible to rename all development objects and generated proxy classes, default names
are used in this example. This example is provided as part of the connector sample code
(DNCWebApp).
Procedure
...
1.
2. To create a new C# Web form project choose New New Project Visual C#
Projects ASP .NET Web Application.
You can also create a project in any other common programming language for .NET,
for example, in Visual Basic .NET. In this case, you must add the SAP .NET proxy
classes as a separate project in the Microsoft Visual Studio .NET solution.
3.
c.
Select Web Project Items SAP Connector Class and choose Open.
You can use search filters to look for the Remote Function Modules. In the example,
enter the search argument RFC_CUST* in Name-Filter and select
RFC_CUSTOMER_GET.
g. Add the modules to your proxy object and choose Next.
The proxy classes for the referenced table and structure types are automatically
created and added to the project.
6.
7.
c.
9.
14.
If you select Save this login information will be stored as an encrypted cookie on
your computer and will provide an alternative single sign-on capability the next time
you wish to access the site. If you do not select Save, the login information will still
be saved in the ASP .NET session state but will be lost once the browser is closed.
Enter a search argument, for example A* in the TextBox field and choose Search.
Your application connects to the SAP System and displays the requested data in the
DataGrid.
Integration
As of SAP Web AS 6.10, the .NET Connector can communicate with the SAP server
either by RFC or using the SOAP protocol. Up to and including SAP_BASIS release
4.6D, communication is only possible using RFC.
As long as the .NET Connector client and the SAP server are both within a firewall,
communication can occur using both RFC and SOAP, although in this situation using an
RFC connection achieves considerably better performance. For communication outside
the firewall, SOAP must be used.
Configuration of the protocol call within the .NET client can be controlled using a
separate program.
Further Information
Project Types
RFC or SOAP
Authentication
Asynchronous Methods
IDoc
Project Types
We recommend using the SAP Connector Class project template for creating SAP .NET
Connector projects as you can reuse the proxy code. It is also worth considering placing
the SAP proxies in the global assembly cache if several applications are making use of
them.
Alternatively you can add the SAP connector class directly to another type of project
such as a Windows Form, ASP .NET web application or ASP.NET web service. With
other project types you can generate the SAP proxy directly in the project or reference an
existing SAP Connector Library. When you select an existing SAP connector library you
have to verify that your project has a reference to the SAP .Connector library
(sap.connector.dll).
RFC or SOAP
The choice of whether to use RFC or SOAP depends on which release of the SAP system
is available (for example, releases before 6.20) and other issues such as whether the
system is available on your intranet or outside the firewall. Depending on the connection
string used to create the proxy (for example, if it begins with http://), SOAP will be used
to connect to the SAP system otherwise RFC will be used to connect to the SAP system.
Authentication
The SAP .NET Connector supports all SAP authentication options including user name,
password and various single sign-on options such as Kerberos, NTLM, X.509 certificates
and SAP Logon tickets. In addition, the connector makes it easy to perform SAP
authentication in your application with the SAPDestination and SAPLogonDestination
classes and in ASP .NET applications with the SAPLogin Form.
We recommend you use the SAP logon classes rather than manually creating a
connection string with the logon information. The SAP logon classes support getting
logon information at runtime from a configuration file, SAPGUI or as another alternative,
programmatically, for example from Microsoft Active Directory.
Asynchronous Methods
Client applications support asynchronous method invocations. The main benefit of this is
that your SAP client application remains responsive even when the RFC call is taking
some time.
Many areas of the .NET framework support asynchronous programming. SAP .NET
Connector classes are built in C# and take advantage of many .NET features including
asynchronous method invocations. Asynchronous programming techniques are important
with SAP RFC calls as some calls can take a long time to complete. During this time, a
single threaded client application seems to be unresponsive as the main thread of
execution is waiting for the SAP method call to complete. Many RFC calls happen very
quickly and the user may not notice, others may take some time and the application
appears to be unresponsive.
With .NET Connector, we can take advantage of many features of the Microsoft Common
Language Runtime (CLR) including support for easy asynchronous programming. This
powerful feature is not available on any other SAP connector at this time. In all other
connectors, BAPI and RFC calls are synchronous calls.
The Asynchronous method calls use the standard .NET delegate callback mechanism. It
provides the programmer with a familiar and powerful way of performing asynchronous
calls in the SAP Client application.
When we use asynchronous methods from the .NET Connector wizard, the proxy
contains two additional methods for each RFC: Begin<RFC Name> and End<RFC
Name> and three additional variables to manage the asynchronous result.
When Begin<RFC Name> is called, CLR queues the request and returns immediately
to the caller. The target method will be on thread from the thread pool. The original
thread is free to continue executing in parallel to the target method. If a callback has been
specified on Begin<RFC Name>, it will be called when the target method returns. In
the callback, the End<RFC Name> method is used to obtain the return value and the
in/out parameters. If the callback was not specified on Begin<RFC Name>, then
End<RFC Name> can be used on the original thread that submitted a request.
A queue index to determine the sequence. The queue index begins with zero.
you must have installed SAPGUI on your developer workstation. You cannot use the
integrated ABAP debug option with web applications because they run under another
Windows context that is invisible to the interactive user.
Detailed traces can be written using the tracing flag. Alternatively you can set the
environment variables RFC_TRACE and CPIC_TRACE to have trace files written to
your application directory.
During initial design and debugging it is often useful to run the SAP RFCfunction
directly in the SAP system using transaction SE37. It is easier to isolate the problem once
you are sure that input values are valid. In addition, you should reference the SAP
function module documentation. The SAP data dictionary, which is integrated in the
function editor, also gives you information on valid input values.
In the SAP system, there are automatic formatting functions that are not available in the
connector, for example to add leading zeroes to a customer or invoice number. If the
function is working in the SAP system but not in your proxy, it could be that the SAP
system has applied one of these automatic-formatting routines but you did not.
The SAP system provides extensive tracing and monitoring capabilities inside of the
system as well, for example within the area Tools Administration Monitoring.
IDOC
SAP Intermediate Documents (IDOCS) are EDI like documents that are asynchronous in
nature. IDOCS are often used in sending business documents (for example sales orders)
from your SAP system to a trading partner or other system. The actual TRFC call to
submit the IDOC to SAP is performed synchronously and very quickly, but the actual
business processing can happen at some later time defined in the SAP system. The
outbound result (for example, sales order confirmation) can also happen at some later
time. With RFC calls, the business processing is done immediately albeit on a different
thread if we make use of the asynchronous methods described above. IDOCS offer
additional queuing and retry capabilities.
SAP .NET Connector supports both submitting and receiving SAP IDOCs. The
SAPIDOCSender class submits IDOCs and the SAPIDOCReceiver class can be used
with a TRFC server to receive IDOCS.
To work with IDOCS you must use transactional RFC. In the SAPIDOCSender and
SAPIDOCReceiver classes, SAP provides for you a TRFC client implementation that
works with the appropriate function modules in SAP.
Prerequisite
The .NET Server is defined as an RFC destination in the SAP system.
Integration
As of SAP Web AS 6.10, the SAP .NET Connector can communicate with the SAP
system either by RFC or using the SOAP protocol. Up to and including SAP_BASIS
release 4.6D, communication is only possible using RFC.
As long as the SAP .NET Connector server and the SAP system are both within a
firewall, communication can occur using both RFC and SOAP, although in this situation
using an RFC connection achieves considerably better performance. For communication
outside the firewall, SOAP must be used.
The .NET Server is configured as an RFC destination in the SAP system in exactly the
same way as any other (external) RFC server, using transaction SM59.
Further Information
Key Steps
Authentication
Key Steps
When calling a .NET program from an SAP system, we distinguish the following key
steps, as shown above:
1.
The .NET program must register itself on the SAP gateway host
2. The SAP system and the .NET program must implement the same method
interface, for example, the function module name and parameters from the SAP
system.
3. The SAP system initiates the call to the .NET program using the CALL
FUNCTION DESTINATIONkeyword
4.
The .NET program must return the appropriate parameters to the SAP system
The SAP server code that is generated by the connector and provides the functionality
described above as well as a default implementation. This allows the Visual Studio
developer to focus on the implementation and not have to understand how RFC servers
work in detail.
Authentication
Unlike client applications, no user name and password is required to register a server on
the SAP gateway. Instead, the program ID, gateway host, gateway service and code page
must be provided. Once the server is registered on the gateway inside the SAP system, it
can be accessed from SAP programs. The computer where the RFC server is running
must grant permissions to the SAP service user to use the necessary resources on that
machine.
For TRFC servers you also have the TRFC monitor (SM58). For QRFC you have the
SAP Queue monitor (transaction SMQ2) to monitor QRFC calls.
Just as the SAP client solution offers integrated Abap/4 debugging for .NET clients, you
can set a breakpoint in your RFC server code, call the function from the SAP system and
examine the values sent to you from the SAP system in debugging mode within Visual
Studio .NET.
Overview of Classes
Samples
Overview of Classes
Class
Explanation
SAPClient
SAPServer
SAPConnection
SAPConnectionPool
Destination
SAPLogonDestination
SAPLoginProvider
RfcException
RfcAbapException
RfcCommunicationException
RfcLogonException
RfcSystemException
RfcQueueItem
RfcTID
SAPTable
SAPStructure
SAPIDocSender
SAPIDocReceiver
SAPClient Class
1.
2.
3.
SAPClient Methods
4.
SAPClient Exceptions
5.
6.
Authentication
7.
SAPIDocSender Class
8.
Asynchronous Methods
9.
10.
11.
Connection Classes
12.
SAPClient Class
SAPClient is the base class for .NET applications wishing to use SAP functionality.
This class is maintained by the SAPConnectorGenerator custom tool and the
SAPProxy wsdl metadata file. It should not be necessary to manually update it. SAP
client proxies are instances of this class.
For a list of members of this type see SAPClient Methods.
[C#]
Public class SAPClient:
System.Web.Services.Protocols.SoapHttpClientProtocol
Remarks
In the SAP client solution, SAP is the server and the .NET application is the client that
interacts with the RFC. When you generate an SAP client application, a WSDL file is
added to your Visual Studio .NET project. This SAPWSDL file in coordination with a
custom tool in Visual Studio creates several C# classes needed to communicate with the
SAP system via either RFC or SOAP. There is one class for the proxy itself, one for each
export parameter and two for each Table parameter in your RFC.
The SAP RFC is called as a method of the proxy object. There can be one or more RFC
per proxy. For example you could have a proxy with all customer related RFCs in one
library. The parameters for each RFC can be customized within the Visual Studio
designer so that optional parameters can be removed, parameters can be renamed and
default values provided. You can also customize SAP structures by renaming or removing
fields.
Visual Studio developers can work with the SAP proxies in their choice of programming
language. The proxies themselves are generated in C# so for projects written in other than
C# you have to add a new project of type SAP Connector class to the Visual
Studio solution.
To add the SAP Proxy to your Visual Studio project you have the following options:
1. Add the proxy to another project type (for example Winform, ASP .NET project,
webservice)
Procedure
...
1.
2.
Explanation
Explanation
from an SAP IFR, you must have a URL for the
WSDL file
In the near future, the SAP IFR will be the
central repository for SAP metadata including
WSDL files
SAP Server
3. If you generate proxies from an SAP server, enter the following information in the
Enter Logon information screen:
Input
Explanation
System
Host
ID
Client
User
Password
Beautify name
4. Select the Remote Function Modules (RFM) you want to use in your proxy object.
You can use the following search filters to look for the function modules:
Option
Explanation
Name-Filter
Group-Filter
After the code has been generated, you can see an SAP proxy WSDL file added to your
project. This WSDL file in coordination with Visual Studio and the
SAPConnectorGenerator custom tool allows you to manage the SAP proxies
automatically.
If you choose to generate the proxy from the SAP IFR you will be asked for the URL of
the IFR Server.
If you choose to generate a proxy from a Standard WSDL file you will be asked for the
path or URL to that WSDL file.
Type of Object
RFC functions (shown as method icon)
SAP table class (shown as SAP table icon)
SAP structure class (shown as class
icon)
Example in Designer
Solution Customizing
These options may be set on the SAPProxy sapwsdl file in the designer. Based on
this input the SAP proxy C# classes will be updated automatically.
Beautify
ClassName
CreateAsyncs
CreateTRFC
CreateQRFC
ProxyType
Method Customizing
Exceptions
Parameters
UseIOStructs
AbapName
OptionalParameters
RemovedParameters
TotalParameters
SAPStructure Customizing
Fields
Filename
SAPTable Customizing
it is called in ABAP
SAPClient Methods
Public Constructors
public SAPClient
(SAP.Connector.Destination
destination)
public SAPClient
(System.String
ConnectionString)
public SAPClient ( )
Public Methods
Public void <RFC Name> (RFC
parameters)
Public void TRFC<RFC Name>
(RFC parameters, RFCTID)
Public void QRFC<RFC Name>
(RFC parameters,
RFCQueueItem)
Public System.IAsynchResult
Begin<RFC Name> (RFC
parameters,
System.AsynchCallback, object
asynchState)
Public void End<RFC
Name>(system.iasycresult
asyncresult, ref parameters)
public System.Boolean
CommitWork ( )
public void ConfirmTID
(SAP.Connector.RfcTID tid)
public System.Boolean
RollbackWork ( )
Public Properties
public
SAP.Connector.SAPConnection
Connection [ get, set ]
public System.Int32
RfcTotalMiliSeconds
Private Methods
protected System.IAsyncResult
BeginSAPInvoke (System.String
method , object[ ]
methodParamsIn ,
System.AsyncCallback callback
, System.Object asyncState)
protected object[ ]
EndSAPInvoke
(System.IAsyncResult ar)
protected object[ ] SAPInvoke
(System.String method ,
object[ ] methodParamsIn)
public void tRfcInvoke
(System.String method ,
object[ ] methodParamsIn ,
SAP.Connector.RfcTID tid)
public void qRfcInvoke
(System.String method ,
object[ ] methodParamsIn ,
SAP.Connector.RfcQueueItem
qItem)
public void ActivateQueue
(System.String QueueName)
public void DeativateQueue
(System.String QueueName)
SAPClient Exceptions
Errors in the .NET Connector are thrown as .NET exceptions. An exception is the
preferred method to handle errors because exceptions are harder to ignore than are return
codes. They also provide you detailed information to create more robust applications.
The SAP .NET Connector has the following exception classes:
RfcCommunicationException
RfcLogonException
RfcSystemException
RfcAbapException
RfcException
1.
RfcMarshalException
Example
try
{
// Call methods here
proxy.Connection.Open();
proxy.Rfc_Function_Search(txtRFC.Text,"EN", ref tblRFC);
}
catch (RfcCommunicationException ex)
{
MessageBox.Show(ex.ToString());
return;
}
catch (RfcLogonException ex)
{
MessageBox.Show(ex.ToString());
return;
}
catch (RfcAbapException ex)
{
switch (ex.AbapException)
{
case (SAPProxy1.No_Function_Found):
MessageBox.Show("no function found");
break;
case(SAPProxy1.Nothing_Specified):
MessageBox.Show("Nothing specified");
break;
default:
MessageBox.Show("Some unknown abap error occurred");
break;
} //switch
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
return;
}
finally {proxy.Connection.Close();}
Further Information
2.
RfcException
3.
RfcCommunicationException
4.
RfcLogonException
5.
RfcSystemException
6.
RfcAbapException
1.
2.
3.
4. Use Single Step (F5) to examine the code execution and variable values in the SAP
function debugger window, part of the Abap/4 developer workbench.
You can turn on tracing in the SAP system by setting the environment variable
CPIC_TRACE and RFC_TRACE. For more information on RFC tracing, refer to SAP
Note 65325.
You can do advanced tracing within the SAP system, for example
from transaction code SM50 and by examining the work process trace
files (for example, dev_w0 in the SAP work directory).
We recommend developers to use the SAP .NET Connector exception
classes in their code to determine why an error has occurred and to use as
a starting point for debugging.
TRFC applications can be monitored from the TRFC monitor
(transaction SM58). QRFC applications can be monitored from QRFC
monitor (transaction SMQ2).
Authentication
The SAP Connector can support all SAP authentication mechanisms including:
X.509 Certificates
And in addition the SAP login form uses standard ASP .NET forms authentication to
provide an alternative single sign-on capability.
The following logon controls are available to manage the SAP authentication in your
project.
Destination
SAPLogonDestination
SAPLoginProvider
Further Information
1.
2.
Single Sign-On
Single Sign-On
Single Sign-On (SSO) is a simplified method of logging on to the SAP system without
reducing security. When a system has been configured for Single Sign-On, an authorized
user who has logged on to the operating system can access the SAP system simply by
selecting it in the SAP logon window or clicking on the shortcut. The user is
authenticated by Windows or some other trusted authority so no SAP password is
required. All SAP supported single sign-on options are also supported by the connector.
Scenario to Use
Kerberos
NTLM
X.509 Certificates
Microsoft Passport
SAPSSO2
SAPLoginForm
SAPSSO1
firewall
Same as X.509 certificates
With Enterprise Portal
User name and password authentication
in an ASP .NET web form can be used
for all web scenarios
With older ITS scenarios
Further Information
X.509 Certificates
Destination Class
SAPLogonDestination Class
SAPLoginProvider Class
SAPIDocSender Class
The SAPIDocSender class is a TRFC client used to submit SAP intermediate
documents to an SAP system for later processing. An example of an IDOC might be a
customer sales order or a material master record. IDOC records are typically used in EDI
scenarios. See the IdocSubmit sample for example code.
[C#]
public class SAPIDocSender : SAP.Connector.SAPClient
Public Constructors
public SAPIDocSender
(System.String
ConnectionString)
public SAPIDocSender ( )
Public Methods
Remarks
An IDOC will consist of three segments, the header (EDIDC), the body (EDIDD) and the
status (EDIDS). The EDIDC record can contain two formats (EDIDC or EDIDC40)
depending on the version of the IDOC. The body of the IDOC will differ depending on
what IDOC type and release it is. The status record is only maintained inside of the SAP
system and is not relevant to submit an IDOC.
Example
Asynchronous Methods
With SAP .NET Connector, we can take advantage of many features of the CLR
including support for easy asynchronous programming. This powerful feature is not
available on any other SAP connector at this time. In all other connectors, BAPI and RFC
calls are synchronous calls.
When we use asynchronous methods from the SAP .NET Connector wizard, the proxy
contains two additional methods Begin<RFC name> and End<RFC Name>.
When Begin<RFC name> is called, CLR queues the request and returns immediately
to the caller. The target method will be on thread from the thread pool. The original
thread is free to continue executing in parallel to the target method. If a callback has been
specified on the Begin<RFC name>, it will be called when the target method returns.
In the callback, the End<RFC name> method is used to obtain the return value and the
in/outparameters. If the callback was not specified on the Begin<RFC name>, then
End<RFC name> can be used on the original thread that submitted a request.
When working with asynchronous calls, we need three additional variables compared to a
synchronous RFC call
When working with asynchronous calls, we need three additional variables compared to a
synchronous RFC call.
Variable
System.IAsyncResult asyncresult
System.AsyncCallback callback
What It Does
A return of IAsyncResult is required to
implement Asynchronous Method
signatures. The result of the call
(IAsyncResult) is returned from the
begin operations, and can be used to obtain
status on whether the asynchronous begin
operations has completed. The result object
is passed to the end operation, which
returns the final return value of the call.
A delegate class that is called when the
operation has completed. If null, no
delegate is called. We can either use a
callback delegate as shown below or pass
the AsyncCallback delegate as null. In
that case, no delegate will be called and we
have to check the status ourselves. To
object asyncState
Example
The following Winform sample shows the code for asynchronous method call (SAPAsyncSearch
method).
Example
The Winform SAPUpdateTRFC method gives an example of TRFC coding.
private bool SAPUpdateTRFC()
{
/* this routine updates the customer list to SAP using (T)RFC */
RfcTID myTid = SAP.Connector.RfcTID.NewTID();
Debug.WriteLine("RFC tid is " + myTid.ToString());
try
{
proxy.TRfcRfc_Customer_Update(ref brfcknA1Table1, myTid);
}
catch (Exception ex)
{
Debug.WriteLine(ex.ToString());
return false;
}
// if you don't confirm the TID, the update is rolled back in SAP.
proxy.ConfirmTID(myTid);
return true;
} //SAPUpdateTRFC
Example
private bool SAPUpdateQRFC()
{
/* this routine updates the customer list using (Q)RFC
* use SMQ2 to see results in SAP */
RfcQueueItem mySAPQueue = new RfcQueueItem("DNCQueue", g_queIndex,
RfcTID.NewTID());
try
{
proxy.QRfcRfc_Customer_Update(ref brfcknA1Table1, mySAPQueue);
}
catch (Exception ex)
{
Debug.WriteLine(ex.ToString());
return false;
}
g_queIndex ++; //increment the queue index for next time
return true;
} //SAPUpdateQRFC
Connection Classes
SAPConnection Class
SAPConnectionPool Class
SAPConnection Class
TheSAPConnection class is used to manage the connection to the SAP system. Some
basis information about the system you are connected to can also be determined from this
class.
[C#]
public class SAPConnection : System.Object
Public Constructors
public SAPConnection
(SAP.Connector.Destination
dest)
public SAPConnection
(System.String connString)
Public Methods
Accept
Close
Dispose
Finalize
Open
Public Properties
ApplicationServer
CodePageEncoding
ConnectionString
KernelRelease
OwnCodePage
PartnerCodePage
SystemID
SystemNumber
SystemRelease
SAPConnectionPool Class
Connection pooling is a more sophisticated way of managing SAP Connections. In a twotier deployment we do not recommend to use this as each client has its own connection.
In an n-tier deployment where multiple users are using the same connection attributes
(for example a web site that is accessed by many users) it may make sense to use
connection pooling. Alternatively, consider using the SAPLogin Provider and
SAPLogin Form.
[C#]
public class SAPConnectionPool : System.Object
Public Constructor
public SAPConnectionPool ( )
Public Methods
public static
SAP.Connector.SAPConnection
GetConnection (System.String
connectionString)
public static void
ReturnConnection
(SAP.Connector.SAPConnection
connection)
Example
The sample application DNCWebServiceSample uses connection pooling.
using(proxy.Connection =
SAP.Connector.SAPConnectionPool.GetConnection(this.destination1.Connect
ionString))
dataGrid1.DataSource = BRFCKNA1Table1;
using(proxy.Connection =
SAP.Connector.SAPConnectionPool.GetConnection(this.destination1.ConnectionString))
{
// call the RFC with the signature defined by SAP
proxy.Rfc_Customer_Get(CustNo, CustName, ref tblCust);
}
1.
A TABLE is always passed by REF and is therefore both an IN and OUT parameter. Since
a table is a collection you can fill it in a loop for example:
Alternatively you can create an additional constructor with the parameters you want to fill.
for(int i = 0; i < number_of_lines; i++)
{
IDRANGETable.Add(new IDRANGE(I,BT,0000001000));
}
For TABLES that are input parameters you have to populate the values yourself before
calling the SAP RFC. For TABLES that are output parameters the SAP marshalling code
populates the values for you automatically.
2.
When an exception is returned, the TABLE object is not reinitialized. If you had made a
previously successful method call and the TABLE contains values, these will not be
reinitialized after an exception has occurred. In this case you can keep the last (good)
results. You can use the tables clear() method to initialize the values yourself.
3.
SAP Tables are built on the .NET CollectionBase class. Therefore they support
indexers and other array operations to allow for easy management of the members in the
array.
Field metadata information can be determined from the structure using the static method:
GetSAPFieldsSchema(System.Type t).
The type parameter is the data type of SAPStructure (in this case the type of
BAPICUSTOMER_IDRANGE).
SAPField[ ] myFields =
BAPICUSTOMER_IDRANGE.GetFieldsSchema(typeof(BAPICUSTOMER_IDRANGE));
You can get metadata information about each field either with a foreach statement or
using the length property of the SAPField array.
SAPTable Class
SAPStructure Class
ABAP Type
.NET CLS
C (String)
I (integer)
F (Float)
D (Date)
String
Int32
Double
String
T (Time)
P (BCD Packed, Currency, Decimal, Qty)
N (Numc)
X (Binary and Raw)
RFC String
XString
String
Decimal
String
Byte [ ]
String
String
ABAP type N (numeric) data is mapped to a STRING data type in the C# proxy. It contains
numeric data such as invoice numbers. Some type N fields like invoice number or
customer number require you to enter the string with leading zeroes. If in your application
the customer number field is numeric, be sure to convert your entry back to the
appropriately formatted string before using it in the proxy.
Date / Time fields are mapped to .NET STRING data types in the C# proxy. The format of
the string is the same as the SAP internal storage of the date and time. Specifically for date
this is YYYYMMDD and for time it is HHMMSS. The SAP .NET connector provides functions
specifically to help you convert from SAP Date/Time fields stored as string to a .NET date
or time field.
Structure
Table (ITAB)
SAPTable Class
The SAPTable class represents a very common data type in the SAP system and is
frequently used to hold the results of the RFC call. It is occasionally used to pass in
selection variables to the RFC call. A SAPTable is made of SAPStructures of a
single type. For example a SAPTable called RFCFuncTable would be made up of
RFCFunc structures (rows).
[C#]
public class SAPTable : System.Collections.CollectionBase
Public Constructors
protected SAPTable ( )
Public Methods
Add (SAPStructure)
Contains(SAPStructure)
CopyTo(SAPStructure[ ],
int)
CreateNewRow()
GetElementType()
IndexOf(SAPStructure)
Insert(int,
SAPStructure)
Remove(SAPStructure)
SortBy(string fieldname,
string direction)
ToADODataTable
FromADODataTable
Public Properties
This[int]
Example
See the Winform sample for examples of using the SAPTable class.
SAPStructure Class
The SAPStructure class represents a very common data type in the SAP system and
is frequently used to hold the results of the RFC call as part of a SAPTableor as a BAPI
error return. A structure is made up of several simple data types and can be thought of as
a row of a table. The SAPStructure is generated for you by the SAP .NET Connector
and should not be modified outside of the SAPConnectorGenerator tool.
[C#]
public class SAPStructure : System.Object
Public Constructors
protected SAPStructure ( )
Example
See the Winform sample application for example code dealing with SAP Structures.
IMPORT
Always pass values from the calling program to the function module unless this is marked
as an optional parameter.
CHANGING
These are passed to the function module from the calling program and are then passed
back to the program.
EXPORT
These are passed from the function module to the calling program unless marked as an
optional parameter.
TABLES
These represent an array of SAP structure instances. They can be IN or OUT parameters.
OPTIONAL
Parameters can also be defined as optional.
C# Parameter Type
IMPORT
EXPORT
CHANGING
TABLES
IN
OUT
REF (In/Out)
REF (In/Out)
Samples
Several samples are provided with the connector to help you understand how the proxies
work and to illustrate the topics discussed in this reference. They are provided without
warranty or support.
The samples are designed to work against the Mini SAP Web Application Server 6.20 or
any system supporting RFC_CUSTOMER_GET and RFC_CUSTOMER_UPDATE. For the
IDOC samples you need a system than can accept IDOCs. An Exchange_rate01
IDOC type is provided as a sample that should work with the mini SAP system. All
samples are written in Microsoft C#, except for the Visual Basic windows form sample.
Before using the samples, be sure to verify the login parameters in the SAP destination
component. The samples are located in the folder Samples. To launch the samples in
Visual Studio .NET double-click on Samples.sln.
Further Information
Further information on the different programming samples you will find here:
Webform Samples
SAPClient programming
Working with SAP Tables (sorting, converting to ADO .NET, data binding)
The Windows form sample uses the RFC_CUSTOMER_GET function module. It accepts
as input a customer name string (for example, A*) and returns in a datagrid all customers
that match that selection.
To use the sample, you have to enter an SAP customer search selection criteria. All
functions are available from the samples application menu.
To use the option Save Results to SQL Server you must set the SQL logon parameters in
the component SqlConnection1 on form1. To do this, click on the property
ConnectionString and use the drop down box. Let the Wizard construct the
connection string for you. You also need a table named cust in the Northwind database,
and a stored procedure called Insert_cust. The SQL script to create both of these
objects is located in the subfolder SQL.
Webform Samples
The web form sample is the simple ASP .NET web form shown in the guide and
illustrates the following:
SAPClient programming
Before using this sample, you have to share the folder DNCWebApp.
Using the RFC Server host with the same connection information for each server
This sample uses command line arguments to connect to the SAP gateway (for example,
aMYPROGID gLOCALHOST xSAPGW00), where a is the program ID used in
your TCP/IP destination, -g is the gateway host and x is the gateway service.
You can set the command line arguments in the Visual Studio .NET debugger by rightclicking on the project RFCServerConsole and selecting Properties
Configuration properties Debugging Command Line Arguments.
Before calling this RFC server in the SAP system, you must have setup a TCP/IP
destination in your SAP system (type registration). You can call this sample RFC server
by running RFC_CUSTOMER_GET in single test from the RFC function builder
(transaction SE37) inside of the SAP system, with the destination of your TCP/IP
destination. Alternatively, you can write an Abap/4 program as described in Calling RFC
.Net Server from SAP Programs.
An example ABAP/4 program is provided in this samples ABAP directory.
Example
*&--------------------------------------------------------------------*& Report ZRFCSERVERCALL
*&
**&-------------------------------------------------------------------*& This program can be used with the RFCServerConsole sample
*& Source is available in %\RFCServerConsole\ABAPProgram
*&--------------------------------------------------------------------REPORT ZRFCSERVERCALL
.
DATA: TBLCUST like BRFCKNA1 occurs 0 with header line.
PARAMETERS: P_CUSTNO like KNA1-KUNNR, P_CUSTNA like KNA1-NAME1,
P_DEST(15) TYPE C.
CALL FUNCTION 'RFC_CUSTOMER_GET' DESTINATION P_DEST
EXPORTING
KUNNR
= P_CUSTNO
NAME1
= P_CUSTNA
TABLES
CUSTOMER_T
= TBLCUST
EXCEPTIONS
NOTHING_SPECIFIED = 1
NO_RECORD_FOUND
= 2
OTHERS
= 3.
CASE SY-SUBRC.
WHEN 0.
LOOP AT TBLCUST.
WRITE: / SY-TABIX, TBLCUST-KUNNR, TBLCUST-NAME1, TBLCUST-ORT01.
ENDLOOP.
WHEN 1.
WRITE: / 'You need to specify a value ', SY-MSGV1.
WHEN 2.
WRITE: / '.NET component didnt find anything ', SY-MSGV1.
WHEN 3.
WRITE: / 'Some other error occurred ', SY-MSGV1.
WHEN OTHERS.
WRITE: / 'Something is wrong if we get here'.
ENDCASE.
The entry point in the C# method is the method with the function module name
being called from the SAP system (for example, RFC_CUSTOMER_GET). In Microsoft
Visual Studio, you can set a breakpoint here and examine the input values from the
SAP system. This provides a similar idea to the ABAP_DEBUG functionality that is
provided in the client proxy.
How to install a Windows Service that is also an SAP RFC .NET server
Before running this sample, you must install it using the Visual Studio utility
Installutil.exe.
Using the Visual Studio .NET command line, navigate to the folder containing
Installutil IdocReceiverService.exe (for example,
SAP .NET Connector\Samples\IdocReceiverService\bin\Debug).
Run the command Installutil IdocReceiverService.exe. This should
install the Windows Service. You can verify this by looking at the Services manager in
the Administrative Tools. The Service name is .Net connector Idoc Service.
You set the SAP connection string in this services Start parametersproperty. For
example if your TCP/IP destination used the program ID of myProgIDand your SAP
system ran on your local machine, then the start parameters would be:
-amyProgID glocalhost xSAPGW00.
Messages are logged to the Windows Application Event Viewer. When received, SAP
IDOCs are appended to the following file: C:\temp\idoc.txt.
To enable your system to send IDOCS you must have a TCP/IP destination (type
registration), a configured partner profile (WE20) and a configured TRFC Port (WE21).
The Mini SAP Web Application Server 6.20 supports the IDOC type
EXCHANGE_RATE01. For convenience, you can find a sample IDOC file in the IDOC
submitter samples SampleIdoc folder. If you have no IDOCs on your system you can
submit this IDOC using the IdocSubmit sample application. Then use the IDOC test
utility (WE19), change the IDOC header and submit it as an outbound IDOC to the TRFC
Port representing this IdocReceiver sample.
Working with a stream reader to open IDOC file and display on Windows form.
Before running this application you have to share the folder DNCWebServiceSample.
This sample illustrates a simple web service wrapper for RFC_CUSTOMER_GET.
Note that you must run this sample in HTTPS to get the X.509 certificate from IIS.