sap4j
We make SAP interactions dead easy :)
Download
sap4j is available on Maven central repository.
<dependency>
<groupId>com.sap4j</groupId>
<artifactId>sap4j</artifactId>
<version>1.0.2</version>
</dependency>
Features
- Clean and intuitive DSL to describe connections, queries and iterate results.
- Maintain multiple SAP connections, query tables and BAPI functions while retrieving all results with same interface.
- Includes circuit breaker pattern, to avoid overhelming SAP server when query execution issues arise.
- Provide means to define throttling policies for queries execution.
Usage Examples
Properties properties = new Properties();
properties.setProperty("username", "xxx");
properties.setProperty("password", "xxx");
SAPConnection connection =
SAPConnectionBuilder.getInstance()
.withLanguage(ISO639LanguageCode.EN)
.withAsHost("somehost")
.withClient("001")
.withSysnr("01")
.withPoolCapacity(3)
.withCredential(SAPCredential.fromProperties(properties))
.build();
// Instantiate executor for given connection
SAPQueryExecutor executor = SAPQueryExecutor.forConnection(connection, throttlingPolicy, circuitBreaker);
// Write some query
SAPQuery query = SAPQueryBuilder.queryFunction("BAPI_MATERIAL_STOCK_REQ_LIST")
.withQueryCondition("MATERIAL", "XAEA12")
.withQueryCondition("GET_IND_LINES", "X")
.fromTable("MRP_IND_LINES").build();
// Execute query
Map<String, Iterator<SAPResultRow>> results = executor.execute(query);
// Retrieve results
Iterator<SAPResultRow> rows = results.get("MRP_IND_LINES");
// Iterate and process results
while(rows.hasNext()){
StringBuilder builder = new StringBuilder();
Map<String, String> values = rows.next().getColumnValues(); // process results
for(String key : values.keySet()){
builder.append(String.format("'%s', ", values.get(key)));
}
System.out.println(builder.toString());
}
Limitations
At the current stage, the library provides means to read data. Executions to write data into SAP were not developed yet. We do not deal with queries caching: this should be handled on server side, to ensure data consisenty.
Recommendations
To ensure optimal queries, please check query conditions target indexed fields. More details on how to ensure high performance can be found in the following SAP document. We specifically advice "Section 5.5: SQL Tuning Guidelines". The rest of the document provides an overview on inner workings of relational DBs, providing details regarding queries optimization, compilation and execution; useful information on how to debug queries performance issues.