SAP RFC from JSP via JCO
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
JSP 코드
Very simple program calling function module "STFC_CONNECTION".
<HTML>
<BODY>
<%@ page language="java" contentType="text/html; charset=Windows-31J"%>
<%@ page
import="java.io.File,
java.io.FileOutputStream,
java.util.Properties,
com.sap.conn.jco.JCoAttributes,
com.sap.conn.jco.AbapException,
com.sap.conn.jco.JCoDestination,
com.sap.conn.jco.JCoDestinationManager,
com.sap.conn.jco.JCoException,
com.sap.conn.jco.ext.DestinationDataProvider,
com.sap.conn.jco.JCoFunction"%>
<%!
// ABAP Application Server
static String ABAP_AS = "ABAP_AS_WITHOUT_POOL";
// 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);
properties.store(fos, "for tests only !");
fos.close();
} 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
function.execute(destination);
} catch (AbapException e) {
System.out.println(e.toString());
return;
}
%>
<%-- Get result of the function module--%>
<H3><%=function.getExportParameterList().getString("ECHOTEXT")%></H3>
<H3><%=function.getExportParameterList().getString("RESPTEXT")%></H3>
</BODY>
</HTML>
This is the result of JSP screen. The screen displays ABAP system information.
Reference
이 문제에 관하여(SAP RFC from JSP via JCO), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://qiita.com/FukuharaYohei/items/f46b0737f23733b8c94d
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
<HTML>
<BODY>
<%@ page language="java" contentType="text/html; charset=Windows-31J"%>
<%@ page
import="java.io.File,
java.io.FileOutputStream,
java.util.Properties,
com.sap.conn.jco.JCoAttributes,
com.sap.conn.jco.AbapException,
com.sap.conn.jco.JCoDestination,
com.sap.conn.jco.JCoDestinationManager,
com.sap.conn.jco.JCoException,
com.sap.conn.jco.ext.DestinationDataProvider,
com.sap.conn.jco.JCoFunction"%>
<%!
// ABAP Application Server
static String ABAP_AS = "ABAP_AS_WITHOUT_POOL";
// 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);
properties.store(fos, "for tests only !");
fos.close();
} 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
function.execute(destination);
} catch (AbapException e) {
System.out.println(e.toString());
return;
}
%>
<%-- Get result of the function module--%>
<H3><%=function.getExportParameterList().getString("ECHOTEXT")%></H3>
<H3><%=function.getExportParameterList().getString("RESPTEXT")%></H3>
</BODY>
</HTML>
Reference
이 문제에 관하여(SAP RFC from JSP via JCO), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/FukuharaYohei/items/f46b0737f23733b8c94d텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)