Skip to Content
0
Former Member
Aug 04, 2005 at 11:12 PM

Jca to Rfc null return

28 Views

Can somebody please help me figure out why i am not getting null when there is data returned by RFC.

I am major part i am using code posted by Prakash.

Just testing YTEST RFC which returns 10 chars.

Bean

import javax.naming.Context;

import javax.resource.cci.MappedRecord;

import javax.resource.cci.RecordFactory;

import com.sapportals.connector.ConnectorException;

import com.sapportals.connector.connection.IConnection;

import com.sapportals.connector.connection.IConnectionFactory;

import com.sapportals.connector.execution.functions.IInteraction;

import com.sapportals.connector.execution.functions.IInteractionSpec;

import com.sapportals.connector.execution.structures.IRecord;

import com.sapportals.connector.execution.structures.IRecordSet;

import com.sapportals.connector.metadata.functions.IFunction;

import com.sapportals.connector.metadata.functions.IFunctionsMetaData;

import com.sapportals.connector.metadata.primitives.IByte;

import com.sapportals.connector.metadata.primitives.IString;

import com.sapportals.htmlb.page.DynPage;

import com.sapportals.htmlb.page.PageException;

import com.sapportals.portal.htmlb.page.JSPDynPage;

import com.sapportals.portal.htmlb.page.PageProcessorComponent;

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.IPortalComponentProfile;

import com.sapportals.portal.prt.component.IPortalComponentRequest;

import com.sapportals.portal.prt.runtime.PortalRuntime;

public class Display extends PageProcessorComponent {

public DynPage getPage(){

return new DisplayDynPage();

}

public static class DisplayDynPage extends JSPDynPage{

private TableBean myBean = null;

public void doInitialization(){

IPortalComponentProfile profile = ((IPortalComponentRequest)getRequest()).getComponentContext().getProfile();

Object o = profile.getValue("myBean");

if(o==null || !(o instanceof TableBean)){

myBean = new TableBean();

profile.putValue("myBean",myBean);

} else {

myBean = (TableBean) o;

}

// fill your bean with data here...

IPortalComponentRequest request = (IPortalComponentRequest) this.getRequest();

doJca(request);

}

public void doProcessAfterInput() throws PageException {

}

public void doProcessBeforeOutput() throws PageException {

this.setJspName("display.jsp");

}

private IConnection getConnection(

IPortalComponentRequest request,

String alias)

throws Exception {

IConnectorGatewayService cgService =

(IConnectorGatewayService) PortalRuntime

.getRuntimeResources()

.getService(

IConnectorService.KEY);

ConnectionProperties prop =

new ConnectionProperties(

request.getLocale(),

request.getUser());

return cgService.getConnection(alias, prop);

}

public void doJca(IPortalComponentRequest request) {

IConnectionFactory connectionFactory = null;

IConnection client = null;

String rfm_name = "YTEST";

try {

try {

//pass the request & system alias

//Change the alias to whatever the alias is for your R/3 system

client = getConnection(request, "SAP_R3_HumanResources");

} catch (Exception e) {

System.out.println(

"Couldn't establish a connection with a target system.");

return;

}

/*

  • Start Interaction

  • */

IInteraction interaction = client.createInteractionEx();

IInteractionSpec interactionSpec = interaction.getInteractionSpec();

interactionSpec.setPropertyValue("Name", rfm_name);

/*

  • CCI api only has one datatype: Record

  • */

RecordFactory recordFactory = interaction.getRecordFactory();

MappedRecord importParams = recordFactory.createMappedRecord("CONTAINER_OF_IMPORT_PARAMS");

IFunctionsMetaData functionsMetaData = client.getFunctionsMetaData();

IFunction function = functionsMetaData.getFunction(rfm_name);

if (function == null) {

System.out.println(

"Couldn't find " + rfm_name + " in a target system.");

return;

}

/*

  • How to invoke Function modules

  • */

System.out.println("Invoking... " + function.getName());

MappedRecord exportParams = (MappedRecord) interaction.execute(interactionSpec, importParams);

/*

  • How to get structure values

  • */

String RetVal = (String)exportParams.get("RETURN");

// IRecord exportStructure = (IRecord) exportParams.get("RETURN");

/*

String columnOne = exportStructure.getString("TYPE");

String columnTwo = exportStructure.getString("CODE");

String columnThree = exportStructure.getString("MESSAGE");

System.out.println(" RETURN-TYPE = " + columnOne);

System.out.println(" RETURN-CODE = " + columnTwo);

System.out.println(" RETURN-MESSAGE =" + columnThree);

*/

/*

  • How to get table values

  • */

// IRecordSet exportTable = (IRecordSet) exportParams.get("OUTPUT");

/*exportTable.beforeFirst(); // Moves the cursor before the first row.

while (exportTable.next()) {

String column_1 = exportTable.getString("PERNR");

String column_2 = exportTable.getString("ENAME");

System.out.println(" COMPANYCODE_LIST-COMP_CODE = " + column_1);

System.out.println(" COMPANYCODE_LIST-COMP_NAME = " + column_2);

}

//create the tableview mode in the bean

*/

myBean.setCW1(RetVal);

/*

  • Closing the connection

  • */

client.close();

} catch (ConnectorException e) {

//app.putValue("error", e);

System.out.println("Caught an exception: \n" + e);

} catch (Exception e) {

System.out.println("Caught an exception: \n" + e);

}

}

}

}

tablebean:

package com.my.package;

import java.io.Serializable;

import java.util.Vector;

import com.sapportals.connector.execution.structures.IRecordSet;

import com.sapportals.htmlb.table.DefaultTableViewModel;

import com.sapportals.htmlb.table.TableViewModel;

public class TableBean implements Serializable {

private String CW1;

public String getCW1() {

return CW1;

}

public void setCW1(String string) {

CW1 = string;

}

}

JSP

<jsp:useBean id="myBean" scope="application" class="com.com.my.package.TableBean" />

Output "<%= myBean.getCW1()%>"

portalapp.xml

<?xml version="1.0" encoding="utf-8"?>

<application>

<application-config>

<property name="PrivateSharingReference" value="com.sap.portal.htmlb,com.sap.portal.ivs.connectorservice"/>

</application-config>

<components>

<component name="Display">

<component-config>

<property name="ClassName" value="com.my.package.Display"/>

<property name="SecurityZone" value="com.my.packagea.Display/low_safety"/>

</component-config>

<component-profile>

<property name="tagLib" value="/SERVICE/htmlb/taglib/htmlb.tld"/>

</component-profile>

</component>

</components>

<services/>

</application>