Skip to Content
avatar image
Former Member

Problems trying to retrieve data from R/3 using Java - RecordSetWrapper

Hello everyone!

I am having problems retrieveing a result from r/3 using Connector Framework API. An ABAP consultant has created a ABAP program which returns an employee based on his or her personal number as an input.

<b>When i run the AbstractPortalComponent i get the following:

<u>RS2: com.sapportals.connectors.SAPCFConnector.execution.structures.RecordSetWrapper@24648563</u></b>

My code is as follows:

package com.sap.test;
 
import java.util.ArrayList;
import java.util.Iterator;

import javax.resource.cci.MappedRecord;
import javax.resource.cci.RecordFactory;

import com.sap.security.api.IUser;
import com.sapportals.connector.connection.IConnection;
import com.sapportals.connector.execution.functions.IInteraction;
import com.sapportals.connector.execution.functions.IInteractionSpec;
import com.sapportals.connector.execution.structures.IRecordSet;
import com.sapportals.connector.execution.structures.IStructureFactory;
import com.sapportals.connector.metadata.functions.IFunction;
import com.sapportals.portal.ivs.cg.ConnectionProperties;
import com.sapportals.portal.ivs.cg.IConnectorGatewayService;
import com.sapportals.portal.ivs.cg.IConnectorService;
import com.sapportals.portal.prt.component.*;
import com.sapportals.portal.prt.runtime.PortalRuntime;

public class Search extends AbstractPortalComponent{
	String sapSystem = "*****";


	
	public void doContent(IPortalComponentRequest request, IPortalComponentResponse response){

		IConnection con = null;
		ConnectionProperties conprop = null;
		ConnectionProperties cp = null;
	
		try{

			Object connectorService = PortalRuntime.getRuntimeResources().getService(IConnectorService.KEY);
			IConnectorGatewayService cgService = (IConnectorGatewayService) connectorService;
			cp = new ConnectionProperties(request.getLocale(),request.getUser());
			if(cgService == null){
				response.write("Error in getting Connector Gateway Service <br>");
			}
			try{

				con = cgService.getConnection(sapSystem, cp);
				IInteraction ix = con.createInteractionEx();
				IInteractionSpec ixSpec = ix.getInteractionSpec();
				ixSpec.setPropertyValue("Name", "Test_RFC");
				RecordFactory rf = ix.getRecordFactory();
				MappedRecord importParams = rf.createMappedRecord("INPUT");
				IFunction function = con.getFunctionsMetaData().getFunction("Test_RFC");
				IStructureFactory structureFactory = ix.retrieveStructureFactory();
				IRecordSet table = (IRecordSet) structureFactory.getStructure(function.getParameter("I_PA0002").getStructure());
				
				importParams.put("PERNR", "123456");
				MappedRecord output = (MappedRecord) ix.execute(ixSpec,importParams);
				
				Object rs = null;
				try{
					Object result = output.get("I_PA0002");
					if(result == null){
						rs = new String ("Error");
						response.write("RS1: " +rs+ "<BR>");
					}
					else
						if(result instanceof IRecordSet){
							rs = (IRecordSet) result;
							response.write("RS2: " +rs+ "<BR>");
						}
						else{
							response.write("RS3: " +rs+ "<BR>");
						}
				}
				catch(Exception e){
					response.write("Error " + e.getMessage()+ "<BR>");
				}
	
				
				
			}
			catch(Exception e){
				response.write("Connection to SAP system failed <br>");
			}

			if(con == null){
				response.write("Connection is null <br>");
			}
			else{
				response.write("Connection succsesful<BR>");
			}	
		}
		catch(Exception e){
			response.write("Exception occured<BR>");
		}

		try{
			con.close();
			response.write("Connection closed<br>");
		}
		catch(Exception e){
			response.write("Could NOT close connection<BR>");
		}
				
	}	
				
}

The result should be all data stored on the person which I search for, but instead i get the following result:

<b>

RS2: com.sapportals.connectors.SAPCFConnector.execution.structures.RecordSetWrapper@24648563</b>

I am really stuck and do not know how to solve the problem. I appreciate any help or sample (or just some answers...)

Thanks in Advance.

Best Regards,

Ola Aarthun

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • Best Answer
    avatar image
    Former Member
    Apr 20, 2006 at 08:50 AM

    Hi,

    From your code you are just displaying the object rs. You have to handle the display of each record the way you want it(as a table).

    You can find a sample code how to build a table from the result object at the following link

    https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/bfb1ba90-0201-0010-5e97-bd6a8f5022dc

    Regards,

    Padmaja

    Add comment
    10|10000 characters needed characters exceeded