18.3    SAP Composite Application Framework

SAP CAF facilitates the modeling of business objects and the building and running of composite services. This section won’t detail all there is to know about SAP CAF. Instead, it will briefly focus on its use and highlight some of its features. SAP CAF offers the following capabilities:

Example

To illustrate the use of SAP CAF in a simple manner, assume that you want to quickly put a composite application in place to manage the details of your organization’s employees. With SAP CAF, you can very quickly model and design an employee business object and its attributes. SAP CAF then automatically creates a database table to store the employees’ details and also makes different services available to enable the business objects’ data to be accessed. This type of services is known as entity services because it provides access to the business object or entity. These services can also be converted into web services with the click of a button.

The next section will show you how you can perform the following tasks:

18.3.1    Design Time Aspects

SAP NetWeaver Developer Studio provides a Composite Application perspective from which you can model the different required business objects. We’ll go over the main tasks in the following subsections.

Before modeling a business object, you’ll need a DC to hold your development objects. The DC will need to be of the composite application type. It’s important to note that as you create a DC of the composite application type, SAP NetWeaver Developer Studio automatically creates five other DCs to support SAP CAF developments: a dictionary, Enterprise Java Bean (EJB) module, metadata, and enterprise and user management engine (UME) permissions DCs. Together, these different DCs provide support for database, persistence, application logic, and service layers for the SAP CAF application. Figure 18.35 shows an example SAP CAF project called caf_demo, which contains the five different DCs that have automatically been created.

DCs Created as Part of an SAP CAF Development

Figure 18.35    DCs Created as Part of an SAP CAF Development

Furthermore, a caf.core project is also created and contains important data types and services that are delivered by SAP and can be incorporated into your composite application. After DCs have been created, you can switch to the Composite Application perspective to create different business objects.

Business Objects

From the Composite Application perspective of SAP NetWeaver Developer Studio, you can create and model a business object, which represents a business entity that will play a role in your composite service. The framework automatically creates database (dictionary) tables that match the structure of the modeled business object.

Note

Business Object Modeler is an editor available in SAP NetWeaver Developer Studio. From this tool, you can define different aspects of a business object. These aspects include the fields and attributes that define it. You can also define relationships to other business objects. These relationships work exactly like defining foreign keys between tables in a rational database.

A business object can be created from SAP NetWeaver Developer Studio by following these steps:

  1. From the Composite Application perspective of SAP NetWeaver Developer Studio, expand your project, and from the context menu of the Business Objects node, select NewBusiness Object.
  2. Provide a name for your business object. The newly created business object is now available under your project tree.
  3. Double-click on the newly created business object to open the Business Object Modeler. On the new screen that opens, select the Structure tab (see Figure 18.36).
    Default Structure of a Newly Created Business Object and Its Fields

    Figure 18.36    Default Structure of a Newly Created Business Object and Its Fields

  4. Click on the Edit Main Structure button to edit the fields of the business object.
  5. On the subsequent screen, you can add multiple fields to your business object. Assuming you’re modeling an employee business object, you’ll want to add fields for first name, surname, and so on. As Figure 18.37 indicates, you’ll need to select the data types of the field from the primitive package of the caf.core project (on the left of the screen).
    Populating the Business Object Fields Using the Structure Editor

    Figure 18.37    Populating the Business Object Fields Using the Structure Editor

  6. Select the arrow in the middle of the screen to move data types from left to right. Looking at the Figure 18.37, you’ll need to use the left-pointing arrow.
  7. The newly created attribute comes with the name newAttribute1. Rename it to a more meaningful name.

You can repeat the preceding steps for as many business objects as you need to fulfill your business requirement.

It’s important to be aware that the fields specified for a business object and relationships defined between the different business objects will serve to generate database tables and foreign keys.

Entity Services

An entity service exposes the functionality of the business object. A list of entity services are automatically created by SAP CAF with every business object. To view the list of entity services created, you can expand the business object in the project structure, or select the Operations tab in the Business Object Modeler. As Figure 18.38 depicts, you can add your own additional operations (via the Add button) and specify their input and output parameters.

List of Standard Operations in a Business Object

Figure 18.38    List of Standard Operations in a Business Object

In the background, these operations are generated in Java using EJBs. To see the generated beans, select the Implementation tab in the Business Object Modeler, and click on the link for the Java bean. Note that the generated EJB uses the name format <BO name>BeanImpl.Java.

The list of operations included by default for any given business object are presented in Table 18.1.

Operation Description
create Inserts one new record in the database table generated by SAP CAF. It automatically generates a primary key for the entry. This operation doesn’t need an input structure. It therefore creates an entry with only the standard input structures filled in.
createMultiple Insert data into the business object table using the business object structure as input parameters. The operation can accept the insertion of multiple records at one time.
delete Deletes a record from the business objects table given a set of attributes as input and filtering criteria. This operation is mostly executed with the primary key as input.
deleteMultiple Works like the delete operation, but can take multiple business object records as input.
findAll Returns all entries of the business object’s database table. Notice that this function doesn’t have any input parameters.
findByMultipleParamaters Returns a list of business object entries from the database table based on some input parameter filtering criteria.
read Retrieves details of a business object entry in the database, given the primary key of a business object as input.
update Updates details of a business object entry in the database with the details provided in the input parameter.
updateMultiple Works like the update operation but has the capability of accommodating multiple business object entries.

Table 18.1    Business Object Standard Operations

On top of these operations, features that are essential to a composite service (e.g., logging/tracing, persistence, and authorization) are automatically provided by the framework.

Application Service

An application service can be used to implement business logic for your composite application. The logic is implemented using EJB 3.0. As part of defining the business logic, an application service defines the overall behaviors of the application. The application service is the box that holds everything together.

The application service has dependencies to different business objects and external services that have to be used for the application. It’s also possible to define custom operations from the application service layer. These operations can in turn encapsulate a number of business object functionalities and expose the composite service to the outside world. Custom business logic can be implemented for these operations.

As Figure 18.39 shows, an application service can be displayed in the diagram editor designer showing all entities that it depends on with all their relationships. The diagram also provides a palette that enables fast modeling via drag and drop of SAP CAF objects.

Application Service Diagram

Figure 18.39    Application Service Diagram

Note

The EJBs’ source code isn’t always immediately updated with details of the new application service. You must select the SAP CAF project and choose the Generate option in the context menu to force a source code update. You can then implement the needed custom business logic within the method definition. See Figure 18.40 for an example of an EJB in which you need to add custom code in the section reserved for the custom operation.

You can provide an application service as a web service so that it can be consumed by external applications. To create a web service from an application service, choose the Expose Service as a Web Service option from the application service’s context menu.

Example EJB with Implementation Open for Custom Logic

Figure 18.40    Example EJB with Implementation Open for Custom Logic

Now that your business objects and application services are ready, you can build and deploy your SAP CAF project to the SAP PO server.

18.3.2    Runtime Aspects

After a successful development, build, and deployment of your SAP CAF project, it’s time to configure or run your service. If your SAP CAF project includes an external web service, then you’ll need to configure the endpoints and destinations of the web service to point toward the correct runtime system. This type of configuration can be performed from SAP NetWeaver Administrator. From there, you’ll need to navigate to different locations depending on the type of service to be consumed. For external RFCs, you add a new destination by navigating to the SOA and Technical Configuration tabs and then click on the Destinations link.

For external web services, configure the new endpoint by navigating to the SOA and Application and Scenario Communication tabs.

After configuring your SAP CAF project, you can access it via http://<hostname>: <port>/caf.

On the landing page, select the Service Browser link. From there, you can expand the tree on the left side and get to the business object of your choice to perform the needed operation (see Figure 18.41).

If the services were exposed as web services, then you can find the WSDL from SAP NetWeaver Administrator by navigating to SOA • Application and Scenario Communication. You then need to click on the Single Service Administration link.

SAP CAF Service Browser with a List of All Available Operations

Figure 18.41    SAP CAF Service Browser with a List of All Available Operations