call-sap-rfc(alias a,rfc b,[inMap c,timeout d,filter e,outList f,debug g,h,i,j])
Group |
Note: See also section SAP RFC.
Requests an RFC b at an SAP system that is identified by alias b. Parameters needed for the call are defined in a Named Map with name c. Fields and tables are returned line by line and are optionally added to a Named List or XML object f. If e is defined, only the specified fields and tables are used. If an ABAP exception occurs the job will be aborted, if not the name of the exception contains one of the tokens, as listed within param h. Parameter h contains an optional semicolon-separated list of ignored exceptions. If an exception occurred, which is ignored, the value of parameter i is returned instead. Parameter j for RFC queue and parameter k for JCoContext (see parameter table for details).
Description of Parameters
Parameter |
Description |
a |
The SAP alias. |
b |
RFC name. |
c |
(optional) Name of the map containing the input parameters. Default: default. See subsection Filling of Parameter Map c Before Call. |
d |
(optional) Time in seconds the function waits for a response for the request. A time lower than three seconds will be ignored. Default: 60 |
e |
(optional) Comma-separated list of field and table names and optional indexes the result should be restricted to. Default: No output filtering. See subsections Output Value Restriction with Parameter e (you can also output ABAP exceptions and the entire response in the SAPXML format). |
f |
(optional) This parameter allows you to additionally write the response values into a Named List or an XML object. If the parameter remains empty, neither is done. To additionally write into a list, simply enter its name here. The list is automatically created (or emptied, if it already exists). The response values are then inserted into the list. Filter e is also applied. The return values of the function and the contents of the list are therefore the same. To additionally write into an XML object, please use the prefix :xml: (written exactly like this and without spaces between prefix and name). The XML object is created automatically and will contain the entire response of the RFC. Filter e is not applied! You can evaluate the RFC response in the XML object using the functions select nodes from XML/DOM to List( a, b, c, d, e ) and get value from XML( a, b, c, d ). Note: The XML structure in the XML object is identical to the XML structure of the debug file *_debug_RfcOut.xml, which can be written as a local debug file using parameter g. |
g |
(optional) true if a trace files of the request should be generated. Default: false . The names of the created trace files will be logged into Lobster_data's log. File name format: <Job number>_<Timestamp>_debug_<RFC name>_<In|Out>.xml , where for a mapping test the value T is used instead of the job number . The files are written into folder ./debug/sap . Important note: Even if the parameter is set to true, the trace files are only written in a mapping test or if tracing has been activated for phase 3 of the profile (or system-wide). If you always want to write the debug files (e.g. in the test phase as proof for the SAP team), i.e. also in a normal job run and without the tracing in phase 3 activated (with its corresponding overhead), you can also specify the value always . Warning: These files are not automatically deleted, so it is the user's responsibility to monitor this folder and delete files manually to prevent a disk overflow. Please also note that a high number of files in this folder can affect performance. |
h |
(optional) Semicolon-separated list of ABAP exceptions to be ignored. |
i |
(optional) Return value if an ignored ABAP exception (see parameter h) occurred. |
j |
(optional) The RFC queue to be used. If the parameter is left empty, the default queue is used. Warning: If a JCoContext is used (see parameter k), a defined queue is ignored! |
k |
(optional) Create JCoContext (true/false). Default: <empty>. Limitation: The JCoContext can only be created for connections with JCo version 3. For aliases with JCo version 2.x, the function terminates with an error occurs if k=true. If a call is made with k=true, a JCoContext is created for alias a, which exists until the end of phase 3 of this profile job (or until a termination with error). Only with an explicit parameter value k=false, you can remove a subsequent call from an existing JCoContext (an empty parameter k does not close the context!). Such a context is required for (stateful) BAPI calls (Business Objects in SAP). All BAPI calls must take place in the same JCoContext because they are contiguous. All calls together are then committed at the end (BAPI_TRANSACTION_COMMIT). If no commit is executed by the end of the JCoContext, the BAPI data transferred to the SAP system within this JCoContext is discarded. Normal RFC calls do not have to be committed, so the JCoContext has no meaning there and should only be created for sequential BAPI calls, since it is very resource-intensive. But you can also call normal RFCs in an existing JCoContext. Note, however, that these are not rolled back if a commit is not made, because they will work without it! Warning: When the JCoContext is created, any queue defined in parameter j is ignored! Note: In the first function call, the value true can also be written in capital letters (TRUE). In that case, the JCoDestination for this job is cloned and an RFC_PING is executed at the beginning to test the connection. |
Filling of Parameter Map c Before Call
The function expects key-value-pairs following a specific notation in order to be able to assign the values to the corresponding parameters in the RFC.
Type of Input Parameter |
Resulting Key per Field |
A single field. |
fieldName |
A structure containing a list of fields (components). |
structureName-fieldName |
A table containing fields (components) as rows. |
tableName[rowNumber]-columnName |
If the value in the map contains a text like @variable_name@ and the mapping has a variable with that name defined, the placeholder will be replaced by the value of the variable. Is there no such variable, the text will be unchanged and be used as parameter including the placeholder.
To ease the process of creating the map holding the parameters, the function fill-map-from-fields( map a, prefix b, index c, hidden d ) can be used.
In the case of structures and tables, it must be noted that the components (field names/column names) are not optional. If a component is specified for a structure type, all other components of this structure must also be defined (with an empty value or the default 0 for numeric types). For tables, each row represents a structural value. As a result, all the components of a row must also be defined there. In the case of tables, it is also important to note that the line numbers must be continuous to avoid a premature termination of the parameter list. If the parameter map c is filled with the function fill-map-from-fields( map a, prefix b, index c, hidden d ), all components of structures and tables must be defined as the fields in the destination structure of the profile. In order to force the insertion of empty fields as well, the processing statement val:addempty must also be used, as described in the documentation for this function. Fields and tables are returned by the function in the same way as it happens with the call of RFCs using the time-driven Input Agent SAP if the output format FixRecord has been selected. You will also find an example at the end of this page.
Output Value Restriction with Parameter e
To restrict the response to single fields or lines of a specific table, it is enough to specify the names of the field or table names in parameter e, e.g. QUERY_TABLE,DATA. If only a part of the single value is needed, it is possible to define part text areas (substrings) to be used for the creation of the result line. This is done in the form of name[index_definition] or name[index_definition}, whereby the beginning of the line is represented by index 1. The curly bracket at the end results in a removal of trailing spaces in the resulting line. An index definition is defined in the form of [fromIndex+length] or [fromIndex-untilIndex]. The untilIndex is exclusive. If it is omitted, the end of the line is taken. Multiple index definitions can be joined by putting a slash / between them.
Below you can find some variants of output filter definitions. All of them are run against the following example line (spaces where substituted by underlines).
DATA__________________________Val1______Val2___Val3________Val4____ |
Output Filter Rule |
Meaning |
Result |
DATA |
The complete line. |
Like above. |
DATA[1] |
The complete line. |
Like above. |
DATA[1} |
The complete line without trailing spaces. |
DATA__[...]__Val4 |
DATA[31] |
The line from index 31. |
Val1__[...]__Val4____ |
DATA[1-2/31-41/48-60} |
The first character, Field1, Field3 without trailing spaces |
DVal1______Val3 |
DATA[1+2/31-41/48-60} |
The first two characters, Field1, Field3 without trailing spaces |
DAVal1______Val3 |
If a list is specified in f, the result of a successful function call is saved in this Named List and also returned as the result of the function. In the return value, the individual records are separated by a line break, whereas in the list each record is a single list entry.
ABAP Exceptions
When the RFC ends with an ABAP exception, then the profile job will end with an error by default. You can modify this behaviour by explicitly inserting the segment EXCEPTION in the parameter e. If so, the ABAP exception is returned within a segment EXCEPTION. Other exceptions from JCo, which do not have the type AbapException, cannot be caught but will terminate the job with an error.
Format SAPXML
If one of the filter rules in parameter e is either :SAPXML: or :sapxml:, the entire response of the RFC is returned in the SAPXML format. All other filter rules except EXCEPTION are then ignored.
This XML can optionally be supplied in a single line if :sapxml: (in lower case) is used, or multi-line (formatted) if :SAPXML: (in upper case) is used.
Both options can be used together with parameter f. For single-line XML return, the list will contain the entire XML in one element. For multiline XML return, the list will contain one element per line.
Examples
The call of the function is shown using RFC_READ_TABLE as an example. See section Example for 'call-sap-rfc'.