cancel
Showing results for 
Search instead for 
Did you mean: 

Reading out complex data structures

timobermueller
Explorer
0 Kudos

I've a problem when i try to read out a complex data structure in Netweaver Developer Studio CE 7.1 Preview Version:

I created a BO called 'Employee' with the attributes firsname and lastname.

A new complex data structure called 'EmployeeOut' contains the regular 'Employee' structure with the cardinality 0..n, named 'Out'

Next I set up an Application Service called 'EmployeeApp', wich contains the function 'getAllEmployees': The Output parameters is set to the new structure 'EmployeeOut' (moreover Dependencies of the 'EmployeeApp' is set to the BO 'Employee').

The function 'getAllEmployees' contains the following Code:

@com.sap.caf.dt.CAFOperation(name="getAllEmployees")
	public com.sap.demo.demo.modeled.EmployeeOut getAllEmployees() throws com.sap.caf.rt.exception.CAFServiceException {
		
		EmployeeOut response = new EmployeeOut();
		
		List<Employee> employeeOut = new ArrayList<Employee>();
		employeeOut = (List<Employee>)this.getEmployeeService().findAll();
		response.setOut(employeeOut);
		
		return response;
	}

The Service-Test, in the Service Browser, shows that everything works fine.

Now I expose the EmployeeApp as a WebService and import this one into another Application Service 'EmployeeCall' without any Problem.

I map the Operation 'getAllEmployees' succesful. Then I create another operation and want to read out the firstname and the lastname. But how can i do this?

How can I call the Service Operation? Somthing like: this.getAllEmployees() ...?

Best Regards

Tim

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

It is possible to map specific fields as well (if you have tried already).

Another way is call local getAllEmployee() directly and then extract fields from response.

>response = getAllEmployee();

>firstname = response.getFirstName();

>lastname = response.getLastname();

>//do whatever you want to do

Regards,

Gourav

timobermueller
Explorer
0 Kudos

Hi Gourav,

Thank you very much ...

I solved the problem, the code now looks like this:

@com.sap.caf.dt.CAFOperation(name="employeeCall")
	public java.util.List<com.sap.demo.call.modeled.Output> employeeCall() throws com.sap.caf.rt.exception.CAFServiceException {
		
		GetAllEmployees employeesOut = new GetAllEmployees();
		List<Employee> employeeList = this.getAllEmployees(employeesOut.getGetAllEmployees()).getGetAllEmployeesResponse().getOut();
		
		List<Output> response = new ArrayList<Output>();
		
		for(Employee h : employeeList){
			Output tmp = new Output();
			tmp.setFirstname(h.getFirstname());
			tmp.setLastname(h.getLastname());
			response.add(tmp);
		}
		return response;
	}

I think this is what you mean ....

Thank you very much ...

Best Regards

Tim

Former Member
0 Kudos

Hi,

Exactly this is the you should write.

Regards,

Gourav

timobermueller
Explorer
0 Kudos

Ok, thank you so much!!!

Regards

Tim

Former Member
0 Kudos

Hi,

Just one modification:

>for(Employee h : employeeList){

> Output tmp = new Output();

Move "Output tmp = new Output();" out of "for" loop.

Regards,

Gourav

timobermueller
Explorer
0 Kudos

Hi Gourav,

when I put the "Output tmp = new Output();" out of the for-loop, every dataset is the same.

I think you have to create a new Output-Object in any for-step, because you have to put all the single datasets one by one in the list.

While leaving this line in the for-loop everything works fine.

But thank you for yout tip!

Best Regards

Tim

Answers (0)