Problem:
JCo to SAP gateway connection fails when you are connecting to SAP gateway using an external or public IP which is NATed to an internal IP.
Solution:
1.Need to add a parameter gw/alternative_hostnames and enter the external or public IP value to the default profile.
2.Use SAPGLOBALHOST name as ASHOST value
SAP Technical and Functional tips and tricks. ABAP,MM,SD,FICO,HR,PP,PM,PS,CRM,SCM,SEM,WM
Showing posts with label SAP JCo. Show all posts
Showing posts with label SAP JCo. Show all posts
Tuesday, September 6, 2016
Wednesday, August 27, 2014
SAP JCo - An example program to establish the connection
import java.io.File;
import java.io.FileOutputStream;
import java.util.Properties;
import com.sap.conn.jco.JCoDestination;
import com.sap.conn.jco.JCoDestinationManager;
import com.sap.conn.jco.JCoFunction;
import com.sap.conn.jco.ext.DestinationDataProvider;
public class BAPICallTest {
static String DESTINATION_NAME1 = "ABAP_AS_WITHOUT_POOL";
static String DESTINATION_NAME2 = "ABAP_AS_WITH_POOL";
static {
Properties connectProperties = new Properties();
connectProperties.setProperty(DestinationDataProvider.JCO_ASHOST, "host name");
connectProperties.setProperty(DestinationDataProvider.JCO_SYSNR, "system number");
connectProperties.setProperty(DestinationDataProvider.JCO_CLIENT, "Client");
connectProperties.setProperty(DestinationDataProvider.JCO_USER, "user name");
connectProperties.setProperty(DestinationDataProvider.JCO_PASSWD, "password");
connectProperties.setProperty(DestinationDataProvider.JCO_LANG, "en");
createDestinationDataFile(DESTINATION_NAME1, connectProperties);
connectProperties.setProperty(DestinationDataProvider.JCO_POOL_CAPACITY, "3");
connectProperties.setProperty(DestinationDataProvider.JCO_PEAK_LIMIT, "10");
createDestinationDataFile(DESTINATION_NAME2, connectProperties);
}
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 !");
fos.close();
} catch (Exception e) {
throw new RuntimeException("Unable to create thedestination files", e);
}
}
public static void main(String[] args) throws Exception {
JCoDestination destination1 = JCoDestinationManager.getDestination("DESTINATION_NAME1");
System.out.println(destination1);
System.out.println("Destination 1 Attributes:");
System.out.println(destination1.getAttributes());
JCoDestination destination2 = JCoDestinationManager.getDestination("DESTINATION_NAME2");
System.out.println(destination2);
System.out.println("Destination 2 Attributes:");
System.out.println(destination2.getAttributes());
JCoFunction function = destination2.getRepository().getFunction("STFC_CONNECTION");
function.execute(destination2);
}
}
import java.io.FileOutputStream;
import java.util.Properties;
import com.sap.conn.jco.JCoDestination;
import com.sap.conn.jco.JCoDestinationManager;
import com.sap.conn.jco.JCoFunction;
import com.sap.conn.jco.ext.DestinationDataProvider;
public class BAPICallTest {
static String DESTINATION_NAME1 = "ABAP_AS_WITHOUT_POOL";
static String DESTINATION_NAME2 = "ABAP_AS_WITH_POOL";
static {
Properties connectProperties = new Properties();
connectProperties.setProperty(DestinationDataProvider.JCO_ASHOST, "host name");
connectProperties.setProperty(DestinationDataProvider.JCO_SYSNR, "system number");
connectProperties.setProperty(DestinationDataProvider.JCO_CLIENT, "Client");
connectProperties.setProperty(DestinationDataProvider.JCO_USER, "user name");
connectProperties.setProperty(DestinationDataProvider.JCO_PASSWD, "password");
connectProperties.setProperty(DestinationDataProvider.JCO_LANG, "en");
createDestinationDataFile(DESTINATION_NAME1, connectProperties);
connectProperties.setProperty(DestinationDataProvider.JCO_POOL_CAPACITY, "3");
connectProperties.setProperty(DestinationDataProvider.JCO_PEAK_LIMIT, "10");
createDestinationDataFile(DESTINATION_NAME2, connectProperties);
}
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 !");
fos.close();
} catch (Exception e) {
throw new RuntimeException("Unable to create thedestination files", e);
}
}
public static void main(String[] args) throws Exception {
JCoDestination destination1 = JCoDestinationManager.getDestination("DESTINATION_NAME1");
System.out.println(destination1);
System.out.println("Destination 1 Attributes:");
System.out.println(destination1.getAttributes());
JCoDestination destination2 = JCoDestinationManager.getDestination("DESTINATION_NAME2");
System.out.println(destination2);
System.out.println("Destination 2 Attributes:");
System.out.println(destination2.getAttributes());
JCoFunction function = destination2.getRepository().getFunction("STFC_CONNECTION");
function.execute(destination2);
}
}
The above program gets attributes of SAP server. It uses direct connection and connection pool.
Labels:
JCO,
JCO Sample,
JCO Sample program,
SAP JCo,
SAP JCO connection,
STFC_CONNECTION
Subscribe to:
Posts (Atom)