Sei sulla pagina 1di 43

SAPx

Getting Started guide


SAPx

Contents
1 About this document....................................................................................................................................................3
2 About SAPx ......................................................................................................................................................................4
3 Architectural overview.................................................................................................................................................5
3.1 RFC function architecture....................................................................................................................................... 6
3.1.1 Data representation........................................................................................................................................... 6
3.1.2 Data mapping.................................................................................................................................................... 7
3.1.3 Early and late function binding......................................................................................................................... 8
3.2 Client applications.................................................................................................................................................... 9
3.2.1 Using connection aliases ...............................................................................................................................10
3.2.2 Features of transactional calls .......................................................................................................................10
3.3 Server applications ................................................................................................................................................10
3.3.1 Using command line.......................................................................................................................................11
4 Installation.......................................................................................................................................................................12
4.1 System requirements ............................................................................................................................................12
4.2 Additional requirements ........................................................................................................................................12
4.3 Building SAPx binaries ..........................................................................................................................................13
4.4 Installing components ...........................................................................................................................................13
5 HowTo call ABAP function with SAPx ...............................................................................................................15
6 HowTo work with SAPx components................................................................................................................17
7 HowTo write a Server function with SAPx.......................................................................................................20
8 HowTo write a Server function with SAPx as NT service..........................................................................21
Appendix A – Data type and mapping............................................................................................................................23
Appendix B – Early and late function binding.............................................................................................................25
Appendix C – Defining server parameters....................................................................................................................26
Appendix D – Transaction management in SAPx server application..............................................................27
Appendix E – SAPx component list.................................................................................................................................30
Appendix F – Listing of SAPx client application........................................................................................................32
Appendix G – Listing of SAPx server as console application .............................................................................34
Appendix H – Listing of SAPx server as NT service ................................................................................................40

Getting Started guide - Page 2 of 43 © 2002-2003 gs -soft AG, Switzerland


SAPx

1 About this document

This document might be very useful for Borland Delphi developers in:

• Building applications that are SAP system clients

• Extending functionality of a SAP application server by creating external non-SAP server programs.

In this guide you will find a general overview of the software SAPx and its possible applications. This
document helps to understand the main architectural concepts of SAPx work: information on RFC
function architecture, different types of data mapping and function binding. You will also learn general
concepts of creating client and server applications based on SAPx. This guide provides the developer
necessary installation ins tructions and gives a brief overview of components installed.

Here are some practical suggestions “How to …”. They give process overviews of creating simple both
client and server applications and contains some recommendations how to use SAPx components
during design time as well as at run time.

If you need to get any additional information not mentioned in this guide do not hesitate to contact us:

gs-soft.public.support.sapx Developers conference

http://www.gs-soft.com/sapx Product web page

info@gs-soft.com Email address

Getting Started guide - Page 3 of 43 © 2002-2003 gs -soft AG, Switzerland


SAPx

2 About SAPx

SAPx is an object-oriented software library. It has been specially designed for access to SAP application
servers using Borland® Delphi™ and for building partner server programs run in non-SAP systems.
SAPx is a flexible and versatile tool for:

• Integration of existing Delphi™ applications with SAP systems. This feature allows corporations to
use their own information systems and create superstructures offering new opportunities;

• Development of new systems and applications that have access to SAP application server as
clients;

• Extension of SAP system functionality through SAPx by building external non-SAP servers. This
feature gives the de veloper an opportunity to avoid costs connected with ABAP training as all
functionality extensions are implemented in Delphi™ programs.

SAPx encapsulates Remote Function Call (RFC) interface and offers high -level software components
and classes.

RFC API is a set of C-language routines that perform certain end user’s communication tasks and allow
execution of remote calls between two SAP Systems or between a SAP System and a non-SAP system.

RFC API supports a number of external systems, such as OS/2, Windows, WindowsNT and
Windows95, as well as all of R/3-based UNIX platforms. This feature makes it possible to use RFC
functionality for interaction of a SAP System with a C-program based on the platforms mentioned above
(there exists a RFC SDK that includes RFC library specific for each platform supported).

Getting Started guide - Page 4 of 43 © 2002-2003 gs -soft AG, Switzerland


SAPx

3 Architectural overview

On Figure 1 you can see the way Delphi applications can interact with SAP system through SAPx. SAPx
can be used both in client and server applications.

In the first case, when the developer wants to call an ABAP function he has to use SAPx object methods
and properties. SAPx packs all the necessary data and transfers the call to the RFC library. In such a
way the client request is sent to the SAP system. On receiving the request the SAP application server
processes it and returns the result. SAPx gets resulting data from the RFC library and the developer can
have access to it.

Application server

ABAP RFC Delphi application


functions
SAPx

Call an ABAP RFC function


RFC library

Client
SAP gateway

Call an external function


RFC library

SAPx
Delphi application

SAP R/3 system Server


Figure 1 : Interaction of a SAP system with Delphi application based on SAPx
In the second case SAPx server application is constantly waiting for SAP system client request. When
the request occurs SAPx receives and processes it. SAPx also undertakes to send the result to the SAP
system in correct format.

Getting Started guide - Page 5 of 43 © 2002-2003 gs -soft AG, Switzerland


SAPx

3.1 RFC function architecture

If you want to understand the way RFC function can be called and how to work with function parameters
it is necessary to examine RFC function architecture.

Delphi data types

SAPx

RFC data types

RFC function

Export Import
Tables
parameters parameters

Output data .
Input data

Figure 2 : RFC function architecture


As it is shown on Figure 2 RFC function receives data from Export parameters; Import parameters
contain resulting data; whereas Tables can contain both input and output data. All data imported from
and exported to RFC function has its own format and internal order. These data formats, RFC data
types, differ from Delphi ones. That is why one of SAPx most important tasks is to map RFC data types
to Delphi ones and backwards.

3.1.1 Data representation

SAP R/3 servers are able to run on different types of computers. And they may have different than on
WinTel representations of integer and float data. So, data representation should be changed, when data
are received from / transmitted to SAP R/3 server and data representations of server and client are
different. SAPx performs that for you. How SAPx will do that is controlled by alias parameters

Getting Started guide - Page 6 of 43 © 2002-2003 gs -soft AG, Switzerland


SAPx

TSAPxRFCAliasGS.DataFormat.IntType and TSAPxRFCAliasGS.DataFormat.FloatType. By default


they have values itAutoDetect and ftAutoDetect. So, SAPx will automatically detect server side data
representation. In some special cases, you can decide to force SAPx to expect some specified data
representation. It is not recommended, although.

3.1.2 Data mapping

RFC data types can be divided into three groups with different mapping methods: simple data type,
structured data type and tables.

3.1.2.1 Simple data types

Figure 3 shows concepts of simple RFC data type mapping (you can find more details on data mapping
procedure in Appendix A). If a data type has ambiguous mapping, the developer can definitely indicate
the target Delphi data type. Otherwise, SAPx maps this data type to the most appropriate Delphi data
type.

dtCharGS String

dtNumGS Int64

. .
. .
. .

dtTimeGS TDateTime

dtDateGS

Simple Delphi
RFC data types data types

Figure 3: Simple RFC data type mapping

3.1.2.2 Structured data types

Unlike simple data types structured one, i.e. dtStructureGS, does not have Delphi analogues. Figure 4
illustrates how SAPx to wrap dtStructureGS type by means of TSAPxRFCParameterGS class that
contains field list of TSAPxRFCFieldsListGS class. So the structure corresponds to the field list and
individual field of TSAPxRFCFieldGS describes each structure item. SAPx does not support nested

Getting Started guide - Page 7 of 43 © 2002-2003 gs -soft AG, Switzerland


SAPx

structured data types. It means that each structure item should be of simple data type (you can find
more details on data mapping procedure in Appendix A).

Item 1 Field 1

Item 2 Field 2

. .
. .
. .

Item N Field N

Field list

Structured
RFC data type Parameter

Figure 4 : Wrapping structured RFC data type by SAPx

3.1.2.3 RFC table parameters

We should also pay more attention to the way SAPx works with function tables featuring their own
format. SAPx includes TSAPxRFCvTableGS component derived from TDataSet that, on the one hand,
offers clear and easy interface for Delphi developers and, on the other hand, works with RFC library
using RFC data types and formats.

3.1.3 Early and late function binding

There are two types of binding ABAP RFC functions with SAPx function objects in SAPx, early and late
binding.

Early binding means that an ABAP function name has been known at design time already. So SAPx
function object is statically defined. It is recommended to get a wrapping code for the ABAP functions
with SAPx Explorer tool (see SAPx Explorer User Guide). It will save you a lot of time and will help you
to avoid lots of mistakes.

On the contrary, late binding allows the developer to call an ABAP function at run time dynamically. In
this case SAPx aut omatically gets the necessary metadata.

If we compare early and late binding:

Getting Started guide - Page 8 of 43 © 2002-2003 gs -soft AG, Switzerland


SAPx

• Early binding has a higher productivity as it excludes application roundtrip to the SAP system for
metadata retrieval;

• Early binding allows to find some mistakes during compile process;

• Late binding has smaller performance but wider flexibility

The developer can choose one binding mode or another depending on the specific task (you can find
more details on quantitative indicators for early and late binding in Appendix B).

3.2 Client applications

Figure 5 illustrates interaction of SAPx components with standard Delphi ones.

RFC
1

n
TSAPxRFCvClientConnectionGS
1 1

n n
TSAPxRFCvFunctionGS TSAPxRFCvServerTableGS
1 1
Delphi application
n n
TSAPxRFCvParamsGS TSAPxRFCvTableGS SAPx

TDataSource TDataSource TDataSource

Delphi client application

Figure 5 : Interaction of SAPx client components in an application.


The main SAPx client component is TSAPxRFCvClientConnectionGS. Such components as
TSAPxRFCvFunctionGS and TSAPxRFCvServerTableGS use TSAPxRFCvClientConnectionGS object

Getting Started guide - Page 9 of 43 © 2002-2003 gs -soft AG, Switzerland


SAPx

to communicate with RFC library. The developer can use TSAPxRFCvParamsGS and
TSAPxRFCvTableGS components to operate TSAPxRFCvFunctionGS function parameters and tables.
The components TSAPxRFCvParamsGS, TSAPxRFCvTableGS, and TSAPxRFCvServerTableGS
inherited from TDataSet can be linked with any data aware controls.

To build a client application you can use components as well as objects encapsulated into these
components.

3.2.1 Using connection aliases

A client application establishes communication with SAP system through RFC library. A connection has
its own set of parameters that are to be specified before connecting. For convenience developers may
apply SAPx aliases to describe connection parameters. The developer can maintained SAPx alias by
SAPx Explorer (see SAPx Explorer User Guide) and then use it in client application.

3.2.2 Features of transactional calls

SAPx supports transactional functions. Transactional function should be called only between starting
and ending points of a transaction. These are distinctive features of transactional calls:

• CallType property of TSAPxRFCvFunctionGS should be set to ftTransactionalGS

• TSAPxRFCvFunctionGS should have no import parameters

• Only one function can be called within a singular transaction

3.3 Server applications

There are two SAPx server components: TSAPxRFCvS erverConnectionGS and


TSAPxRFCvServerFunctionGS. The main and most important is TSAPxRFCvServerConnectionGS
(Figure 6). It provides a non-SAP server with registration on gateway and supports communication of
TSAPxRFCvServerFunctionGS components with SAP system through the RFC library.

SAPx supports transactional server functions (you can find detailed information on transactional
management in )

Getting Started guide - Page 10 of 43 © 2002-2003 gs -soft AG, Switzerland


SAPx

RFC library
1

n
TSAPxRFCvServerConnectionGS
1

n
TSAPxRFCvServerFunctionGS

SAPx

Delphi server application

Figure 6: Interaction of SAPx server visual components in an application.


The developer can use a TSAPxRFCvServerFunctionGS component to implement server functions.
Server applications as well as client ones can be built on both SAPx components and SAPx objects
encapsulated into these components.

3.3.1 Using command line

Server connection parameters can be specified in the command line when the server application is
starting. In this case command line parameters are automatically assigned to CommandLine property of
TSAPxRFCvServerConnectionGS component. Appendix C shows command line switches and their
meaning. When server starts it becomes possible to specify either PROGRAM_ID, GWHOST,
GWSERV and RFC_TRACE parameters or just a DESTINATION parameter solely.

In the second case you have to define entry named DESTINATION in the saprfc.ini file specifying all
connection parameters (see example in Appendix C). This way to specify server connection parameters
is much more flexible than the first one.

While using command line it is very important to remember that you cannot specify more than one set of
server connection parameters. So, for server applications with multiple connections the developer
should definitely and explicitly specify Com mandLine property of TSAPxRFCvServerConnectionGS
component.

Getting Started guide - Page 11 of 43 © 2002-2003 gs -soft AG, Switzerland


SAPx

4 Installation

4.1 System requirements

Before installing SAPx ensure that:

• SAP RFC library version at least 4.6 is installed on your PC. RFC library is specific for different
operational systems. For example, librfc32.dll is used in Windows 95/NT/2000. SAP RFC library
may be installed as part of SAPgui installation.
Notice. SAP RFC library from SAP GUI v 6.x has a bug – each unload of librfc32.dll will result
memory loss around 6 Mb.

• SAP R/3 system you want to work with is at least Release 2.1

• Borland Delphi 5 / 6 / 7 or Borland C++ Builder 5 / 6 is installed on your PC.

4.2 Additional requirements

SAP user account used by SAPx client application should have all required privileges to execute
following RFC function modules:

Table 1: SAP R/3 function modules, used by SAPx software


Function module Used for Used by
RFC_GET_FUNCTION_INTERFACE To dynamically obtain function TSAPxRFCFunctionGS,
module interface. TSAPxRFCvFunctionGS

RFC_GET_STRUCTURE_DEFINITION To dynamically obtain record data TSAPxRFCFunctionGS,


type layout. TSAPxRFCvFunctionGS

RFC_SYSTEM_INFO To get server representation of TSAPxRFCClientConnectionGS,


integer and float data types. TSAPxRFCvClientConnectionGS

RFC_READ_TABLE To read SAP server tables data. TSAPxRFCEasyDataMoveGS,


TSAPxRFCvServerTableGS

RFC_FUNCTION_SEARCH To show list of accessible RFC SAPx RFC Explorer


function modules

RFC_GROUP_SEARCH To show list of accessible RFC SAPx RFC Explorer


function groups.

Getting Started guide - Page 12 of 43 © 2002-2003 gs -soft AG, Switzerland


SAPx

4.3 Building SAPx binaries

SAPx software includes a set of BAT command files. They may be used to build SAPx binary files don’t
running IDE, but from command line:

Table 2: SAPx command files


File name Tool
compileD5.bat Delphi 5

compileD6.bat Delphi 6

compileD7.bat Delphi 7

compileBCB5.bat C++ Builder 5

compileBCB6.bat C++ Builder 6

All BAT files will automatically detect is the tool installed or not and where it is installed. And if the tool is
not installed you will get an error message about that. The command files has optional parameters:

Table 3: SAPx command files


Parameter Meaning
tolib If specified then produced binary files will be in <SAPx>\Lib\Full\<Tool>
directory. If not specified – in <SAPx>\ directory.

fullbin Used together with “tolib”. If specified, then set of binary files will include
additional file, required to build package / applications. It is DFM, RES,
DCR, etc files. If not specified, these files will stay in <SAPx>\ directory.

4.4 Installing components

Installation of new components has become very easy due to the Delphi package system. To install
SAPx:

1. Run Delphi IDE.

2. Choose File -> Open. Set Files of type to Delphi package (*.dpk) and open appropriate Package
Project file in the SAPx installation directory:

Table 4: SAPx package files


Package name Tool
gsSAPxRFCD5.dpk Delphi 5

gsSAPxRFCD6.dpk Delphi 6

gsSAPxRFCD7.dpk Delphi 7

Getting Started guide - Page 13 of 43 © 2002-2003 gs -soft AG, Switzerland


SAPx

gsSAPxRFCbcb5.bpk C++ Builder 5

gsSAPxRFCbcb6.bpk C++ Builder 6

3. Click on Com pile button in Package window and then press Install button.

The new components should appear in the Delphi Component Palette (Figure 7).

Figure 7 : Delphi component palette after successful installation of SAPx.

You can find list of all SAPx components in Appendix E.

Getting Started guide - Page 14 of 43 © 2002-2003 gs -soft AG, Switzerland


SAPx

5 HowTo call ABAP function with SAPx

In order to examine how to call an ABAP function developer can create a simple application that calls
ABAP function RFC_GET_NAMETAB. This function returns as result time stamp of table creation
(CRSTAMP). Input parameter TABNAME specifies the table name.

The developer has to take the following steps:

1. To create a new application form with a set of standard components on it (see Figure 8).

2. To locate on the form such SAPx components as TSAPxRFCvClientConnectionGS and


TSAPxRFCvFunctionGS.

Figure 8 : The main form of the application calling ABAP function module RFC_GET_NAMETAB

3. To set the key components properties according to Table 5.

Table 5: Key components properties and their values


Component name Class name Property
ClientConnection TSAPxRFCvClientConnectionGS AliasFileName = <Full name of alias file>
AliasName = <Any valid alias>
GetNameTab TSAPxRFCvFunctionGS Connection = ClientConnection
ObjName = ‘RFC_GET_NAMETAB’
btnConnect TButton OnClick = btnConnectClick
btnDisconnect TButton OnClick = btnDisconnectClick
btnExecute TButton OnClick = btnExecuteClick

4. To implement the event handlers: btnConnectClick, btnDisconnectClick and btnExecuteClick as it is


shown on Listing 1.

Listing 1: Implementation of event handlers

procedure TfrmMain.btnExecuteClick(Sender: TObject);


begin
with GetNameTab do begin

Getting Started guide - Page 15 of 43 © 2002-2003 gs -soft AG, Switzerland


SAPx

Prepared := True;
InParams.ParameterByName('TABNAME').AsString := edtTableName.Text;
ExecFunction;
edtStamp.Text :=
OutParams.ParameterByName('HEADER').SubFields.FieldByName('CRSTAMP').AsString;
end;
end;

{ --------------------------------------------------------------------------- }
procedure TfrmMain.btnConnectClick(Sender: TObject);
begin
ClientConnection.Connected := True;
end;

{ --------------------------------------------------------------------------- }
procedure TfrmMain.btnDisconnectClick(Sender: TObject);
begin
ClientConnection.Connected := False;
end;
5. To run the application.

6. To press Connect button and log in the SAP system.

7. To specify the target table name and press Execute button. The final result is shown on Figure 9

Figure 9 : The result of RFC_GET_NAMETAB function call

Getting Started guide - Page 16 of 43 © 2002-2003 gs -soft AG, Switzerland


SAPx

6 HowTo work with SAPx components

Let us take as an example a simple application that calls ABAP function RFC_GET_FUNC_LOC_DATA.
This function returns information on locked SAP DB table by its name (you can find complete listing of
this application in Appendix F).

To build it using SAPx components the developer has to take the following steps:

1. To create a new application form with a set of standard components on it.

2. To locate on the created form the following SAPx components: TSAPxRFCvClientConnectionGS,


TSAPxRFCvFunctionGS, TSAPxRFCvTableGS and TSAPxRFCvParamsGS (see Figure 10).

Figure 10: The main application form with SAPx client components located on it.
3. Now you have access to function parameters and tables using data aware controls such as
TDBGrid, TDBEdit, TDBLable and others. To make it possible key components properties should be
maintained in accordance with Table 6.

Table 6: Maintaining key SAPx components properties for work using data aware controls.
Component name Class name Property
ClientConnection TSAPxRFCvClientConnectionGS AliasFileName = <Full name of alias file>
AliasName = <Any valid alias>
GetFuncData TSAPxRFCvFunctionGS Connection = ClientConnection
ObjName = ‘RFC_GET_FUNC_LOC_DATA’
PInput TSAPxRFCvParamsGS Func = ‘GetFuncData’
ParamKinds = [ipIn]
POutput TSAPxRFCvParamsGS Func = ‘GetFuncData’

Getting Started guide - Page 17 of 43 © 2002-2003 gs -soft AG, Switzerland


SAPx

ParamKinds = [ipOut]
Table TSAPxRFCvTableGS Func = ‘GetFuncData’
TableName = ‘SAP_FIELD_DATA’
dsrInput TDataSource DataSet = PInput
dsrOutput TDataSource DataSet = Poutput
dsrTable TDataSource DataSet = Table
edtFuncLoc TDBEdit DataSource = dsrInput
DataField = ‘I_FUNC_LOC’
grdOutput TDBGrid DataSource = dsrOutput
grdTable TDBGrid DataSource = dsrTables
btnConnect TButton OnClick = btnConnectClick
btnDisconnect TButton OnClick = btnDisconnectClick
btnPrepare TButton OnClick = btnPrepareClick
btnExecute TButton OnClick = btnExecuteClick

4. To run the application and connect to the SAP system by clicking on Connect button. When clicking
on Prepare button you prepare the GetFuncData function to access to its parameter list and tables
(Listing 2 shows implementation of btnConnectClick and btnPrepareClick event handlers). When the
function is prepared, its parameters and tables will be displayed in DB grids.

Listing 2: Implementation of btnConnectClick and btnPrepareClick event handlers

procedure TfrmMain.btnConnectClick(Sender: TObject);


begin
ClientConnection.Connected := True;
end;

procedure TfrmMain.btnPrepareClick(Sender: TObject);


begin
GetFuncData.Prepare;
PInput.Active := True;
POutput.Active := True;
Table.Active := True;
end;
5. To enter I_FUNC_LOC input function parameter value use edtFuncLoc control. Then press the
Execute button. Figure 11 shows the results of executing RFC_GET_FUNC_LOC_DATA ABAP
function module.

Getting Started guide - Page 18 of 43 © 2002-2003 gs -soft AG, Switzerland


SAPx

Figure 11: Function results received with data aware controls.

Getting Started guide - Page 19 of 43 © 2002-2003 gs -soft AG, Switzerland


SAPx

7 HowTo write a Server function with SAPx

To enhance SAP system functionality by implementing a non-SAP server we are going to build, as an
example, a server console application that supports transactional calls. The application has a single
server function that is very simple as it can only write its input parameters to its table.

To build such server application the developer should take the following steps (you can find complete
listing of this application in Appendix G):

1. To create a new console application TransServer and its main class TxServer

2. To add the following main SAPx server objects to TxServer as class members:

• FSConnection1 of TSAPxRFCServerConnectionGS type

• FSFunction1 of TSAPxRFCServerFunctionGS type

3. To implement InitConnection and InitFunction procedures to initialize server connection


(FSConnection1 ) and server function (FSFunction1). The developer can specify server connection
parameters either in program code, for example in InitConnection procedure, or use capability of
SAPx to take these parameters out of command line. In our example we are going to use the second
way, therefore the server program should be launched with the following command line:

TransServer.exe –aMY_SERVER_ID –gmyserver.mydomain.com –xsapgw00


Before running SAPx server you have to create the SAP destination that is used in ABAP program to
call SAPx server function (SM59 transaction).

4. To implement server function actions into HandleExecute event handler. HandleError event handler
contains actions that have to be performed when an error occurs. If the server has to support
transactions, then it is necessary to implement transaction events handlers such as
HandleCheckTID, HandleCommit, HandleRollback and HandleConfirm .

Transactional functions cannot have output parameters.

5. To write code that will launch and terminate the application server using Start and Shutdown
methods of TSAPxRFCServerApplicationGS object. Use SAPxRFCServerApplication function to
access to TSAPxRFCServerApplicationGS global object.

Getting Started guide - Page 20 of 43 © 2002-2003 gs -soft AG, Switzerland


SAPx

8 HowTo write a Server function with SAPx as NT service

The majority of server programs in Windows NT are implemented as services. SAPx server can be
implemented as NT service as well. Server of this kind is built on TService standard Borland Delphi
class and uses TService events to control SAPx application server. To design such SAPx server the
developer should take the following steps (you can find complete listing of this application in Appendix
H):

1. To create a new Service Application.

2. To add one or more TSAPxRFCvServerConnectionGS and TSAPxRFCvServerFunctionGS


components.

3. To maintain the main components properties as it is shown in Table 7.

Table 7: Maintaining of key SAPx components work properties using data aware controls.
Component (object) name Class name Property
FSConnection1 TSAPxRFCvServerConnectionGS CommandLine.IniDest = ‘DEST1’
OnCheckTID = ‘HandleCheckTID’
OnCommit = HandleCommit
OnConfirm = HandleConfirm
OnRollback = HandleRollback
FSConnection2 TSAPxRFCvServerCo nnectionGS CommandLine.IniDest = ‘DEST2’
OnCheckTID = ‘HandleCheckTID’
OnCommit = HandleCommit
OnConfirm = HandleConfirm
OnRollback = HandleRollback
FSFunction11 TSAPxRFCvServerFunctionGS Connection = FSConnection1
ObjName = ‘SAPXRFCF11’
OnExecute = FSTxFunctionExecute
FSFunction12 TSAPxRFCvServerFunctionGS Connection = FSConnection1
ObjName = ‘SAPXRFCF12’
OnExecute = FSFunctionExecute
FSFunction21 TSAPxRFCvServerFunctionGS Connection = FSConnection2
ObjName = ‘SAPXRFCF21’
OnExecute = FSTxFunctionExecute
FSFunction22 TSAPxRFCvServerFunctionGS Connection = FSConnection2
ObjName = ‘SAPXRFCF22’
OnExecute = FSFunctionExecute

4. To define destinations ‘DEST1’ and ‘DEST2’ in saprfc.ini file.

Getting Started guide - Page 21 of 43 © 2002-2003 gs -soft AG, Switzerland


SAPx

5. To implement handlers for the following TService’s events: OnStart, OnStop, OnPause and
OnContinue. These handlers are quite simple (see Listing 3).

Listing 3: Implementation of event handlers controlling SAPx application server.

procedure TSAPxRFCServer.ServiceStart(Sender: TService; var Started: Boolean);


begin
SAPxRFCServerApplication.Start;
Started := not SAPxRFCServerApplication.Terminated;
end;

{-----------------------------------------------------------------------------}
procedure TSAPxRFCServer.ServiceStop(Sender: TService; var Stopped: Boolean);
begin
SAPxRFCServerApplication.Shutdown;
end;

{-----------------------------------------------------------------------------}
procedure TSAPxRFCServer.ServicePause(Sender: TService; var Paused: Boolean);
begin
SAPxRFCServerApplication.Pause;
end;

{-----------------------------------------------------------------------------}
procedure TSAPxRFCServer.ServiceContinue(Sender: TService; var Continued: Boolean);
begin
SAPxRFCServerApplication.Resume;
end;
6. To include all server function actions into HandleExecute event handler.

7. If the server has to support transactions, it is necessary to implement event handlers such as
HandleCheckTID, HandleCommit, HandleRollback and HandleConfirm .

Getting Started guide - Page 22 of 43 © 2002-2003 gs -soft AG, Switzerland


SAPx

Appendix A – Data type and mapping

Mapping of simple RFC data type to Delphi data and field types
RFC data type Delphi data type Delphi field type
(see gsSAPxRFCStdObj) (see gsSAPxRFCvClient)
dtCharGS String • ftString (size <= 8192)
• ftMemo (size > 8192)

dtNumGS Int64 • ftSmallInt (size <= 4)


• ftInteger (size <= 9)
• ftLargeInt (size > 9)

dtByteGS String • ftVarBytes (size <= 8192)


• ftBlob (size > 8192)
dtBCDGS • Integer ftFloat
• Int64
• Currency
• Double
• String

dtIntGS Integer ftInteger


dtInt1GS Byte ftSmallInt

dtInt2GS SmallInt ftSmallInt


dtFloatGS Double ftFloat
dtDateGS TDateTime ftDate

dtTimeGS TDateTime ftTime

Conversion of dtStructureGS data type to Delphi field type


RFC data type Delphi data type Delphi field type
(see gsSAPxRFCStdObj) (see gsSAPxRFCvClient)
dtStructureGS ftADT
TSAPxRFCParameterGS
1…1
TSAPxRFCFieldsListGS
1…N
TSAPxRFCFieldGS

Getting Started guide - Page 23 of 43 © 2002-2003 gs -soft AG, Switzerland


SAPx

Converting RFC table parameters to Delphi data type


RFC data type Delphi data type Delphi field type
(see gsSAPxRFCStdObj) (see gsSAPxRFCvClient)
RFC table parameter TSAPxRFCTableGS TSAPxRFCvTableGS

Getting Started guide - Page 24 of 43 © 2002-2003 gs -soft AG, Switzerland


SAPx

Appendix B – Early and late function binding

Listing 4: Early binding. Wrapping code generated for RFC_READ_TABLE ABAP function by SAPxExplorer.

TSAPxRFCRFC_READ_TABLEFuncGS = class(TSAPxRFCFunctionGS)
private
proc edure SetDELIMITER(const AValue: String);
function GetDELIMITER: String;
function GetDATA: TSAPxRFCTAB512TableGS;
public
constructor Create; override;
property DELIMITER: String read GetDELIMITER write SetDELIMITER;
property DATA: TSAPxRFCTAB512TableGS read GetDATA;
end;

implementation

procedure Execute;
begin
// working with TSAPxRFCRFC_READ_TABLEFuncGS object interface
with FCFunction as TSAPxRFCRFC_READ_TABLEFuncGS do begin
DELIMITER := ‘%’;
ExecFunction;
with DATA do begin
{ do something with table ‘DATA’ }
end;
end;
end;

Listing 5: Late binding. Using a dynamically prepared function.

procedure Execute;
begin
// working with TSAPxRFCFunctionGS object interface
with FCFunction do begin
ObjName := ‘RFC_READ_TABLE’;
Prepared := True;
InParams.ParameterByName('DELIMITER').AsString := ‘%’;
ExecFunction;
with Tables.TableByName('DATA') do begin
{ do something with table ‘DATA’ }
end;
end;
end;

Statistics of function execution for different binding modes


Binding mode Early binding Late binding
Single function call ~ 0.161 sec ~ 0.46 sec
Sequential function calls (100 times) ~14.191 sec ~14.882 sec

Getting Started guide - Page 25 of 43 © 2002-2003 gs -soft AG, Switzerland


SAPx

Appendix C – Defining server parameters

Command line switches and their meanings


Command line switch Meaning
-a<PROGRAM_ID> Identifier of server connection registered on SAP gateway
-g<GWHOST > Host name of SAP gateway
-x<GWSERV> Service name on SAP gateway
-t<RFC_TRACE> Indicator of tracing
-D<DESTINATION> Destination name in saprfc.ini file

Listing 6: Example of destination list in saprfc.ini file

// -----------------------------------------------------------------------
// SAPx server destinations
// ---------- -------------------------------------------------------------
DEST=S1
TYPE=R
PROGID=SAPXRFCTEST_PROGID1
GWHOST=myserver.mydomain.com
GWSERV=sapgw00

Getting Started guide - Page 26 of 43 © 2002-2003 gs -soft AG, Switzerland


SAPx

Appendix D – Transaction management in SAPx server application

SAPx support s transactional server functions. SAP R/3, the RFC library and SAPx server connection
communicate in two phases (see Figure 12: Scheme of calling a transactional function):

• The first phase (F1) – Function transfer

• The second phase (F2) – Confirmation

Function transfer phase is initiated in ABAP program and is divided into three parts:

• T1 – OnCheckTID event handler has to check TID status, update it and return corresponding
check result

• T2 – OnExecute event handler should contain the required RFC server function implementation

• T3 (T3’) – OnCommit (OnRollback) event handler updates TID status and commits (rolls back)
database (non -SAP database) transaction(s)

Confirmation phase starts as soon as RFC library informs SAP system about successful T3 (not T3’ ).
TSAPxRFCvServerConnectionGS component receives confirmation of the current transaction
immediately. In OnConfirm event handler the developer should update TID status (delete). After this
phase is over current transaction is successfully completed on both sides.

A simple example of transaction management is shown in Listing 7: Transactional management.

Getting Started guide - Page 27 of 43 © 2002-2003 gs -soft AG, Switzerland


SAPx

TSAPxRFCvServerConnectionGS

F1 T1
OnCheckTID
// Check and update TID

T2
OnExecute
// Execute some actions

SAP tRFC T3
RFC library OnCommit
component // Update TID and commit DB
if necessary
T3'
OnRollback
// Update TID and rollback DB
if necessary

F2 T4
OnConfirm
// Update (delete) TID
SAPx

SAP R/3 system Delphi server application

Figure 12: Scheme of calling a transactional function

Listing 7: Transactional management

procedure TxServer.HandleCheckTID(Sender: TObject; const ATID: String;


var AResult: TSAPxRFCCheckTIDResultGS);
begin
if CheckStatus(ATID) then // whether the transaction has not started
UpdateStatus(ATID, tsCreated) // updating the transaction’s status
else
AResult := crCancelGS; // rejecting the transaction
end;

{-----------------------------------------------------------------------------}
procedure TxServer.HandleCommit(Sender: TObject; const ATID: String);
begin
UpdateStatus(ATID, tsExecuted);
CommitDB(ATID); // committing non-SAP database transaction
end;

{-----------------------------------------------------------------------------}
procedure TxServer.HandleConfirm(Sender: TObject; const ATID: String);
begin

Getting Started guide - Page 28 of 43 © 2002-2003 gs -soft AG, Switzerland


SAPx

UpdateStatus(ATID, tsDeleted);
end;

{-----------------------------------------------------------------------------}
procedure TxServer.HandleRollback(Sender: TObject; const ATID: String);
begin
RollbackDB(ATID); // rolling non-SAP database transaction back
end;

Getting Started guide - Page 29 of 43 © 2002-2003 gs -soft AG, Switzerland


SAPx

Appendix E – SAPx component list

SAPx building components are divided into two groups: components for client programs and for non-
SAP server programs. In the following sections you can find description of each of these groups.

Client components

SAPx components used in client programs with access to SAP application server RFC functions are
called client components.

Using SAPx Explorer

SAPx Explorer is a specially designed tool that offers the developer SAP system dictionary information
on RFC objects. For more detailed information about this tool, please, refer to SAPx Explorer User
Guide.

TSAPxRFCvClientConnectionGS

The TSAPxRFCvClientConnectionGS is the main client component. It connects to the specified


SAP system and supports data exchange between a client program and the SAP system.

TSAPxRFCvFunctionGS

The TSAPxRFCvFunctionGS component allows execution of an ABAP RFC function module. It


contains sets of input and output parameters and table lists that are used for access to the function
module data.

TSAPxRFCvTableGS

The TSAPxRFCvTableGS is a TDataSet component descendant; that is why it can be used by


data aware controls. It allows access to the specified table from the TSAPxRFCvFunctionGS table list.

TSAPxRFCvServerTableGS

The TSAPxRFCvServerTableGS is also a TDataSet component descendant; that is why it can be


used by data aware controls as well. It allows to get dictionary information on specified SAP DB table
(fields description) and data stored within this table.

Getting Started guide - Page 30 of 43 © 2002-2003 gs -soft AG, Switzerland


SAPx

TSAPxRFCvParamsGS

The TSAPxRFCvParamsGS corresponds to a set of function parameters. It allows to edit and


display a set of parameters using data aware controls.

Server components

The set of SAPx server components allows implementation of non-SAP server programs that enhance
SAP system functionality.

TSAPxRFCvServerConnectionGS

The TSAPxRFCvServerConnectionGS is the main component for non-SAP server programs. It


registers all supported server functions on SAP gateway; processes client requests and dispatches
them.

TSAPxRFCvServerFunctionGS

The TSAPxRFCvServerFunctionGS component allows implementation of a certain part of server


functionality. Every TSAPxRFCvServerFunctionGS component belongs to the specified server
connection and can receive client requests only from it.

Getting Started guide - Page 31 of 43 © 2002-2003 gs -soft AG, Switzerland


SAPx

Appendix F – Listing of SAPx client application

Listing 8: SAPx client application

unit ClientApp;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, gsSAPxRFCvClient, DB, StdCtrls, Grids, DBGrids, Mask, DBCtrls;

type
{ --------------------------------------------------------------------------- }
TfrmMain = class(TForm)
ClientConnection: TSAPxRFCvClientConnectionGS;
GetFuncData: TSAPxRFCvFunctionGS;
btnExecute: TButton;
btnConnect: TButton;
grpInput: TGroupBox;
grpOutput: TGroupBox;
grpTables: TGroupBox;
btnDisconnect: TButton;
Table: TSAPxRFCvTableGS;
dsrInput: TDataSource;
dsrOutput: TDataSource;
dsrTables: TDataSource;
POutput: TSAPxRFCvParamsGS;
edtFuncLoc: TDBEdit;
PInput: TSAPxRFCvParamsGS;
grdOutput: TDBGrid;
GrdTable: TDBGrid;
btnPrepare: TButton;
lblFieldName: TLabel;
procedure btnExecuteClick(Sender: TObject);
procedure btnConnectClick(Sender: TObject);
procedure btnDisconnectClick(Sender: TObject);
procedure btnPrepareClick(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
end;

var
frmMain: TfrmMain;

implementation
{$R *.dfm}

{ --------------------------------------------------------------------------- }
procedure TfrmMain.btnExecuteClick(Sender: TObject);
begin
GetFuncData.ExecFunction;
end;

{ --------------------------------------------------------------------------- }
procedure TfrmMain.btnConnectClick(Sender: TObject);
begin
ClientConnection.Connected := True;
end;

Getting Started guide - Page 32 of 43 © 2002-2003 gs -soft AG, Switzerland


SAPx

{ --------------------------------------------------------------------------- }
procedure TfrmMain.btnDisconnectClick(Sender: TObject);
begin
ClientConnection.Connected := False;
end;

{ --------------------------------------------------------------------------- }
pro cedure TfrmMain.btnPrepareClick(Sender: TObject);
begin
GetFuncData.Prepare;
PInput.Active := True;
POutput.Active := True;
Table.Active := True;
end;

{ --------------------------------------------------------------------------- }
procedure TfrmMain.FormClose(Sender: TObject; var Action: TCloseAction);
begin
ClientConnection.Connected := False;
end;

end.

Getting Started guide - Page 33 of 43 © 2002-2003 gs -soft AG, Switzerland


SAPx

Appendix G – Listing of SAPx server as console application

Listing 9: SAPx server as console application

program TransServer;
{$APPTYPE CONSOLE}

uses
Windows, SysUtils, gsSAPxRFCvServer, StdCtrls, gsSAPxRFCServer, gsSAPxRFCBase,
gsSAPxRFCvClient, gsSAPxRFCStdObj, Classes, dbtables, db;

type
TSAPxRFCABAPTEXTTableGS = class;
TSAPxRFCZMY_STRUCTUREStrGS = class;
TSAPxRFCZMY_SERVER_FUNCTIONFuncGS = class;

{-----------------------------------------------------------------------------}
{ TxServer }
{-----------------------------------------------------------------------------}
TxServer = class(TObject)
private
FSConnection1: TSAPxRFCServerConnectionGS;
FSFunction1: TSAPxRFCZMY_SERVER_FUNCTIONFuncGS;
procedure InitConnection;
procedure InitFunction;
procedure HandleExecute(AFunction: TSAPxRFCServerFunctionGS);
procedure HandleError(Sender: TObject; E: Exception;
var AErrAction: TSAPxRFCErrorActionGS);
procedure HandleCheckTID(Sender: TObject; const ATID: String;
var AResult: TSAPxRFCCheckTIDResultGS);
procedure HandleCommit(Sender: TObject; const ATID: String);
procedure HandleConfirm(Sender: TObject; const ATID: String);
procedure HandleRollback(Sender: TObject; const ATID: String);
public
constructor Create;
destructor Destroy; override;
procedure Start;
procedure Shutdown;
end;

{-----------------------------------------------------------------------------}
{ TSAPxRFCABAPTEXTTableGS }
{-----------------------------------------------------------------------------}
TSAPxRFCABAPTEXTTableGS = class(TSAPxRFCTableGS)
private
procedure SetLINE(const AValue: String);
function GetLINE: String;
public
constructor Create; override;
property LINE: String read GetLINE write SetLINE;
end;

{-----------------------------------------------------------------------------}
{ TSAPxRFCZMY_STRUCTUREStrGS }
{-----------------------------------------------------------------------------}
TSAPxRFCZMY_STRUCTUREStrGS = class(TSAPxRFCParameterGS)
private
procedure SetTABNAME(const AValue: String);

Getting Started guide - Page 34 of 43 © 2002-2003 gs -soft AG, Switzerland


SAPx

function GetTABNAME: String;


procedure SetFLAG(const AValue: String);
function GetFL AG: String;
procedure InstallStructure;
public
constructor Create; override;
property TABNAME: String read GetTABNAME write SetTABNAME;
property FLAG: String read GetFLAG write SetFLAG;
end;

{-----------------------------------------------------------------------------}
{ TSAPxRFCZMY_SERVER_FUNCTIONFuncGS }
{-----------------------------------------------------------------------------}
TSAPxRFCZMY_SERVER_FUNCTIONFuncGS = class(TSAPxRFCServerFunctionGS)
private
function GetASTAT: TSAPxRFCZMY_STRUCTUREStrGS;
function GetDATA: TSAPxRFCABAPTEXTTableGS;
function GetFTABNAME: string;
procedure SetFTABNAME(Value: string);
public
constructor Create; override;
property ASTAT: TSAPxRFCZMY_STRUCTUREStrGS read GetASTAT;
property FTABNAME: string read GetFTABNAME write SetFTABNAME;
property DATA: TSAPxRFCABAPTEXTTableGS read GetDATA;
end;

{-----------------------------------------------------------------------------}
{ TxServer }
{-----------------------------------------------------------------------------}
constructor TxServer.Create;
begin
FSConnection1 := TSAPxRFCServerConnectionGS.Create;
FSFunction1 := TSAPxRFCZMY_SERVER_FUNCTIONFuncGS.Create;
InitConnection;
InitFunction;
end;

{-----------------------------------------------------------------------------}
destructor TxServer.Destroy;
begin
FSConnection1.Free;
FSFunction1.Free;
inherited Destroy;
end;

{-----------------------------------------------------------------------------}
procedure TxServer.InitConnection;
begin
with FSConnection1 do begin
OnError := HandleError;
OnCheckTID := HandleCheckTID;
OnCommit := HandleC ommit;
OnConfirm := HandleConfirm;
OnRollback := HandleRollback;
end;
end;

{-----------------------------------------------------------------------------}
procedure TxServer.InitFunction;

Getting Started guide - Page 35 of 43 © 2002-2003 gs -soft AG, Switzerland


SAPx

begin
// the initialization of server function
with F SFunction1 do begin
Connection := FSConnection1;
OnExecute := HandleExecute;
end;
end;

{-----------------------------------------------------------------------------}
procedure TxServer.Start;
begin
SAPxRFCServerApplication.Start;
end;

{-----------------------------------------------------------------------------}
procedure TxServer.Shutdown;
begin
SAPxRFCServerApplication.Shutdown;
end;

{-----------------------------------------------------------------------------}
procedure TxServer.HandleExecute(AFunction: TSAPxRFCServerFunctionGS);
var
sStructDump, sTabName: String;
begin
if AFunction is TSAPxRFCZMY_SERVER_FUNCTIONFuncGS then
with AFunction as TSAPxRFCZMY_SERVER_FUNCTIONFuncGS do begin
sTabName := FTABNAME;
sStructDump := ASTAT.TABNAME + '; ' + ASTAT.FLAG;
DATA.Append;
DATA.LINE := sTabName + '; ' + sStructDump;
DATA.Post;
end;
end;

{-----------------------------------------------------------------------------}
procedure TxServer.HandleError(Sender: TObject; E: Exception;
var AErrAction: TSAPxRFCErrorActionGS);
begin
{ Error handling }
end;

{-----------------------------------------------------------------------------}
procedure TxServer.HandleCheckTID(Sender: TObject; const ATID: String;
var AResult: TSAPxRFCCheckTIDResultGS);
begin
{ Check status of transaction with ATID }
{ if the transaction has not been started, then }
{ AResult := crOkGS, else AResult := crCancelGS }
end;

{-----------------------------------------------------------------------------}
procedure TxServer.HandleCommit(Sender: TObject; const ATID: String);
begin
{ do DB Commit }
{ Update status of transaction with ATID }
end;

{-----------------------------------------------------------------------------}

Getting Started guide - Page 36 of 43 © 2002-2003 gs -soft AG, Switzerland


SAPx

procedure TxServer.HandleConfirm(Sender: TObject; const ATID: String);


begin
{ Update status of transaction with ATID }
end;

{-----------------------------------------------------------------------------}
procedure TxServer.HandleRollback(Sender: TObject; const ATID: String);
begin
{ do DB Rollback }
end;

{-----------------------------------------------------------------------------}
{ TSAPxRFCABAPTEXTTableGS }
{-----------------------------------------------------------------------------}
constructor TSAPxRFCABAPTEXTTableGS.Create;
begin
inherited Create;
TableType := dtCharGS;
with Fields.AddField do begin
Name := 'LINE';
DataType := dtCharGS;
DataSize := 72;
Offset := 0;
end;
end;

{-----------------------------------------------------------------------------}
procedure TSAPxRFCABAPTEXTTableGS.SetLINE(const AValue: String);
begin
Fields[0].AsString := AValue;
end;

{-----------------------------------------------------------------------------}
function TSAPxRFCABAPTEXTTableGS.GetLINE: String;
begin
Result := Fields[0].AsString;
end;

{-----------------------------------------------------------------------------}
{ TSAPxRFCZMY_STRUCTUREStrGS }
{-----------------------------------------------------------------------------}
constructor TSAPxRFCZMY_STRUCTUREStrGS.Create;
begin
inherited Create;
InstallStructure;
end;

{-----------------------------------------------------------------------------}
procedure TSAPxRFCZMY_STRUCTUREStrGS.SetTABNAME(const AValue: String);
begin
SubFields[0].AsString := AValue;
end;

{-----------------------------------------------------------------------------}
function TSAPxRFCZMY_STRUCTUREStrGS.GetTABNAME: String;
begin
Result := SubFields[0].AsString;
end;

Getting Started guide - Page 37 of 43 © 2002-2003 gs -soft AG, Switzerland


SAPx

{-----------------------------------------------------------------------------}
procedure TSAPxRFCZMY_STRUCTUREStrGS.SetFLAG(const AValue: String);
begin
SubFields[1].AsString := AValue;
end;

{-----------------------------------------------------------------------------}
function TSAPxRFCZMY_STRUCTUREStrGS.GetFLAG: String;
begin
Result := SubFields[1].AsString;
end;

{-----------------------------------------------------------------------------}
procedure TSAPxRFCZMY_STRUCTUREStrGS.InstallStructure;
var
oStr: TSAPxRFCStructureCacheItemGS;
i: Integer;
begin
oStr := FSAPxRFCEnvironment.StructureCache.FindStructure('ZMY_STRUCTURE');
if oStr = nil then begin
oStr := FSAPxRFCEnvironment.StructureCache.Add;
with oStr do begin
StructName := 'ZMY_STRUCTURE';
with Elements.AddElement do begin
Name := 'TABNAME';
DataType := dtCharGS;
DataSize := 30;
Offset := 0;
end;
with Elements.AddElement do begin
Name := 'FLAG';
DataType := dtCharGS;
DataSize := 1;
Offset := 30;
end;
end;
oStr.Install;
end;
DataType := dtStructureGS;
TypeHandle := oStr.TypeHandle;
SubFields.Clear;
for i := 0 to oStr.Elements.Count - 1 do
oStr.Elements[i].CreateField(SubFields);
end;

{-----------------------------------------------------------------------------}
{ TSAPxRFCZMY_SERVER_FUNCTIONFuncGS }
{-----------------------------------------------------------------------------}
constructor TSAPxRFCZMY_SERVER_FUNCTIONFuncGS.Create;
begin
inherited Create;
Name := 'ZMY_SERVER_FUNCTION';
with InParameters.AddParameterEx(TSAPxRFCZMY_STRUCTUREStrGS) do begin
Name := 'FSTAT';
DataSize := 31;
end;
with InParameters.AddParameter do begin
Name := 'FTABNAME';
DataSize := 30;

Getting Started guide - Page 38 of 43 © 2002-2003 gs -soft AG, Switzerland


SAPx

DataType := dtCharGS;
end;
with Tables.AddTableEx(TSAPxRFCABAPTEXTTableGS) do begin
Name := 'FDATA';
RecordSize := 72;
Open;
end;
end;

{-----------------------------------------------------------------------------}
function TSAPxRFCZMY_SERVER_FUNCTIONFuncGS.GetASTAT: TSAPxRFCZMY_STRUCTUREStrGS;
begin
Result := InParameters[0] as TSAPxRFCZMY_STRUCTUREStrGS;
end;

{-----------------------------------------------------------------------------}
function TSAPxRFCZMY_SERVER_FUNCTIONFuncGS.GetDATA: TSAPxRFCABAPTEXTTableGS;
begin
Result := Tables[0] as TSAPxRFCABAPTEXTTableGS;
end;

{-----------------------------------------------------------------------------}
function TSAPxRFCZMY_SERVER_FUNCTIONFuncGS.GetFTABNAME: string;
begin
Result := InParameters[1].AsString;
end;

{-----------------------------------------------------------------------------}
procedure TSA PxRFCZMY_SERVER_FUNCTIONFuncGS.SetFTABNAME(Value: string);
begin
InParameters[1].AsString := Value;
end;

{-----------------------------------------------------------------------------}
var
Srv: TxServer;
F1: TextFile;
Ch: Char;
begin
Srv := TxSe rver.Create;
try
Srv.Start;
AssignFile(F1, '');
Reset(F1);
try
repeat
Read(F1, Ch);
until UpperCase(Ch) = 'Q';
finally
CloseFile(F1);
end;
finally
Srv.Shutdown;
Srv.Free;
end;
end.

Getting Started guide - Page 39 of 43 © 2002-2003 gs -soft AG, Switzerland


SAPx

Appendix H – Listing of SAPx server as NT service

Listing 10: SAPx server as NT service

unit fMain;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, SvcMgr, Dialogs,
gsSAPxRFCvServer, gsSAPxRFCServer, gsSAPxRFCBase, gsSAPxRFCStdObj, Db, DBTables;

type
{-----------------------------------------------------------------------------}
{ TSAPxRFCService }
{-----------------------------------------------------------------------------}
TTransStatus = (tsCreated, tsExecuted);
TSAPxRFCServer = class(TService)
FSConnection1: TSAPxRFCvServerConnectionGS;
FSFunction21: TSAPxRFCvServerFunctionGS;
FSFunction11: TSAPxRFCvServerFunctionGS;
FSConnection2: TSAPxRFCvServerConnectionGS;
FSFunction12: TSAPxRFCvServerFunctionGS;
FSFunction22: TSAPxRFCvServerFunctionGS;
procedure ServiceStart(Sender: TService; var Started: Boolean);
procedure ServicePause(Sender: TService; var Paused: Boolean);
procedure ServiceContinue(Sender: TService; var Continued: Boolean);
procedure ServiceCreate(Sender: TObject);
procedure FSFunctionExecute(AFunction: TSAPxRFCServerFunctionGS);
procedure FSTxFunctionExecute(AFunction: TSAPxRFCServerFunctionGS);
procedure ServiceExecute(Sender: TService);
procedure ServiceStop(Sender: TService; var Stopped: Boolean);
procedure HandleCommit(Sender: TObject; const ATID: String);
procedure HandleConfirm(Sender: TObject; const ATID: String);
procedure HandleRollback(Sender: TObject; const ATID: String);
procedure HandleCheckTID(Sender: TObject; const ATID: String;
var AResult: TSAPxRFCCheckTIDResultGS);
procedure ServiceDestroy(Sender: TObject);
private
FTransList: TStringList;
procedure CreatingOnFly;
public
function GetServiceController: TServiceController; override;
end;

var
SAPxRFCServer: TSAPxRFCServer;

implementation
{$R *.DFM}

{-----------------------------------------------------------------------------}
procedure ServiceController(CtrlCode: DWord); stdcall;
begin
SAPxRFCServer.Controller(CtrlCode);
end;

{-----------------------------------------------------------------------------}

Getting Started guide - Page 40 of 43 © 2002-2003 gs -soft AG, Switzerland


SAPx

{ TSAPInfoService }
{-----------------------------------------------------------------------------}
function TSAPxRFCServer.GetServiceController: TServiceController;
begin
Result := ServiceController;
end;

{-----------------------------------------------------------------------------}
procedure TSAPxRFCServer.ServiceStart(Sender: TService; var Started: Boolean);
begin
SAPxRFCServerApplication.Start;
Started := not SAPxRFCServerApplication.Terminated;
end;

{-----------------------------------------------------------------------------}
procedure TSAPxRFCServer.ServicePause(Sender: TService; var Paused: Boolean);
begin
SAPxRFCServerApplication.Pause;
end;

{-------------------------------------------------------------- ---------------}
procedure TSAPxRFCServer.ServiceStop(Sender: TService; var Stopped: Boolean);
begin
SAPxRFCServerApplication.Shutdown;
end;

{-----------------------------------------------------------------------------}
procedure TSAPxRFCServer.ServiceContinue(Sender: TService; var Continued: Boolean);
begin
SAPxRFCServerApplication.Resume;
end;

{-----------------------------------------------------------------------------}
procedure TSAPxRFCServer.ServiceCreate(Sender: TObject);
begin
FTransList := TStringList.Create;
CreatingOnFly;
end;

{-----------------------------------------------------------------------------}
procedure TSAPxRFCServer.ServiceDestroy(Sender: TObject);
begin
FTransList.Free;
end;

{-----------------------------------------------------------------------------}
procedure TSAPxRFCServer.FSFunctionExecute(AFunction: TSAPxRFCServerFunctionGS);
begin
{ non-transactional actions }
end;

{-----------------------------------------------------------------------------}
procedure TSAPxRFCServer.FSTxFunctionExecute(AFunction: TSAPxRFCServerFunctionGS);
begin
{ transactional actions }
end;

{-----------------------------------------------------------------------------}
procedure TSAPxRFCServer.ServiceExecute(Sender: TService);

Getting Started guide - Page 41 of 43 © 2002-2003 gs -soft AG, Switzerland


SAPx

begin
while not Terminated do
ServiceThread.ProcessRequests(True);
end;

{-----------------------------------------------------------------------------}
procedure TSAPxRFCServer.CreatingOnFly;
var
i: Integer;
oFSFunction: TSAPxRFCvServerFunctionGS;
begin
for i := 0 to ComponentCount - 1 do
if Components[i] is TSAPxRFCvServerFunctionGS then begin
oFSFunction := TSAPxRFCvServerFunctionGS(Components[i]);
oFSFunction.InParameters.Clear;
oFSFunction.OutParameters.Clear;
with oFSFunction.InParameters.AddParameter do begin
{ specifying a set of input parameters }
end;
with oFSFunction.OutParameters.AddParameter do begin
{ specifying a set of output parameters }
end;
end;
end;

{--------------------------- --------------------------------------------------}
procedure TSAPxRFCServer.HandleCheckTID(Sender: TObject; const ATID: String;
var AResult: TSAPxRFCCheckTIDResultGS);
begin
if FTransList.IndexOf(ATID) = -1 then begin
FTransList.AddObject(ATID, TObject(tsCreated));
AResult := crOkGS;
end
else
AResult := crCancelGS;
end;

{-----------------------------------------------------------------------------}
procedure TSAPxRFCServer.HandleCommit(Sender: TObject; const ATID: String);
var
i: Integer;
begin
i := FTransList.IndexOf(ATID);
if i <> -1 then
FTransList.Objects[i] := TObject(tsExecuted);
{ DB commit }
end;

{-----------------------------------------------------------------------------}
procedure TSAPxRFCServer.HandleConfirm (Sender: TObject; const ATID: String);
var
i: Integer;
begin
i := FTransList.IndexOf(ATID);
if i <> -1 then
FTransList.Delete(i);
end;

{-----------------------------------------------------------------------------}

Getting Started guide - Page 42 of 43 © 2002-2003 gs -soft AG, Switzerland


SAPx

procedure TSAPxRFCServer.HandleRollback(Sender: TObject; const ATID: String);


begin
{ DB rollback }
end;

end.

Getting Started guide - Page 43 of 43 © 2002-2003 gs -soft AG, Switzerland

Potrebbero piacerti anche