Posted at

SAP RFC from JSP via JCO

More than 1 year has passed since last update.

This article shows a simple JSP program calling SAP Remote function module via JCo(SAP Java Connector).

How to create JCO and JDK environment is on another article(Japanese).

How to create Eclipse and Jetty environment is on another article(Japanese).

Development Environment

  • IDE: Eclipse(Oxygen.2 Release (4.7.2))

  • JDK: Oracle JDK 1.8.0_152(not SAP JDK)

  • JCo: SAP Java Connector 3.0.17

  • Web Server: Jetty(Eclipse plugin "Eclipse Jetty3.9.0" and "Run-Jetty-Run 1.3.5-nightly")

JSP code

Very simple program calling function module "STFC_CONNECTION".


<%@ page language="java" contentType="text/html; charset=Windows-31J"%>
<%@ page
// ABAP Application Server

// Destination Properties
static {
Properties connectProperties = new Properties();
connectProperties.setProperty(DestinationDataProvider.JCO_ASHOST, "XXXX"); //host name or ip address
connectProperties.setProperty(DestinationDataProvider.JCO_SYSNR, "00");
connectProperties.setProperty(DestinationDataProvider.JCO_CLIENT, "400");
connectProperties.setProperty(DestinationDataProvider.JCO_USER, "fukuhara");
connectProperties.setProperty(DestinationDataProvider.JCO_PASSWD, "XXXX"); //password
connectProperties.setProperty(DestinationDataProvider.JCO_LANG, "en");
createDataFile(ABAP_AS, "jcoDestination", connectProperties);

//Create SAP Destination properties
static void createDataFile(String name, String suffix, Properties properties) {
File cfg = new File(name + "." + suffix);
if (!cfg.exists()) {
try {
FileOutputStream fos = new FileOutputStream(cfg, false);, "for tests only !");
} catch (Exception e) {
throw new RuntimeException("Unable to create the destination file " + cfg.getName(), e);

//Get Destination
JCoDestination destination = JCoDestinationManager.getDestination(ABAP_AS);

//Get metadata of function module "STFC_CONNECTION"
JCoFunction function = destination.getRepository().getFunction("STFC_CONNECTION");
if (function == null)
throw new RuntimeException("TFC_CONNECTION not found in SAP.");

//Set Import parameter of the function module
function.getImportParameterList().setValue("REQUTEXT", "Hello SAP");
try {

//Call Function
} catch (AbapException e) {

<%-- Get result of the function module--%>


This is the result of JSP screen. The screen displays ABAP system information.