Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Proposal] Enhanced Usability for SAP JCo Function Execution in Ballerina with Multiple Parameters #6783

Closed
RDPerera opened this issue Jul 25, 2024 · 1 comment · Fixed by ballerina-platform/module-ballerinax-sap.jco#21
Assignees
Labels
module/sap.jco Issues related to Ballerina SAPJCo module Status/Active Proposals that are under review Type/Improvement Type/Proposal

Comments

@RDPerera
Copy link
Member

RDPerera commented Jul 25, 2024

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

ABAP Type Description Ballerina Type
CHAR Fixed-length character string string
CHAR Single character string
NUMC Numeric text string
INT1 1-byte integer int
INT2 2-byte integer int
INT4 4-byte integer int
INT8 8-byte integer (if supported) int
FLTP Floating-point number float
DEC Packed decimal decimal
RAW/XSTR Variable-length byte string byte[]
CHAR/FLAG Character representing true/false (e.g., 'X' for true) boolean
DATS Date in the format YYYYMMDD time:Date
TIMS Time in the format HHMMSS time:TimeOfDay
DATS/TIMS Combination of date and time time:Utc
LANG Language key string
CUKY Currency key string
QUAN Quantity field decimal
UNIT Unit of measure string
Complex ABAP Type Description Ballerina Type
STRUCTURE Group of fields record {}
TABLE Multi-row dataset, array of structures record{}[]
@RDPerera RDPerera added Type/Proposal module/sap.jco Issues related to Ballerina SAPJCo module labels Jul 25, 2024
@niveathika
Copy link
Contributor

niveathika commented Jul 29, 2024

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.

@niveathika niveathika changed the title [Proposal] Mapping SAP JCo Data Types to Ballerina Data Types in the Ballerina SAP JCo Connector [Proposal] Enhanced Usability for SAP JCo Function Execution in Ballerina with Multiple Parameters Jul 29, 2024
@niveathika niveathika added the Status/Active Proposals that are under review label Jul 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
module/sap.jco Issues related to Ballerina SAPJCo module Status/Active Proposals that are under review Type/Improvement Type/Proposal
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants