Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 
former_member4529
Active Contributor
0 Kudos

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.

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>!https://weblogs.sdn.sap.com/weblogs/images/251760438/association.png|height=241|alt=BO Association|width=580|src=https://weblogs.sdn.sap.com/weblogs/images/251760438/association.png|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>!https://weblogs.sdn.sap.com/weblogs/images/251760438/findByAssociated.png|height=388|alt=Associated findBy Key|width=367|src=https://weblogs.sdn.sap.com/weblogs/images/251760438/findByAssociated.png|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>!https://weblogs.sdn.sap.com/weblogs/images/251760438/findDepartmentByEmployeeID.png|height=387|alt=f...!</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">@com.sap.caf.dt.CAFOperation(name = "addEmployeeToDepartment")

public void addEmployeeToDepartment(java.lang.String DepartmentID, java.util.Collection<com.ibm.caf_bo.types.Employee> Employee) throws com.sap.caf.rt.exception.CAFServiceException {

//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">@com.sap.caf.dt.CAFOperation(name = "readDepartmentEmployee")

public com.ibm.caf_bo.types.DepartmentReadResponseMessage readDepartmentEmployee(java.lang.String departmentID) throws com.sap.caf.rt.exception.CAFServiceException {

 

//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

deptResponseMsg.setDepartment(dept);

//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

empList.add(empService.read(employeeKey[i]));

}

 

//add the Employee BO List to the return structure

deptResponseMsg.setEmployee(empList);

 

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.

 

 

!https://weblogs.sdn.sap.com/weblogs/images/251760438/createchildbo.png|height=309|alt=Create Composition BO|width=363|src=https://weblogs.sdn.sap.com/weblogs/images/251760438/createchildbo.png|border=0!

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

 

 

!https://weblogs.sdn.sap.com/weblogs/images/251760438/childbo1.png|height=295|alt=Child BO|width=570|src=https://weblogs.sdn.sap.com/weblogs/images/251760438/childbo1.png|border=0!

 

 

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

!https://weblogs.sdn.sap.com/weblogs/images/251760438/composition.png|height=242|alt=BO Composition|width=457|src=https://weblogs.sdn.sap.com/weblogs/images/251760438/composition.png|border=0!

 

 

10 Comments
Labels in this area