Screencast: Connecting Java CAPS 6 to SAP ECC
Introduction
This entry demonstrates how to connect from Java CAPS 6 to SAP ECC 5.0. Java CAPS 6 is the next release of Java CAPS. It will be based on NetBeans 6.1, Glassfish and Open ESB. Projects created with Java CAPS 5.1.x can be imported in Java CAPS 6 and they run on the same runtime as Open ESB. This powerful combination creates a very compelling development and integration platform.
Requirements
This entry assumes you have installed:
Java CAPS 6 with the SAP BAPI Adapter I have tested with Early Access 2 on Windows XP. This is a pre-release of Java CAPS 6, therefore you need to remember that your mileage may vary when Java CAPS is released.
SAP ECC 5.0. You need to collect the connection parameters for the SAP system you want to connect and have a valid SAP user account.
SAP JCO libraries. You need to download these files from http://service.sap.com. A valid login is required, you need to be either a SAP customer or a SAP partner.
What we are going to do
The goal is to execute from Java CAPS 6 a lookup inside SAP of the name for a vendor when we specify the vendor code as input. To implement this lookup we will use the BAPI/RFC Adapter to call an RFC function module defined in SAP. We will query directly the underlying vendor table in SAP, namely LFA1.
There are other implementations to do this, specifically:
using the higher level BAPIs, specifically BAPI_VENDOR_FIND and/or BAPI_VENDOR_GETDETAIL
using a CREMAS IDOC to get data asynchronously from SAP
The benefit of the RFC approach is that you can do the lookup synchronously from Java CAPS. Moreover, you can modify the call to the RFC function module to do the query differently, for example query the vendor code given the vendor name, in a single call. However, in a real project scenario you would need to consider the different implementations and choose the one which is the most appropriate to your case. From a technical perspective the RFC layer is also used for BAPIs and IDOCs. Therefore, this scenario using RFC provides a common technical ground with the other potential SAP communication mechanisms.
Installation specific to the BAPI Adapter
1/ With Java CAPS 6 EA2, if you are using a non US Windows system, you need to force the US locale. Modify the the file <JavaCAPS6>\netbeans\etc\netbeans.conf
and modify the line with netbeans_default_options so that it begins like:
netbeans_default_options="-J-Duser.region=US -J-Duser.language=en
2/ The BAPI Adapter will connect from Java CAPS to SAP at design time. This connectivity relies on the SAP JCO libraries. For example I have extracted the JCO libraries in a directory called « jco2.1 ». You need also to copy librfc32.dll into your windows\system32 directory.
Updated 11/03/2009: you can install the JCO libraries more easily using the script provided in the product and described hereYou need to launch NetBeans using the following command:
netbeans -cp:p <JavaCAPS6>\jco2.1\windows\sapidoc.jar -cp:p <JavaCAPS6>\jco2.1\windows\sapidocjco.jar -cp:p <JavaCAPS6>\jco2.1\windows\sapjco.jar
3/ The Application server needs also the JCO libraries at runtime. To do this you need to modify the file
<jcaps6>/glassfish/domains/domain1/config/domain.xml
and configure the classpath-prefix as shown below
<java-config classpath-prefix="<jcaps6>/jco2.1/sun/sapidoc.jar:<jcaps6>/jco2.1/sun/sapidocjco.jar:<jcaps6>/jco2.1/sun/sapjco.jar"
Creating and running the project
I have captured a screencast to demonstrate how to build and run the project. You can download the screencast here (unzip and launch the html file) or view it directly here
The Java code of the JCD is presented here:
package CAPSProject1;
public class Collaboration_1
{
public com.stc.codegen.logger.Logger logger;
public com.stc.codegen.alerter.Alerter alerter;
public com.stc.codegen.util.CollaborationContext collabContext;
public com.stc.codegen.util.TypeConverter typeConverter;
public void start( com.stc.schedulerotd.appconn.scheduler.FileTextMessage input, rFC_RFC_READ_TABLE.RFC_RFC_READ_TABLE RFC_RFC_READ_TABLE_1 )
throws Throwable
{
try {
RFC_RFC_READ_TABLE_1.getRFC_READ_TABLE().getImportParams().setQUERY_TABLE( "LFA1" );
RFC_RFC_READ_TABLE_1.getRFC_READ_TABLE().getFIELDS( 0 ).setFIELDNAME( "LIFNR" );
RFC_RFC_READ_TABLE_1.getRFC_READ_TABLE().getFIELDS( 1 ).setFIELDNAME( "NAME1" );
String sapQuery = "LIFNR = '0123456789'";
logger.info( "sapQuery=" + sapQuery );
RFC_RFC_READ_TABLE_1.getRFC_READ_TABLE().getOPTIONS( 0 ).setTEXT( sapQuery );
RFC_RFC_READ_TABLE_1.getRFC_READ_TABLE().execute();
logger.info( "*** countDATA=" + RFC_RFC_READ_TABLE_1.getRFC_READ_TABLE().countDATA() );
for (int i = 0; i < RFC_RFC_READ_TABLE_1.getRFC_READ_TABLE().countDATA(); i++) {
logger.info( "*** WA=" + RFC_RFC_READ_TABLE_1.getRFC_READ_TABLE().getDATA( i ).getWA() );
}
} catch ( Exception e ) {
logger.error( "", e );
}
}
}
The following screen capture presents the JCD in the JCD editor:

You must modify the vendor code, that is to say the sapQuery initialization. You need to lookup a code in your SAP system, either directly in the LFA1 table using SAP transaction SE11 or using SAP transaction FK01 to identify a vendor. At runtime the JCD will be triggered once just after deployment. If all SAP parameters are correct, you will see the vendor name in the log file. You can download the Java CAPS 6 project here
What's next
We barely scratched the surface of Java CAPS 6. From an SAP perspective we can build from this simple scenario and use higher level BAPIs or IDOCs. We could also simply expose the BAPI adapter to the Open ESB JBI bus and leverage features like BPEL 2.0 and Event processing. These might be the subject of another blog entry.