Example for 'call-sap-rfc'
The call of the function call-sap-rfc(alias a,rfc b,[inMap c,timeout d,filter e,outList f,debug g,h,i,j,k]) is shown using RFC_READ_TABLE as an example. The interface description can be retrieved using Lobster_data and looks like follows.
RFC_READ_TABLE |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Input Parameters |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Output Parameters |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
None |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Table Parameters |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
The description shows the following parameters that are needed to be set in order to call the RFC.
Parameter Name |
Type |
Meaning |
Field Names Within That Parameter |
DELIMITER |
Field Char(1) |
A delimiter to separate single values within a response line. |
n.a. |
NO_DATA |
Field Char(1) |
X if no data but only the field information is needed. |
n.a. |
QUERY_TABLE |
Field Char(30) |
Name of the database table to read from. |
n.a. |
ROWCOUNT |
Field Integer |
Number of rows to read. |
n.a. |
ROWSKIPS |
Field Integer |
Number of rows to be skipped before ROWCOUNT rows are read. |
n.a. |
DATA |
Table(OUT) |
Contains the read rows after a successful call. |
WA Char(512) |
FIELDS |
Table(INOUT) |
Information about the fields being read or - if set in the request - the columns to be read from the table. |
FIELDNAME Char(30) |
OPTIONS |
Table(IN) |
Text being added to the internally used SQL statement and regarded as the WHERE part of the statement. |
TEXT Char(72) |
To prepare and perform the RFC call, a destination structure like the following can be prepared.
In general, the node CallSapRfc can be organised into two main parts.
Creation of the map that contains all values being needed. Because the RFC in this example does not have any parameters of type structures only two nodes filling the field parameters (node fill_INPUT_PARAMS) and table parameters (node fill_TABLE_PARAMS) are used.
Call of the RFC in the node CALL containing an additional field dumpParamsKeys thatis only used to dump keys and values of the parameter map. This can, for example, be used e.g. in a mapping test.
Filling Values into the Parameter Map
The fields in the nodes are named exactly like the names of the fields in the corresponding parameter (in this case fields and tables, everything following after a # is ignored).
The goal of this example is reducing the number of fields to be read. This is realised by using a list that is filled in the field prepareFieldSelection.
1) save variable a(b) type-safe
a constant: VAR_FIELD_SELECTION
b constant: MANDT,CARRID,CONNID,FLDATE,PRICE,CURRENCY,PLANETYPE
2) add to list(a,b,c)
a result: 1
b constant: fieldList
c constant: ,
3) count values in list(name of list a)
a constant: fieldList
4) save variable a(b) type-safe
a constant: VAR_SIZE
b result: 3
In every iteration of the node fill_FIELDS the first element of the list at that time is removed.
1) remove from list(position a, name of list b)
a constant: 1
b constant: fieldList
These are the functions of the single fill fields.
In field fill_INPUT
1) fill-map-from-fields( map a, prefix b, index c, hidden d )
a constant: inMap
b constant:
c constant:
d constant: false
In field fill_option_table
1) fill-map-from-fields( map a, prefix b, index c, hidden d )
a constant: inMap
b constant: OPTIONS[#]
c constant: 1
d constant: true
In field fill_fields_table
1) calculate and save variable(a,b,c,d,[e])
a constant: VAR_COUNTER
b constant: +
c constant: 1
d constant: true
2) fill-map-from-fields( map a, prefix b, index c, hidden d )
a constant: inMap
b constant: FIELDS[#]
c variable: VAR_COUNTER
d constant: true
dumpParamsKeys is only used to dump the keys and values of the parameter map to the log. To prevent this from happening when the mapping runs productively, the variable VAR_IS_TEST is checked.
1) dump map (a,b)
a constant: inMap
b variable: VAR_IS_TEST
The field callRFC contains the 'main' function for the call of the RFC.
1) call-sap-rfc( alias a,rfc b,[inMap c],[timeout d],[filter e],[outList f],[debug g])
a constant: testsap
b constant: RFC_READ_TABLE
c constant: inMap
d constant: 8
e constant: DATA[1}
f constant: outList
g constant: true
RFC Call
When starting the test, the dumParamKeys functions will log the following.
[...]
[M:] Dump of map inMap:
'FIELDS[6]-LENGTH'='0'
'FIELDS[5]-FIELDTEXT'=' '
'FIELDS[3]-LENGTH'='0'
'FIELDS[7]-OFFSET'='0'
'FIELDS[1]-OFFSET'='0'
'FIELDS[1]-FIELDNAME'='MANDT'
'FIELDS[4]-LENGTH'='0'
'FIELDS[4]-FIELDNAME'='FLDATE'
'FIELDS[7]-TYPE'=' '
'QUERY_TABLE'='SFLIGHT'
'FIELDS[6]-FIELDTEXT'=' '
'FIELDS[1]-TYPE'=' '
'FIELDS[6]-TYPE'=' '
'FIELDS[7]-FIELDTEXT'=' '
'FIELDS[2]-FIELDTEXT'=' '
'FIELDS[2]-LENGTH'='0'
'OPTIONS[1]-TEXT'='CARRID = 'LH''
[...]
'FIELDS[2]-OFFSET'='0'
'FIELDS[5]-OFFSET'='0'
'FIELDS[5]-LENGTH'='0'
'FIELDS[1]-LENGTH'='0'
'FIELDS[3]-FIELDNAME'='CONNID'
'FIELDS[2]-TYPE'=' '
'ROWCOUNT'='@VAR_ROWCOUNT@'
'FIELDS[4]-OFFSET'='0'
[...]
For technical reasons, the key-value pairs are not sorted.
The call of the function call-sap-rfc(alias a,rfc b,[inMap c,timeout d,filter e,outList f,debug g,h,i]) leads to the following messages.
15:07:52.768 [M:] Calling SAP by RFC 'RFC_READ_TABLE'
15:07:52.893 [M:] rfc debug info: .\debug\sap\1319029672768_debug_RfcIn.xml
15:07:52.940 [M:] rfc debug info: .\debug\sap\1319029672768_debug_RfcOut.xml
15:07:52.940 [M:] Returning from SAP RFC 'RFC_READ_TABLE' after 172 ms
15:07:52.940 [M:field=callRFC] Executed function [Pos=1]call-sap-rfc( alias a,rfc b,[inMap c],[timeout d],[filter e],[outList f],[debug g]), result='DATA 000LH 040020011222 666.00 EUR A310-300
DATA 000LH 040020020119 666.00 EUR A310-300
DATA 000LH 040020020216 666.00 EUR A310-300
DATA 000LH 040020020316 666.00 EUR A310-300
DATA 000LH 040020020413 666.00 EUR A310-300
'
Because parameter g is set to true, trace files were created and their filenames are logged. Because an output list has been specified, containing the rows of output table DATA the result of the function itself - a fix record format - can be ignored or used for bug tracking purposes.
Result Processing
In this example, the values of output table DATA were added to the list outList. Every element in that list is a complete row of the table DATA. The single values must be 'extracted' by yourself later on.
The example profile does that in node OUTPUT.
In order to enter the node OUTPUT as often as there are entries in the list, the number of values is saved to a variable of type Integer in field readSize. This variable is used as path in node OUTPUT. The calculation field item always removes the first entry from that list outList using the function remove from list, all subsequent functions use the value of this field for further processing (using destination field item). Are more than one field or table added to the result (by saying so using parameter e) the different lines must be 'distributed' over the corresponding nodes. For this reason - even if it is not needed in this particular examples - there is a function on node OUTPUT.
1) starts-with( a, b )
a destination: item
b constant: DATA
If the condition is met, the node will be entered and the calculation field data_item will cut away the first 30 characters of the row to let the line start with the first data field of the response.
All subsequent fields are cutting the needed part out of this line using the function substring( a, start [,length] ) to eventually continue with the data conversion using other functions. Field FLDATE is shown here as an example:
1) substring( a, start [,length] )
a destination: data_item
b constant: 11
c constant: 8
2) create date(a, [adj. template b], template c, d [, force-empty e])
a result: 1
b constant: yyyyMMdd
c constant: dd.MM.yyyy
d constant: empty
e constant:
An exemplary result of a node OUTPUT can be seen in the following screenshot.
Remarks
Following the profile, this example is based on: Package-SAP RFC Call Example RFC_READ_TABLE.pak