Skip to Content

For developing composite applications SAP provides the Composite Application Framework which has been enhanced to a major extent in SAP Netweaver Composition Environment. In this blog I’ll discuss the enhancements and new features available in CAF Core in Netweaver CE for modeling Business Objects. The Business Object in CAF Core refers to a data object created in the composition layer.

<br />Defining a BO

While creating a new Business Object in CAF two options are available to define its structure.


A custom structure can be defined previously which can be used as the structure of the BO. Otherwise a new structure will get created for the BO. The structure of the BO can be edited from the Structure tab. To add an attribute to the BO structure Click on the Edit Main Structure button. That will open the structure editor as below.

Edit BO Structure

Here simple data types or complex data types/structures can be selected from the project references at the left and added to the BO structure as attributes. But no attribute can be defined with 0…n or 1…n cardinality. To define multiple cardinality we need to use association or composition as explained in the next sections. 

<u>Defining Releationships Between Business Objects</u>

<u>Association</u></p><p> The Business Objects relationship can be defined in two ways – Composition and Association. E.g. here a BO called Employee has been created. It can have an association relationship with another BO called Department. That means both Employee and Department BO can exist independently but there is an association relationship maintained between them. To define an association relationship add the Department BO to the Employee BO in the Association tab of BO.</p><p>!|height=241|alt=BO Association|width=580|src=|border=0!</p><p>The cardinality of the associated BO can be set to NONE_TO_ONE (0…1) or NONE_TO_MANY (0…n). Custom operations can be defined for this BO by input parameter of the associated BO as well.</p><p>!|height=388|alt=Associated findBy Key|width=367|src=|border=0!</p><p>In this operation employee ID is specified as input and it returns the Departments to which the employee ID is associated.</p><p>!|height=387|alt=findDeptByEmployeeOperation|width=557|src=|border=0!</p><p>The association of BOs is defined by associating the keys of the two BOs. This can be done in the implementation of corresponding application service operation as below:</p><textarea cols=”69″ rows=”14″> = “addEmployeeToDepartment”)

public void addEmployeeToDepartment(java.lang.String DepartmentID, java.util.Collection<> Employee) throws {

//get the Department BO Local Interface

DepartmentServiceLocal deptService = this.getDepartmentService();

//get the Department Entity<br>Department dept = deptService.findByDepartmentID(QueryFilterFactory.createFilter(DepartmentID));

//loop at Employee List

for(Employee emp : Employee) {

//add association

deptService.addEmployeeDeptAssociation(dept.getKey(), emp.getKey());



</textarea> <p> In the above example the Department and Entity BOs exist independently and an association is created between the given department and the list of employees. To create the association DepartServiceLocal.addEmployeeDeptAssociation(sourceKey, targetKey) is called which is generated for the association named EmployeeDeptAssociation.</p><p> To read the parent BO with the associated BOs refer the following code:</p><p><textarea cols=”70″ rows=”41″> = “readDepartmentEmployee”)

public readDepartmentEmployee(java.lang.String departmentID) throws {

//get the Department BO Local Interface

DepartmentServiceLocal deptService = this.getDepartmentService();

//get the Department data object

Department dept = deptService.findByDepartmentID(QueryFilterFactory.createFilter(departmentID));

//get the associated BO references/keys

String[] employeeKey = deptService.getEmployeeDeptAssociation(dept.getKey());

//get the Employee BO Local Interface

EmployeeServiceLocal empService = this.getEmployeeService();

//create the instance of the return type

DepartmentReadResponseMessage deptResponseMsg = new DepartmentReadResponseMessage();

//set the Department BO instance to the return message


//create a new ArrayList

List<Employee> empList = new ArrayList<Employee>();

//loop at the list of associated keys of Employee

for(int i=0; i < employeeKey.length; i++)


//add associated Employee to the list



//add the Employee BO List to the return structure


return deptResponseMsg;

}</textarea></p><p>In the above code first the key the of the Department BO is obtained by calling the corresponding findByDepartmentID() method. There is a method called DepartmentServiceLocal.getEmployeeDeptAssociation(key) generated for the association named EmployeeDeptAssociation defined for the BO. this will return the list of key of all the associated BOs.</p><p><u>Compostion</u>

Composition relationship means that one BO is contained in another BO, so that there exists a parent-child relationship between the two BOs.
To create composition relationship between Business Objects add a new BO Node on an existing BO.

!|height=309|alt=Create Composition BO|width=363|src=|border=0!

 In this example we add a child BO Assignment to Department BO.

!|height=295|alt=Child BO|width=570|src=|border=0!

Whenever a BO node is added under another BO a composition relationship gets created automatically.

!|height=242|alt=BO Composition|width=457|src=|border=0!

To report this post you need to login first.


You must be Logged on to comment or reply to a post.

  1. Reena Wadhwa
    Hi Dipankar,
        I found the Blog very useful..Thanks for such useful information. but can you please explain the differnec ebetween both relationships i.e composition and association. As mentioned in blog one is cross_BO relation and other is parent_child. apart from that functionality wise i did not see any difference. So can you please thow some light on it.


    1. Dipankar Saha Post author
      Hi Reena,
      For associated BOs one BO can exist without the other though they are associated. An example may be employee and department. In CAF the associated BOs are created at the same level
      For composition BOs the child cannot exist without the parent e.g. order header and order item. In CAF composition BOs are created one below the another.


      1. Steffen Spahr
        Hi Dipankar,

        I have the same understanding from a parent-Child-composition. A child cannot exist without a parent. And one child must exactly have one parent-object.

        But if you define the parent-child composition in CAF and test it in the Service-Browser you can define a child without a parent and you also can define a child with more than one parent object.

        So I think the implementation of the persistence is nearly the same for composition and association.

        The only difference I found, if you delete a parent-object the child-objects are deleted too.

        I tried out to define the child as a complex structure. Doing this I got the expexted result. The child has a “foreign-key” association to the parent.

        But it is impossibly to define the cardinality 0:n or 1:n. Only 0:1 or 1:1 works:-(((

        I don’t know why?

        So, it is not the global solution for building a “real” Parent-Child-Association:-((


        1. Dipankar Saha Post author
          Hi Steffen,
          Your observations regarding the composition parent-child relationship is correct. It is expected for a composition relationship that the child will get deleted automatically when the parent is deleted whereas for association it is not.
          Also for cardinality you can define multi-cardinality relationship between BOs related by association or composition but not in BO attributes as explained in my blog. For setting multi-cardinality relationship between BOs set NONE_TO_MANY in the association tab under cardinality column.


    1. Dipankar Saha Post author
      Select the Data Types node under Modeled in the CAF project in Composite Explorer view in NWDS and right-click and select Complex Structure from the context menu. In the Structure tab define the structure of the complex data type selecting either the primitive or modeled data types.


  2. Ritu Singh
    What will be the cardinality of the complex structure.
    I tried same but not getting any value for employee by giving the deptID in web browser.But if I am passing a single employee in that complex structure its is working fine.

    Can you please tell me the details structure of readDepartmenResponse.What will be the cardinality of the employee under this structure

  3. Fernando Alvarez
    Is association or composition of business objects from different DCs (different DCs from different CAF projects) supported?

    I can browse other DCs BOs from the association of the BO, but the button for adding the association is disabled.

    Best regards


Leave a Reply