You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
if you do not change the filename, you will see the following error message:
if not include sapjco3.jar
JCo initialization failed with java.lang.ExceptionInInitializerError:
Illegal JCo archive "sapjco3-3.0.14.jar".
It is not allowed to rename or repackage the original archive "sapjco3.jar".
if not include libsapjco3.so (linux), libsapjco3.jnilib (mac), sapjco3.dll (windows)
java.lang.UnsatisfiedLinkError: no sapjco3 in java.library.path:
example
basic
importjava.io.IOException;
importjava.util.List;
importjava.util.Map;
importcom.sap.conn.jco.JCoException;
importcom.sap.conn.jco.JCoTable;
importme.saro.sap.jco.SapFunction;
importme.saro.sap.jco.SapFunctionResult;
importme.saro.sap.jco.SapManager;
importme.saro.sap.jco.SapManagerBuilderOption;
publicclassSapManagerNormalTest {
// example connectpublicSapManagergetSapManager() throwsJCoException, IOException {
returnSapManager
.builder()
.set(SapManagerBuilderOption.ASHOST, "host") // AS host
.set(SapManagerBuilderOption.MSSERV, "9999") // MS port [AS, MS is MSSERV, GW is JCO_GWSERV]
.set(SapManagerBuilderOption.SYSNR, "01") // system number
.set(SapManagerBuilderOption.GROUP, "Group Name") // group
.set(SapManagerBuilderOption.LANG, "KO") // language code
.set(SapManagerBuilderOption.CLIENT, "100") // client number
.set(SapManagerBuilderOption.USER, "user") // user
.set(SapManagerBuilderOption.PASSWD, "password") // password
.build();
}
// example basicpublicvoidbasic() throwsJCoException, IOException {
// connectSapManagersap = getSapManager();
// load sap functionSapFunctionfunction = sap.getFunction("SAP_RFC_FUNC_NAME");
// set parametersfunction.getImportParameterList().setValue("param1", "text");
function.getImportParameterList().setValue("param2", 1);
function.getImportParameterList().setValue("param3", true);
// set table parameters [example table parameter name is param4]JCoTablerequestTableParameter = function.getImportTableParameter("param4");
List.of("value1", "value2", "value3").forEach(e -> {
requestTableParameter.appendRow();
requestTableParameter.setValue("field1", "text");
requestTableParameter.setValue("field2", e);
requestTableParameter.setValue("field3", false);
});
// executeSapFunctionResultresult = function.execute();
// get result parametersresult.getExportParameterList().getString("param1");
result.getExportParameterList().getInt("param2");
result.getExportParameterList().getDate("param3");
// get result tablesList<Map<String, Object>> resultTable = result.getTable("SAP_RESULT_TABLE_NAME");
// print result tableSystem.out.println("print SAP_RESULT_TABLE_NAME");
resultTable.forEach(row -> {
System.out.println("=============================================");
row.forEach( (key, value) -> System.out.println(key + " : " + value) );
});
}
}
multiple thread
importjava.io.IOException;
importjava.util.List;
importcom.sap.conn.jco.JCoException;
importme.saro.sap.jco.SapFunctionResult;
importme.saro.sap.jco.SapManager;
importme.saro.sap.jco.SapManagerBuilderOption;
publicclassSapManagerMultipleThreadTest {
// example connectpublicSapManagergetSapManager() throwsJCoException, IOException {
returnSapManager
.builder()
.set(SapManagerBuilderOption.ASHOST, "host") // AS host
.set(SapManagerBuilderOption.MSSERV, "9999") // MS port [AS, MS is MSSERV, GW is JCO_GWSERV]
.set(SapManagerBuilderOption.SYSNR, "01") // system number
.set(SapManagerBuilderOption.GROUP, "Group Name") // group
.set(SapManagerBuilderOption.LANG, "KO") // language code
.set(SapManagerBuilderOption.CLIENT, "100") // client number
.set(SapManagerBuilderOption.USER, "user") // user
.set(SapManagerBuilderOption.PASSWD, "password") // password
.build();
}
// example multiple threadpublicvoidmultipleThread() throwsJCoException, IOException {
// example user no -> nameList<Integer> userNoList = List.of(1, 2, 3, 4);
// connectSapManagersap = getSapManager();
// use 10 thread// executeAllThreads method is blocking until complete all a tasksList<String> userNameList = sap.getFunctionTemplate("USER_TABLE").executeAllThreads(10, userNoList, (function, userNo) -> {
function.getImportParameterList().setValue("user_no", userNo);
SapFunctionResultresult = function.execute();
Stringname = result.getExportParameterList().getString("USER_NAME");
returnname;
});
// printSystem.out.println("user names");
System.out.println(userNameList);
}
}