Introduction
In the last 15 years, several approaches have been developed for connecting with SAP – or running in conjunction with SAP, using Java. The Java language is now used side-by-side with the original SAP programming language ABAP.
SAP-Java connector
SAP Java Connector (JCo) is a middleware component that enables you to develop ABAP-compliant components and applications in Java. SAP JCo supports communication with the AS ABAP in both directions: inbound (Java calls ABAP) and outbound calls (ABAP calls Java).
The figure below shows the communication layers of the Jco Java to SAP connection.
Data conversion via these layers work as follows in the SAP JCo (standalone version):
- Java Application – a Java method is forwarded via the
- JCo Java API (Application Programming Interface) to the
- CPI-C layer – which converts it to an,
- RFC (ABAP) call using the
- JNI (Java Native Interface) layer
and sent to the SAP system.
JCo essentially facilitates a bidirectional interface – and communication channel – to and from SAP. Jco is suited for reading tables from the SAP Hana database. .
SAP JCo offers the following functions for creating ABAP-compliant external Java applications:
- SAP JCo is based on JNI (Java Native Interface) that enables access to the CPI-C library,
- It supports SAP (R/3) systems from Release 3.1H upwards, and other SAP components that provideBAPIs or RFMs (Remote-enabled Function Modules),
- A JCo program can execute inbound function calls (Java client calls BAPI or RFM) or receive outboundfunction calls (ABAP calls external Java Server),
- With SAP JCo, you can use synchronous, transactional, queued and background RFC,
- SAP JCo can be used on different platforms.
The major application of the JCo connector is reading data content from SAP-tables into Java-classes. The Java-code fragment below shows how to retrieve the data in the SAP table COMPANYCODE_LIST.
JCoFunctionfunction function = dest.getRepository().getFunction("BAPI_COMPANYCODE_GETLIST"); if (function == null) { throw new RuntimeException("BAPI_COMPANYCODE_GETLIST not found in SAP."); } try { function.execute(dest); } catch (AbapException e) { System.out.println(e); return; } JCoStructurereturnStructure = function.getExportParameterList().getStructure("RETURN"); if ( !(returnStructure.getString("TYPE").equals("") || returnStructure.getString("TYPE").equals("S"))) { throw new RuntimeException(returnStructure.getString("MESSAGE")); } // Here - the actual table content is being retrieved from SAP JCoTablecodes = function.getTableParameterList().getTable("COMPANYCODE_LIST"); for (int i = 0; i < codes.getNumRows(); i++) { codes.setRow(i); System.out.println(codes.getString("COMP_CODE") + '\t' + codes.getString("COMP_NAME")); }
JCo is a much simpler way to connect with SAP and exchange data, than the elaborate SAP NetWeaver Java-framework.
JCo makes use of the SAP RFC protocol for calling a SAP BAPI function.