An easier way to connect components to SAP server functions: Part 1. Generate a J2C bean for a SAP resource adapter using improved Rational Application Developer 8.0 Java tools

In this world of service-driven business applications, it is very important that various components of a complex system can easily access enterprise information system (EIS) functionality. Improved Java EE connector tools in IBM® Rational® Application Developer 8.0 make it easier for you to generate a J2C bean that provides better access. This step-by-step guide demonstrates a quick way to create a simple JavaServer Page that uses the J2C bean to access the SAP server functions.

IBM® Rational® Application Developer Version 8.0 has improved the user experience for many application development tools, including the Java EE Connector architecture (JCA or J2C) suite of tools for Java Platform, Enterprise Edition (Java EE) technology. This article highlights some of these improvements while demonstrating how, as a Jave EE developer, you can use the Java EE connector tools to generate a J2C bean that uses functions provided by a backend SAP server (enterprise information management system).

In the current world of service-driven business applications, it is very important that enterprise information system (EIS) functionality is easily accessible by various components of the complex business ecosystem. This article shows you how to implement this access by creating a simple JavaServer Page (JSP) that accesses the SAP functionality through a J2C bean and J2C databinding bean.

System requirements

To follow this article in a hands-on fashion, you need to prepare:

  1. Install Rational Application Developer V8.0 with Java EE Connector tools and IBM® WebSphere® Application Server V7.0 on the developer's machine.
  2. Get these files from your SAP server administrator:
    • sapjco3.jar
    • sapjco3.dll
  3. Obtain all SAP server connection information from your SAP server administrator.
  4. Copy the sapjco3.jar file to WAS_Install_DIR\lib, where the part in italics is specific to your installation. For example: C:\Rad80\SDP\runtime\base_v7\lib
  5. Copy the CWYAP_SAPAdapterExt.jar file (which is under the ext folder of the SAP Adapter package), which is under RAD_Install\SDP\ResourceAdapter\SAP_7.0.0.3\ext, to WAS_Install_DIR\lib
  6. Copy the sapjco3.dll file to WAS_Install_DIR\bin.

Scenario description

The SAP example demonstrates how to use the WebSphere SAP Resource Adapter to create company information on the SAP system. You will create data on the SAP server using a J2C bean in a Java EE project, and then follow these steps to implement this scenario:

  1. Launch the J2C Bean wizard.
  2. Configure connector dependencies.
  3. Set the connection properties for SAP server.
  4. Select business objects and services for BAPI outbound processing.
  5. Configure the Java data bindings for the BAPI interface.
  6. Set the deployment properties and generating artifacts.

Launch the J2C Bean wizard

  1. Launch Rational Application Developer v8.0, and select File > New > Other.
  2. In the New page, select J2C > J2C Java Bean, as shown in Figure 1.
Figure 1. J2C Bean wizard launch
New page with list of wizards available
  1. On the Resource Adapters Select page, select SAP > IBM WebSphere Adapter for SAP Software (IBM 7.0.0.3), as Figure 2 shows, and then click Next.
Figure 2. Select the SAP 7.0.0.3 resource adapter
Resource Adapter Selection page that lists adapters

On the first page of the wizard, there is a list of adapters that can be used to generate a J2C bean. Rational Application Developer V8.0 includes different types of resource adapters, such as IBM® CICS®, IBM® IMS™, JD Edwards EnterpriseOne, Oracle, PeopleSoft, SAP, and Siebel Systems adapters. For this article, use the IBM WebSphere Adapter for SAP Software (IBM:7.0.0.3) so you can communicate with the SAP system from Rational Application Developer.

  1. On the Connector Import page (Figure 3), select the target server to use for the connecter project. In this scenario, choose WebSphere Application Server v7.0, and then click Next.
Figure 3. Select the runtime target server
Fields to specify connector project and target server

Configure connector dependencies

  1. On the Connector Settings page, specify the location of the library files that need to be available for the wizard (the first file is sapjco3.jar, and the second system library file is either sapjco3.dll or libsapjco3.so, depending on your configuration), and then click Next.
Figure 4. Configure connector dependencies
Connector Settings pages shows the files selected

Those third-party files will be added to the class path of the connector project after importing.

Note:
Obtain the sapjco3.jar file and the associated files for your operating system from your SAP administrator or from the SAP website. Obtain the CWYAP_SAPAdapterExt.jar file from the adapter package. The files are listed in Table 1.

Table 1. External software dependency files required by SAP Software
Operating systemFiles to copy
Microsoft Windows and IBM® i5/OS®sapjco.jar and any *.dll files that come with the SAP JCo download from the SAP website
UNIX (including UNIX System Services on IBM® z/OS® ) sapjco.jar and any .so files that come with the SAP JCo download from the SAP website
  1. SAP JCo3 requires the msvcp71.dll and msvcr71.dll files in a Windows environment. These .dll files are in the system32 directory on most systems. Copy them to your Windows environment if it does not have them already.
  2. In the Adapter Style page, there are two adapter styles. Select Outbound.
Figure 5. Select an adapter style
This page provides two adapter styles, Inbound, and Outbound

JCA1.5 supports inbound communication, which provides system-level contracts, including transaction inflow and message inflow to support bidirectional communications between J2EE applications and the EIS system.

For outbound communication, a client application sends a request to the adapter, which converts the request into a function call. The EIS system processes the request and sends the results back to the adapter. The adapter sends the results in a response message to the calling application.


Set up connection properties for the SAP server

  1. In the Configure Settings for Discovery Agent page (Figure 6), enter the SAP server information, and then select BAPI from the SAP interface name list, and click Next.
Figure 6. Configure SAP server connection properties
Entries show which SAP interface will be accessed

The SAP interfaces enable business process integration and asynchronous data communication between two or more SAP systems or between SAP and external systems. The following interfaces exist for SAP software:

  • BAPI interfaces
  • BAPI work unit interface
  • BAPI result set interface
  • ALE interface
  • ALE pass-through IDOC interface
  • Query interface
  • Advanced event processing interface

The SAP adapter supports outbound processing and inbound processing for simple BAPIs, which perform a single operation, such as creating new customers or retrieving a list of customers. The adapter supports simple BAPI calls by representing each with a single business object schema.

The information will be used to connect to the underlying EIS system using the chosen J2C resource adapter. This information is backend system-specific, and the page is generated dynamically, based on the connection requirements of different backend systems.

The SAP interfaces enable business process integration and asynchronous data communication between two or more SAP systems or between SAP and external systems.

The following interfaces are available for SAP software:

  • BAPI interfaces
  • BAPI work unit interface
  • BAPI result set interface
  • ALE interface
  • ALE pass-through IDOC interface
  • Query interface
  • Advanced event processing interface

Select business objects and services for BAPI outbound processing

  1. In the Object Discovery and Selection page, click the RFC object in the "Objects discovered by query" pane on the left, as Figure 7 shows (right pane shows "Objects to be imported").
  2. To enable the "Create or edit filter" option, click the icon with three forward arrows:
Figure 7. Configure the imported object
RFC and filter icon selected
  1. From the Filter Properties window (see Figure 8), specify information about the BAPI or BAPIs that you want to discover:
    1. From the "Object attribute to use for discovery" list, select Discover objects by name or Discover objects by description.
    2. In the "Find objects with this pattern" field, type a search string that represents the BAPI that you want to call (for example, BAPI_CUSTOMER_*).

      Tip:
      This is the name of the BAPI in SAP plus an asterisk as a wild card character to indicate that you want a list of all SAP application components that start with the phrase BAPI_CUSTOMER.
    3. For the "Maximum number of objects to retrieve" field, indicate the number of functions that you want returned by changing the default value in or by accepting the default value (for this example: 25).
    4. Click OK.
Figure 8. Enter filter properties for "RFC"
Dialog window to set filter properties
  1. From the "Object Discovery and Selection" window, Figure 7, still in the New J2C Bean wizard, in the "Objects discovered by query" list in the left pane (Figure 9), expand the RFC tree, select BAPI_ CUSTOMER _CREATEFROMDATA1, and click the button with the arrow pointing to the adjacent pane to add them to "Objects to be imported" pane on the right.

Tip:
The filtered objects lists displays only the first 25 objects. Use the filter icon to change the default filter setting to see more.

Figure 9. Add an object to import
L pane: objects from query, R: objects to import
  1. In the Configuration Properties window, follow these steps to add each BAPI to the list of business objects to be imported:
    1. (Optional) Select the check box for Use SAP field names to generate attribute names. If you want to generate business object attribute names using the original SAP field name casing, check the Use original casing of SAP field names to generate business object attribute names check box. By default (when the first check box is not selected), field descriptions are used to generate properties.
    2. If the BAPI has optional parameters associated with it (see Figure 10), expand Optional parameters, and select the type of parameters (import or export) that you want to work with. By default, the J2C Bean wizard generates all the parameters required for the selected BAPI, so select this check box and then clear the check boxes for any parameters that you do not want to include in your business object. For example, if you are adding the ChangeFromData BAPI, you have the option of adding these parameters:
      • PI_DIVISION
      • PI_DISTR_CHAN

See the SAP documentation for a list and description of the optional parameters.

  1. Click OK to add the BAPI to the list of business objects to be imported.

Tip:
If you want to remove an object from the list, select the object name and click the left arrow.

Figure 10. Configure parameter for "BAPI_CUSOMTER_CREATEFROMDATA1"
Optional parameters: import, export
  1. Now, on the Object Discovery and Selection page, you'll see that the selected object has been added to the "Objects to be imported" list. Click Next.
Figure 11. Imported object was added
Selected object now in Objects to imported pane

Configure the Java data bindings for the BAPI interface

  1. In Configure Composite Properties page (Figure 12), enable the check box for Generate BAPI business objects within a wrapper to generate top-level business objects that contain a child business object for each BAPI selected. You can configure a maximum number of four BAPIs.

Note:
The composite properties are also including "Ignore errors in BAPI return object" and "Wait until commit all to SAP database in completed and returned."

Figure 12. Configure Composite Properties page in New J2C Bean wizard
dialog window

For this example, you will work with a single BAPI.

  1. Click the Add button, select an operation from the list in the pop-up window shown in Figure 13 (select Create, for this example), and then click OK.
Figure 13. Add Value window options
Four options: Create, Delete, Retrieve, Update
  1. In the "Business object name for service operations:" field (Figure 14), enter BapiDemo.
  2. Then click Next.
Figure 14. The selected composite properties
BapiDemo entered, Next button selected

Set up deployment properties and generating artifacts

The Java Bean Creation and Deployment Configuration page (Figure 15) shows the J2C bean properties, including project name, package name, and bean name.

  1. You need to specify the project and package for code generation. Also, when you enter the Interface name, the Implementation name will automatically default to Interface name with an Impl suffix. In this sample, generate all artifacts in a Java project.

When you are finished, the information should look like what Figure 15 shows for these fields:

  • Project name: SAPBAPISample selected from the Browse drop-down menu
  • Package name: sample.sap selected from the Browse drop-down menu
  • Interface name: Customer
  • Implementation name: CustomerImpl (automatically filled in)
  1. There are two Connection options on this page. To simplify this example, we'll use the Non-managed Connection, so uncheck Managed Connection.
Figure 15. J2C Bean Creation and Deployment Configuration page
Dialog window with properties entered

Note:
There are three ways that this connection information can be specified:

  • Providing managed connection information
  • Providing non-managed connection information
  • Providing a combination of both
Managed connection
The application server manages the lifecycle of the connection (3-tier model). A managed connection is specified by the Java Naming and Directory Interface (JNDI) name of the managed connection factory defined on the application server. The managed connection factory is EIS adapter-specific and contains all of the required connection information. Managed connection implies that the resource adapter is installed directly on the server and, therefore, the JNDI name of the managed connection factory is visible to all EAR (enterprise application archive) files installed on the application server.
 
Non-managed connection
A two-tier model in which the application communicates directly to the EIS and manages all the connections. Therefore, all of the connection information in this setup is encapsulated within the application. For a J2C bean, this means that all of the connection information is specified with doclet tags in the generated J2C bean.
 
Combination of both
The client will first try to fetch a managed connection factory from the server using the provided JNDI name. If this is not successful, it will use information defined for the non-managed case.
 

There is a check box labeled Click to launch J2C deployment wizard, which allows you to go to the J2C deployment wizard directly. You can also invoke the wizard by selecting New > Other > J2C > Web Page and either Web Service or EJB from J2C bean.

  1. For this sample, enable the check box to launch the J2C deployment wizard directly, and then click Finish to generate all artifacts in the SAPBAPITest Java project.

The page will then look like Figure 16.

Figure 16. Configure J2C bean properties
All required entries completed

In this page, the choice to use non-managed connection and SAP server connection properties will be populated as you selected previously.

Your J2C bean artifacts are now generated.


Preview of Part 2

Part 2 of this two-part article (click "More in this series") demonstrates how to generate and test a J2C bean for a SAP resource adapter outbound scenario, using Java EE connector tools in Rational Application Developer V8.0. You will then deploy the Java bean to a simple JSP and run that page on WebSphere Application Server V7.0.

Resources

Learn

Get products and technologies

Discuss

Comments

developerWorks: Sign in

Required fields are indicated with an asterisk (*).


Need an IBM ID?
Forgot your IBM ID?


Forgot your password?
Change your password

By clicking Submit, you agree to the developerWorks terms of use.

 


The first time you sign into developerWorks, a profile is created for you. Select information in your profile (name, country/region, and company) is displayed to the public and will accompany any content you post. You may update your IBM account at any time.

All information submitted is secure.

Choose your display name



The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerWorks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

Required fields are indicated with an asterisk (*).

(Must be between 3 – 31 characters.)

By clicking Submit, you agree to the developerWorks terms of use.

 


All information submitted is secure.

Dig deeper into Rational software on developerWorks


static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=Rational, DevOps
ArticleID=751986
ArticleTitle=An easier way to connect components to SAP server functions: Part 1. Generate a J2C bean for a SAP resource adapter using improved Rational Application Developer 8.0 Java tools
publish-date=08162011