Properties of the RFC Select interface

The "RFC Select Interface" frequently used in CIS mobile is a combination of two components of the SAP Basis System:
  • ABAP select statement for accessing the database incl. SAP's own cache ("table buffer" on application server)
  • Remote Function Call (RFC) for external call of ABAP functions

In VB.NET you build a select statement (SAP syntax). This is transferred via RFC to a generic ABAP function module in the SAP system and executed there. The result table of the select represents the return of the RFC call. In VB.NET you then process the returned data.

In addition, the RFC Select interface does the following:

  • Multiple accesses can optionally be processed "bundled". That is, multiple select statements are collected and then executed with a single RFC in the SAP system. The RFC then returns all result tables of the select statements. The interface splits them again among the individual select statements when they are returned.
  • Optionally, you can buffer individual accesses to SAP tables in a cache so that no RFC is required. The access times, if the record is found in the cache, are of the order of a few microseconds, while the RFC call is of the order of a few milliseconds, i.e. a factor of 1000.

Advantages and disadvantages:

  • No ABAP knowledge required
  • Very good performance achievable
  • Complex select accesses only via definition of views in the SAP system
  • Additional authorization checks may be required in VB.NET
  • Very fast implementation
  • Optimal if all required data originate from a single SAP table (or view)
  • Can be combined with local cache
Example 1:
Read article number and name of the customer

In addition to a material number, we want to display the customer's article number and article description as a CIS add-on. You can find all details about the add-on integration in the chapter "Implementing add-ons" in section Example article description. Here we focus on data acquisition.

In the SAP system, this information is displayed in transaction VD53:

 

The corresponding database table is the KNMT, shown here with transaction SE11, red bordered the two fields we need:

 

With the key fields VKORG, VTWEG, KUNNR and MATNR we want to read the table KNMT and take from it the fields KDMAT (article number at customer) and POSTX (article description at customer). The VB.NET coding for this can look like this:

Vb.net
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
Private Function read_knmt(ByVal Sorg As String, ByVal Vtweg As String, _
                ByVal Account As String, ByVal Matnr As String, _
                ByRef KDMAT As String, ByRef POSTX As String) As Boolean


        Dim Sapknmt As New Addonknmt

        ' fill all key fields
        Sapknmt.vkorg = Sorg
        Sapknmt.vtweg = Vtweg
        Sapknmt.kunnr = Account
        Sapknmt.matnr = Matnr

        ' read KNMT via RFC / SAP Select
        If Sapknmt.ic.RfcDatabaseRead() Then

            ' set values from KNMT 
            KDMAT = Sapknmt.kdmat 'Material number (customer)
            POSTX = Sapknmt.postx 'Material text   (customer)

            Return True
        Else

            KDMAT = ""
            POSTX = ""

            Return False

        End If

 

For this to work, especially the class "addonknmt" is known in VB.NET, create the class in the "S10 Repository" of the CIS mobile project and include in your VB.NET project "s10cisaddon" the VB.NET classes addonknmt and s10_addonmt generated from it. This works as follows:

Start the S10 repository,




open the CIS mobile project and click Class-> Generate from SAP table in the menu

 
In the next screen enter the SAP table "KNMT" and class "addonknmt". Please let self-added classes always start with "addon" so that there is no overlap in later CIS mobile upgrades:


:

Generate the class "addonknmt" from the SAP table KNMT in the S10 repository.

 

As "assembly" please use your VB.NET project "s10csiaddon" enter After generation, "s10cis", i.e. the CIS mobile standard project, is displayed here first:

Generated class addonknmt in S10 repository

 

 

If you only need the two fields KDMAT and POSTX apart from the key fields, you can delete all other fields or set them to comment with // at the beginning of the line. This has the advantage that the database interface only has to read these two fields, which is then faster, especially in the case of a matching secondary index.

If you need other fields later, you can either include them again (if you need the additional fields in the same database access) or create a second class addonknmt2 suitable for a different database access.

You can delete the MANDT field (client in SAP system), since it is set automatically by the SAP Select interface. However, there is no harm in leaving it in the class. In any case, it is not necessary to provide MANDT with a value to read the table.

Finally, press "Generate" in the S10 repository to generate the VB.NET classes.

Class addonknmt in S10 repository after deleting unnecessary fields

 

From the class addonknmt the VB.NET files addonknmt.vb and s10_addonknmt.vb are generated at "Generate". Include both files in your VB.NET project "s10ciaddon". To do this, it is best to first copy the files from the "classes\s10cisaddon" subdirectory of the CIS mobile folder to config\s10cisaddon:

The two generated VB.NET files are initially located in classes/s10cisaddon
 

Copy the two files into your project, i.e. to config/s10cisaddon

 

And finally, add both files to your VB.NET project "s10cisaddon" using "Add Existing Item" in Visual Studio :



 

General procedure for reading an SAP table

1. For the SAP table XXXX, generate a new table in the S10 Repository a class addonxxxx

2. With: assembly= Put "s10cisaddon" instead of the generated "s10cis".

3. Optional: Remove the unnecessary fields (but not the key fields) there

4. On "Generate" click

5. The two files addonxxxx.vb and s10_addonxxxx.vb copy You from classes/s10cisaddon to config/s10cisaddon

6. In your VB.NET Project "s10cisaddon" you add the two files via Project->Add existing element auf

7. Now you can create an object of class addonxxxx in VB.NET and read the SAP table with ic.RfcDatabaseRead() or ic.RfcDatabaSeselect()

Bundled accesses

Instead of a single table row, you can also read in a set of rows from a table specified by a WHERE condition.
You can find a detailed example of this at the add-on Complaints.

Procedure:

1. For the SAP table XXXX, generate a new table in the S10 Repository a class addonxxxx

2. With: assembly= Instead of the generated "s10cis" put the name "s10cisaddon

3. Optional: In the class, remove the fields that are not needed (but not the key fields)

4. On "Generate" click

5. The two files addonxxxx.vb and s10_addonxxxx.vb copy You from classes/s10cisaddon to config/s10cisaddon

6. In your VB.NET Project "s10cisaddon" you add the two files via Projekt->Vorhandenes Element hinzufügen

7. In the S10 repository, take a "folder" On in the class "addon", which contains objects of the class addonxxx:

   folder all_xxxx class="addonxxxx"

8. Now you can read in the desired table rows in VB.NET with all_xxxx.RfcDatabaseSelect()

9. With the loop

    For all x as addonxxxx in all_xxxx


    Next

 You will get all read table rows one after the other.

Description of ic.RfcDatabaseRead (from S10 Forum)
Function

With ic.RfcDatabaseRead() read an object from the SAP database via the S10 RFC database interface.

All fields of the S10 class specified with dbkey="yes" are used to automatically form the where condition for database access via SAP Select.

Format

ic.RfcDatabaseRead([withcache as Boolean = true]) as Boolean

Return value

True if the object was found, otherwise False.

Arguments
withcache

The S10 cache is used if dbcache="yes" is specified in the class definition and the object has not been locked before.

   

 

Description of ic.RfcDatabaseSelect (from S10 Forum)
Function

With ic.RfcDatabaseSelect() You can read database tables from the SAP database via the S10 RFC database interface.

The expression condition Is used to execute the SAP select command (WHERE condition). Only the first row of the result table is evaluated; please use a S10 folder to read in multiple table rows. 

You can use attribute names with an '@' prefix in the expression, e.g. @CompanyID. They are replaced by the attribute value in database-adequate format. For example, strings are enclosed with '...' and number or date formats are inserted appropriately.

Format

ic.RfcDatabaseSelect(condition As String) As Boolean

Arguments

condition

where condition for the SAP select call. The syntax is largely identical to the standard SQL syntax, see the SAP documentation on the ABAP select statement.

Bitte beachten: The SAP field names must be specified in capital letters, e.g. KUNNR and not kunnr.

Return value

True if at least one line has been read, otherwise False

Description of folder.RfcDatabaseSelect (from S10 Forum)
Function

With folder.DatabaseSelect() You can read several table rows from a database into a folder. This is only possible with typed folders (classname="..." in the S10 folder attribute).

Existing elements are deleted before the new elements are added. If you want to keep the existing elements and append the new ones, please use instead  folder.DatabaseAddSelect() .

The expression stmt Is used to execute an SQL command. For all S10 attributes that refer to a database column, an attempt is made to match them to a column in the results list. If an attribute is not found in the results list, it is left empty.

For the printout stmt There are two possibilities:

  • A complete "Select" command (Cf. Example 1)
    In this case, the printout will be executed without any changes.
     

  • An expression that does not begin with "Select" (upper or lower case) (Cf. Example 2)
    In this case, the system first generates a select command "Select [field list] from [table name] " , then adds the expression and executes the resulting command.
    The [field list] consists of all database fields in the S10 class definition, and the table name is the table name assigned to the S10 class. The expression stmt can be a WHERE condition and/or other SQL phrases like ORDER BY or GROUP BY.

You can use attribute names with an '@' prefix in the expression, e.g. @CompanyID. They are replaced by the attribute value in database-adequate format. For example, strings are enclosed with '...' and number or date formats are inserted appropriately.

 

Format

folder.DatabaseSelect(stmt As String) As Integer

Return value

Number of new folder items, or -1 if a database error occurred.

 

Bundling of accesses

For example, if you have two objects

dim sapxxxx like addonxxxx
dim sapyyy like addonyyy


for which you read the values from the SAP tables xxxx and yyyy with ic.RfcDatabaseRead():

sapxxxx.ic.rfcdatabaseread()
sapyyy.ic.rfcdatabaseread()


two RFC calls are made to the SAP system in succession.

Instead you can use

sapxxxx.ic.rfcdatabaseread(deferred:=True)
sapyyy.ic.rfcdatabaseread
(deferred:=True)

ic.RfcExecuteDeferredCalls(rfcmessages)

work. In this case, both database accesses are stored in oneprocessed in a single RFC call.
Auch Volume accesses über folder.RfcDatabaseSelect können Sie über
deferred:=True in take up the bundled processing.

Using the cache

Regardless of any buffering of the tables on the SAP application server, you can use an access cache on the machine running CIS mobile and thus avoid RFC access in many cases. This is done simply by adding dbcache="yes" to the class definition in the S10 repository:

All entries found are then stored locally and searched there first. The cache content is discarded at the beginning of the day and recreated, i.e. the entries in the cache are out of date for a maximum of 24 hours. This makes the cache well usable for tables where a next day update is sufficient. For Example: Designations of plants, storage locations, order types, tax codes, payment terms, etc. 

The total size of the cache is defined in the S10 repository for CIS mobile under "Properties":

The cache is shared for all CIS mobile users, i.e. what was read in for one user is used for all other users.

If the cache is full, the oldest entries are displaced by newly added ones. With 4MB and an average length of 400 bytes per stored record, approximately 10,000 different entries can be buffered. This is sufficient for an application such as CIS mobile, since the set of keys such as storage locations, order types, etc., is too large. is not so big. However, you can also reserve e.g. 100MB without any problems, since the memory only accrues once, even with e.g. 50 active users.

With the trace function of the S10 Repository you can determine which accesses were processed via the cache. In the following excerpt, you can see two RFC function calls and then several table accesses found in the cache: