Accessing SAP Objects with VisualAge for Java

By Dale Nilsson, IBM

here is a lot going on with Java and VisualAge for Java. NetScape Navigator and Microsoft Internet Explorer now have some but differing support for the Version 1.1 JDK and JavaBeans. Database vendors are shipping their JDBC support including IBM's new DB2 Universal Database (UDB), Lotus BeanMachine is now up to the JDK 1.1 and Lotus Notes V4.6 includes support for Java that is extensive. Although each product has its quirks and there are still many inconsistencies, the breadth and depth of software that is moving to Java and supporting the V1.1 JDK is literally awesome.

Another project in development is a joint effort with SAP and IBM to build a VisualAge for Java SAP Access Builder. SAP, based in Waldorf Germany, was started a number of years ago by some ex-IBMers and has grown into a huge application software and services company. It is a multi-billion dollar company with consistent double digit annual growth. SAP has many business partners and there are a number of companies that supply additional software can be used with the SAP System.

The SAP system has evolved over time and the current system is called the R/3 System. This is SAP's flagship product which is rich in functionality and it includes over 1,000 predefined processes to help developers create business applications. SAP has had broad success with various companies in the manufacturing, retail and service sectors using the R/3 System for business applications. SAP is pursuing a clear strategy to continue to improve the SAP R/3 System keep its keeping it a leading product for business applications. It is collaborating with customers and partners to spur on the evolutionary development of R/3, tuning the system to absorb technological innovations, and driving system componentization.

SAP's strategy is to evolve the R/3 System into a family of distributable software components known as the Business Framework architecture. The foundation for the open Business Framework architecture are the Business Application Programming Interfaces (BAPIs pronounced 'bappies', or 'boppies' in German) which allow access to the R/3 System. The BAPIs provide an open Java interface which allow developers to write applications and applets that interface freely with the integrated R/3 System. SAP has traditionally offered turnkey solutions for different sectors of industry. These specially tailored solutions meet most of the industry-specific requirements not covered by standard R/3 software. integrated into customers' existing software environment. BAPIs play a vital role in application development, because they allow individual SAP R/3 components to be enhanced independently of the core R/3 components. Figure 1 shows the api layers used to access the R/3 System.

All these layers are needed to access the SAP Objects. This is possible with the JNI (Java Native Interface) support which is new in the JDK V1.1. The SAP R/3 Access use the JNI to get to the Business Object Repository. On the Tool side, BOR Access classes are generated and the SAP Access Builder allows you to view the BOR object and select objects for generation. I'll take you through these steps in a little greater detail.

The SAP Access Builder is somewhat similar to the Data Access Builder in the Enterprise version of VisualAge for Java because it maps SAP Business Objects from an R/3 Repository and it generates invisible or business logic JavaBeans. In order to do this, you must first have access to an SAP R/3 system that has business objects. Fortunately the R/3 System includes a number sample objects that are there by default. These JavaBeans can be imported into VisualAge for Java and used to build applets and applications.

In order to do the mapping, there is a preparation step for SAP Access Builder browser. First the Access Builder creates serialized beans for the browser by reading the SAP Business Object Repository (BOR). Depending on the number and size of the objects in the Repository, this process will take quite a while. You can then start the BOR browser which displays a tree view of all the objects in the repository. This give you an easy way to browse the repository for the objects that you want to map. From this list of objects you can select objects for generation.

freeware windows mobile As an example, I'll take you through the process to create a some JavaBeans that are generated from the R/3 System. One of the sample objects in the repository is the Company object that can be accessed through a CompanyCode. Figure 2 illustrates the steps used to generate SAP objects using the BAPI.

Let's follow these mapping steps to understand how it works: 1) First select the CompanyCode SAP object from the BOR Browser to generate 2) The Builder calls the BOR Access Classes to get the CompanyCode TypeInfo 3) This calls the Repository to get the CompanyCode TypeInfo 4) Which then goes to the R/3 System for the CompanyCode 5) Now with the CompanyCode from the R/3 System, the Access Builder can generate the JavaBean for the CompanyCode.

In order to use the generated beans, you must import them into VisualAge for Java. Once they are loaded in the Workspace you can use these JavaBeans to make applets and applications. Remember that when Java classes are loaded into the Workspace, the IDE will compile all the classes. If you are mapping quite a few classes, then be patient while they load.

When accessing an R/3 System the user must logon, so a GUI JavaBean which resembled the standard SAP logon screen is provided. The Logon bean has all the logon options and it is easy to use. It has 2 panels on a CardLayout with the appropriate TextFields to gather the necessary logon information. The Logon bean was built using VisualAge for Java so it can be easily used in VisualAge for Java using the Visual Composition Builder. Figure 3 shows the first page of the LogonView. As stated earlier, you will need a User id and Password for the SAP System and it gets entered on this page. The Language field can accept the default language, for example, English.

There is additional information needed for the Logon. This information goes on the second page of the CardLayout. You will need to specify the System Number, RfcMode, and Host Name. The SAP R/3 System administrator will be able to give you these. The second page of the Logon is shown in Figure 4. At runtime, when the information is entered and you select the Logon button. If the logon is successful it will be displayed in the info area.

There is a sample Java application that uses the generated Beans in Figure 5. This sample was built in the Visual Composition Editor in VisualAge for Java and it adds a Sales Item to the R/3 system. In this sample you can see the LogonView and its visual connections. The R/3 Logon Button just shows the LogonView so the user can logon. When the logon is successful it will emit a LogonEvent, there is also a LogoffEvent. You can use the LogonEvent to enable the beans that access the R/3 system. This sample uses an AddItem bean, which adds Sales Orders to the sample R/3 system.

You can test you SAP Java applications in the VisualAge for Java IDE, but remember that the proximity of the SAP R/3 Server has a big influence on performance. You will also see significant performance improvements when you run the Java application outside the VisualAge IDE. This is due to a few reasons. First, the VisualAge IDE has its own JVM (Java Virtual Machine) that is not fully optimized. The JVM also needs to do development time things like trapping exceptions in the Debugger. Additionally, the repository based IDE used a lot of memory, so running Java programs in the IDE are not as fast.

I spent a few weeks working with the team at the IBM Lab in Ehningen Germany preparing for a workshop at the SAP Technical conference in Atlanta Georgia. I have to give some thanks to Christopher Puerckhauer, Michael Friess, Rainer Vetter and Gerhard Pfau who showed me their work on the SAP Access Builder and helped demystify the SAP R/3 System for me. There are a number of other developers working on the project, but I worked mainly with these guys and they are good OO programmers.

The SAP Access Builder is in its first beta and you can get more information on how to get the beta at the alphaworks website at: http://www.alphaworks.ibm.com. From this location you can download the beta code and Java beans which is 6mb zipped and a sample Java program.

The developers are always interested in users comments and anything that can improve the usability or functions in the builder. Since the SAP Access Builder generates pure Java code, you can subclass them to extend their function, or additional methods to the generated classes.

You can also access the beta via: http://mfriess2.ehningen.de.ibm.com ftp://mfriess2.ehningen.de.ibm.com (use anonymous login).

The SAP Access Builder is still in development and it is under constant improvement. You can get more information on the R/3 BAPIs by accessing the SAP Open BAPI Network at SAP wesite on www.sap.com.

Java, VisualAge, SAP, and Netscape Navigator are trademarks of the respective companies that own them.

Enjoy the article? Subscribe to Eye on Objects!

Dale Nilsson is a Senior Software Consultant with IBM VisualAge. He has been programming software since 1976 using a number of different programming languages using PCs, minis, and mainframes. He has experience working with customers and vendors throughout the United States, Europe, Asia, and South America. Dale currently works with customers providing software consulting and education, technical presentations, and application design using Visualage for C++ and VisualAge for Java. He is also an Advisor and Contributor to the VisualAge Certification program.

Home Page