Closed RDPerera closed 3 months ago
When considering the use case for input parameters and output parameters in SAP JCo, the RFC accepts multiple values. To improve usability, we can introduce two functions in Ballerina:
public type FieldType string|int|float|decimal|boolean|byte[]|time:Date|time:TimeOfDay|time:Utc|record {|FieldType...;|}|record {|FieldType...;|}[];
isolated remote function execute(string functionName, FieldType? importParams = (), typedesc<FieldType|FieldType[]|map<FieldType>|xml|json?> exportParams = <>) returns exportParams|Error;
isolated remote function executeWithMultipleParams(string functionName, FieldType[]|map<FieldType>? importParams = (), typedesc<FieldType|FieldType[]|map<FieldType>|xml|json?> exportParams = <>) returns exportParams|Error;
The execute() function can be used when there is only one input parameter, and executeWithMultipleParams() can be used for multiple values.
For the output return, all simple types can be used to bind to specific types:
// Returns one string field
string result = check jcoClient->execute("functionName", "a");
// Returns multiple fields in order
FieldType[] results = check jcoClient->execute("functionName", "a");
// Returns multiple fields with parameter names
map<string> resultsMap = check jcoClient->execute("functionName", "a");
// Returns one JCoStructure
record{||} structure = check jcoClient->execute("functionName", "a");
// Returns one JCoStructure with parameter names
map<record{||}> structuresMap = check jcoClient->execute("functionName", "a");
// Returns a table
record{||}[] table = check jcoClient->execute("functionName", "a");
// Returns multiple tables in positional value
record{||}[][] tables = check jcoClient->execute("functionName", "a");
To handle the case where multiple JCoStructures are expected in an array, we introduce a special annotation:
public annotation MultiStructure on type;
@MultiStructure
type MultipleValues record{||}[];
MultipleValues _ = check jcoClient->execute("", "a");
This exception addresses potential confusion when the user expects either one return value of table type or multiple JCoStructures in an array.
Note on Data Mapping in Ballerina In Ballerina, another consideration for data mapping is to process all return values if the return type is an open record, or only return specified fields for closed records. This will not apply to JCoStructure or JCoTable. Due to compile-time validation of types, the user must always use a closed record. Since these types contain only limited fields, significant performance degradation due to this behavior is not expected.
This proposal outlines the mapping of JCo data types to Ballerina data types for the SAP JCo Connector. The objective is to ensure accurate and efficient data exchange between SAP systems and Ballerina applications by providing clear and consistent mappings for both import (setters) and export (getters) parameter types.
JCo to Ballerina Data Type Mapping
string
string
string
int
int
int
int
float
decimal
byte[]
boolean
time:Date
time:TimeOfDay
time:Utc
string
string
decimal
string
record {}
record{}[]