cancel
Showing results for 
Search instead for 
Did you mean: 

RFC Export Parameter is array - how do I retrieve the get method from array

Former Member
0 Kudos

Hi

How do I retrieve the get methods from an array?

In my bean I have the following to retrieve the array:

private Z_GDataType[] callRFC(com.sap.mw.jco.JCO.Client client, CKey cKey)
			throws SystemFaultException, ApplicationFaultException
		{
			Z_Get_GData_Input input = new Z_Get_GData_Input();
			input.setPernr(cKey.getObjectID());
			input.setKey_Date(cKey.getDate());
			
			Z_GData_PortType proxy = new Z_GData_PortType();
			((AbstractProxy) (proxy)).messageSpecifier.setJcoClient(client);
			Z_Get_GData_Output  output = proxy.z_Get_GData(input);
			return output.getGData(); 
		}

In my get method i have the following:

  
private Z_GDataType[] genDataCM;
......
	public String getJobGrade()
	{
		int j = genDataCM.length;	
		return genDataCM[j].getJobgrade().toString(); 
	}

Is this the correct way of accessing the getJobGrade method from the array??

Regards

RD

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

public String getJobGrade()
	{
		int j = genDataCM.length;	
		return genDataCM[j].getJobgrade().toString(); 
	}

On this way you will get only the last record in the array. If is good enough for you, OK. But probable you want all data from array.

Put int j out of getJobGrade() (private class variable) and use it for counter. And you must have some boolean function eq. next()


int j = 0;	

public boolean next()
{
	if (j<=genDataCM.length)
	{
		j++;
		return true;
	}
	else
	{
		return false;
	}
}

public String getJobGrade()
{
	return genDataCM[j].getJobgrade().toString(); 
}

and when you want retrive data you will make loop


while (myObject.next())
{
	myObject.getJobGrade();
}

I wish you luck

Former Member
0 Kudos

Hi Vedran

Thank you for your reply!!

I get an error but I think my while statement is wrong since i get an error.

Please see if this is correct:

int j = 0;
	public boolean next()
	{
		if (j<=genDataCM.length)
		{
			j++;
			return true;
		}
		else
		{
			return false;
		}
	}
 
	public String getJobGrade()
	{
		String jGrade = "";
		while (next())
		{
			jGrade=  genDataCM[j].getJobgrade().toString();
		}
		return jGrade; 
	}

RD

Former Member
0 Kudos

Sorry, I wrote code without testing and I went out of bones.


public boolean next()
{
	if (j<genDataCM.length)
	{
		j++;
		return true;
	}
	else
	{
		return false;
	}
}
--------------------------------
public String getJobGrade()
{
	return genDataCM[j-1].getJobgrade().toString();
}

---------

<b>and this part put outside your class!!!</b>


while (myObject.next())
{
	myObject.getJobgrade();
}

If you get error again, pleas write it in next post.

If you put loop in getJobGrade(), you will get the same result as in your first post.

You can not with one getter get the whole list.

Where you want to retrive records from RFC (where you want call getJobGrade() )?

Former Member
0 Kudos

Hi

Im sorry I dont understand - the "while" statement should be outside my class??

For example..

package com.gendata;
public class GenDataBean{

  public boolean next(){
  ......
  }

  public String getJobGrade{
     return genDataCM[j-1].getJobgrade().toString();
  }

}//class end

while (myObject.next())
{
	myObject.getJobgrade();
}

myObject is what??

Please give me an example...

I am basically recieving the rfc in table format. How would I retrieve those get methods ?

Your help is much appreciated..

Former Member
0 Kudos

Hi again

can you tell me where you want use records from your RFC. Do you use WebDynpro or jsp or somewhere else? Where you want call getJobGrade()?

Former Member
0 Kudos

Hi

I would call it in JSP:

Here is part of it...

<%@ page import="java.util.ResourceBundle"%>
<%@ taglib uri="htmlb" prefix="hbj" %>
<jsp:useBean id="data" scope="request" class="com.sap.pct.hcm.employeeprofile.generaldata.GeneralDataBean" />
<jsp:useBean id="cKey" scope="request" class="com.sap.pct.hcm.orgmanagementeventing.CKey" />
<hbj:content id="myContext" >
<hbj:page>
<hbj:form>
<table border="0"><tr><td colspan="7">
<td><hbj:label id="ll" labelFor="l" text="<%=rb.getString("job_grade")%>"/></td>
<td></td>
<td><hbj:textView id="l" text="<%=data.getJobGrade()%>"/></td>

.......

Former Member
0 Kudos

OK try this

in class GeneralDataBean

put


Z_Get_GData_Output[] genDataCM;
int j;

private void callRFC(com.sap.mw.jco.JCO.Client client, CKey cKey)
			throws SystemFaultException, ApplicationFaultException
	{
		Z_Get_GData_Input input = new Z_Get_GData_Input();
		input.setPernr(cKey.getObjectID());
		input.setKey_Date(cKey.getDate());
		
		Z_GData_PortType proxy = new Z_GData_PortType();
		((AbstractProxy) (proxy)).messageSpecifier.setJcoClient(client);
		Z_Get_GData_Output  output = proxy.z_Get_GData(input);
		genDataCM = output.getGData(); 
		j = 0;
	}


public void executeRFC() throws SystemFaultException, ApplicationFaultException
{
	callRFC(<put parameters>);
}

	public boolean next()
	{
		if (j<genDataCM.length)
		{
			j++;
			return true;
		}
		else
		{
			return false;
		}
	}
	
	
	public String getJobGrade()
	{
		return genDataCM[j-1].getGsber().toString();
	}

-


in jsp

put

	
<%
	
//data = new GeneralDataBean(); - im not sure, maybe you need this
data.executeRFC();


while(data.next())
{%>
	<%=data.getJobGrade()%>   <br>
<%}%>


I hope it will work. See you tomorow

Former Member
0 Kudos

Sorry for the late response..

I have tried that out - thou it still gives an error. The RFC thou, has now been changed to return it as export parameters - So this way it works.

I would however would like to get this right for future reference - I shall play around with the code further.

Thank you - I have awarded you some points for your inputs.

RD