This is the post to explain the way of achieve the connection between non SAP Web application interacting with SAP backend RFC's through Jco3 connector.
Mandatory Files:
* sapjco3.jar (place in lib folder)
* sapjco3.dll(required only windows based machine ,need to place under "C:\Windows\System32" folder.)
Required to download it from SAP market place with valid credentials,consider the version 32/64 bits depends on your work environment)
Steps to connect SAP Backend:
1. Create a Stand alone/web application using any development tool.
2. Include jar and dll files in above specified folder
3. Create a connection class to connect backend with valid credentials
4. Create a service or consumer class with RFC call code to utilise the connection
5. Close the connection
Make sure you have access and no firewall blocks for the SAP backend connection.
Example Connection Code:
sapConnect.java
import com.sap.conn.jco.JCoDestination;
import com.sap.conn.jco.JCoDestinationManager;
import com.sap.conn.jco.JCoException;
import com.sap.conn.jco.JCoFunction;
import com.sap.conn.jco.JCoTable;
import java.io.File;
import java.io.FileOutputStream;
import java.util.Properties;
import com.sap.conn.jco.ext.DestinationDataProvider;
import java.io.IOException;
import java.util.List;
public class sapConnect {
static String DESTINATION_NAME1 = "ABAP_AS_WITHOUT_POOL";
static {
Properties connectProperties = new Properties();
connectProperties.setProperty(DestinationDataProvider.JCO_ASHOST, "198.10.01.108");
connectProperties.setProperty(DestinationDataProvider.JCO_SYSNR, "03");
connectProperties.setProperty(DestinationDataProvider.JCO_CLIENT, "500");
connectProperties.setProperty(DestinationDataProvider.JCO_USER, "solmanadmin");
connectProperties.setProperty(DestinationDataProvider.JCO_PASSWD, "solmanpassword");
connectProperties.setProperty(DestinationDataProvider.JCO_LANG, "en");
createDestinationDataFile(DESTINATION_NAME1, connectProperties);
connectProperties.setProperty(DestinationDataProvider.JCO_POOL_CAPACITY, "10");
connectProperties.setProperty(DestinationDataProvider.JCO_PEAK_LIMIT, "100");
}
static void createDestinationDataFile(String destinationName, Properties connectProperties) {
File destCfg = new File(destinationName + ".jcoDestination");
try {
FileOutputStream fos = new FileOutputStream(destCfg, false);
{
connectProperties.store(fos, "for tests only !");
}
} catch (IOException e) {
throw new RuntimeException("Unable to create the destination files", e);
}
}
public static void jcovalue(String ibase) throws JCoException {
JCoTable tables = null;
JCoDestination destination = CoDestinationManager.getDestination(DESTINATION_NAME1);
JCoFunction jf = destination.getRepository().getFunction("ZSOLMAN_STATUS_COUNT");
jf.getImportParameterList().setValue("PNO", ibase);
jf.execute(destination);
tables = jf.getTableParameterList().getTable("RESULT");
System.out.println(tables.toString());
}
public static void main(String[] args) throws JCoException {
jcovalue("349");
}
}
Mandatory Files:
* sapjco3.jar (place in lib folder)
* sapjco3.dll(required only windows based machine ,need to place under "C:\Windows\System32" folder.)
Required to download it from SAP market place with valid credentials,consider the version 32/64 bits depends on your work environment)
Steps to connect SAP Backend:
1. Create a Stand alone/web application using any development tool.
2. Include jar and dll files in above specified folder
3. Create a connection class to connect backend with valid credentials
4. Create a service or consumer class with RFC call code to utilise the connection
5. Close the connection
Make sure you have access and no firewall blocks for the SAP backend connection.
Example Connection Code:
sapConnect.java
import com.sap.conn.jco.JCoDestination;
import com.sap.conn.jco.JCoDestinationManager;
import com.sap.conn.jco.JCoException;
import com.sap.conn.jco.JCoFunction;
import com.sap.conn.jco.JCoTable;
import java.io.File;
import java.io.FileOutputStream;
import java.util.Properties;
import com.sap.conn.jco.ext.DestinationDataProvider;
import java.io.IOException;
import java.util.List;
public class sapConnect {
static String DESTINATION_NAME1 = "ABAP_AS_WITHOUT_POOL";
static {
Properties connectProperties = new Properties();
connectProperties.setProperty(DestinationDataProvider.JCO_ASHOST, "198.10.01.108");
connectProperties.setProperty(DestinationDataProvider.JCO_SYSNR, "03");
connectProperties.setProperty(DestinationDataProvider.JCO_CLIENT, "500");
connectProperties.setProperty(DestinationDataProvider.JCO_USER, "solmanadmin");
connectProperties.setProperty(DestinationDataProvider.JCO_PASSWD, "solmanpassword");
connectProperties.setProperty(DestinationDataProvider.JCO_LANG, "en");
createDestinationDataFile(DESTINATION_NAME1, connectProperties);
connectProperties.setProperty(DestinationDataProvider.JCO_POOL_CAPACITY, "10");
connectProperties.setProperty(DestinationDataProvider.JCO_PEAK_LIMIT, "100");
}
static void createDestinationDataFile(String destinationName, Properties connectProperties) {
File destCfg = new File(destinationName + ".jcoDestination");
try {
FileOutputStream fos = new FileOutputStream(destCfg, false);
{
connectProperties.store(fos, "for tests only !");
}
} catch (IOException e) {
throw new RuntimeException("Unable to create the destination files", e);
}
}
public static void jcovalue(String ibase) throws JCoException {
JCoTable tables = null;
JCoDestination destination = CoDestinationManager.getDestination(DESTINATION_NAME1);
JCoFunction jf = destination.getRepository().getFunction("ZSOLMAN_STATUS_COUNT");
jf.getImportParameterList().setValue("PNO", ibase);
jf.execute(destination);
tables = jf.getTableParameterList().getTable("RESULT");
System.out.println(tables.toString());
}
public static void main(String[] args) throws JCoException {
jcovalue("349");
}
}
Thanks for sharing Information.
ReplyDeleteApplication Management Services