cancel
Showing results for 
Search instead for 
Did you mean: 

RFC Lookup error.

former_member335553
Active Contributor
0 Kudos

Hi

Scenario - File - RFC LOOKup- SAP

File has got 2 fields (Zprod and Zoffer) .When these fields are empty,material number from the file is sent as an input parameter in RFC lookup such that it woud fetch the value ZZprod and Zoffer from the SAP table and populate it in the file fields which is parsed and sent to the target .

<b>Where do i go wrong in this code</b>

imports java.io.;com.sap.aii.mapping.lookup.;

public String getProductOffering(String e,Container container){

MappingTrace importanttrace;

importanttrace = container.getTrace();

{

String content = "";

String m = "<?xml version=\"1.0\"encoding=\"UTF-8\"?><ns0:Z_SD_LOOKUP_SNS xmlns:ns0=\"urn:sap-com:document:sap:rfc:functions\"> <MATNR/> ns0:Z_SD_LOOKUP_SNS>";

RfcAccessor accessor = null;

importanttrace.addInfo(m);

try

{

String BSName = "";

java.util.Map map;

map = container.getTransformationParameters();

BSName = (String)map.get(StreamTransformationConstants.RECEIVER_SERVICE);

// 1. Determine a channel (Business system, Communication channel)

Channel channel = LookupService.getChannel(BSName,"TSGD_TSD_RFC_IN");

// 2. Get a RFC accessor for a channel.

accessor = LookupService.getRfcAccessor(channel);

// 3. Create a xml input stream representing the function module request message.

InputStream inputStream = new ByteArrayInputStream(m.getBytes());

// 4. Create xml payload

XmlPayload payload = LookupService.getXmlPayload(inputStream);

// 5. Execute lookup.

Payload resultPayload = accessor.call(payload);

InputStream in = resultPayload.getContent();

BufferedInputStream bis = new BufferedInputSream(in);

int i;

while((i = bis.read()) != -1)

{

content = content + i;

}

bis.close();

}

catch(LookupException e)

{

importanttrace.addWarning("Error while lookup " + e.getMessage() );

}

catch(IOException e)

{

importanttrace.addWarning("Error " + e.getMessage() );

}

finally

{

// 7. close the accessor in order to free resources.

if (accessor!=null) {

try {

accessor.close();

} catch (LookupException e) {

importanttrace.addWarning("Error while closing accessor " + e.getMessage() );

}

}

}

return content;

}

Help in this is highly appreciated .Thanks.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Anusha,

I think the problem might be due to the closing tag.

You haven't closed the tag </ns0:Z_SD_LOOKUP_SNS>";

Thanks

Pravesh

Answers (5)

Answers (5)

Former Member
0 Kudos

Hi,

I think you need to have some value for MATNR in the UDF as it seems it is empty in the String. Either add an argument in the UDF to get the value of MATNR or specify a value in the String.

String m = "<?xml version=\"1.0\"encoding=\"UTF-8\"?><ns0:Z_SD_LOOKUP_SNS xmlns:ns0=\"urn:sap-com:document:sap:rfc:functions\"> <MATNR/> </ns0:Z_SD_LOOKUP_SNS>";

Pravesh

Former Member
0 Kudos

Hi

use this peace of code

String headerField;

java.util.Map map;

String Sender_Service = "";

String comm_channel = "";

Sender_Service= "";

JCO.Repository mRepository;

JCO.Client mConnection = JCO.createClient( "" , "", "", "" , "" , "" );

// connect to SAP

mConnection.connect();

//Repository = new JCO.Repository( "SAPLookup", mConnection );

JCO.Function function = null;

IFunctionTemplate ft = mRepository.getFunctionTemplate("UR FUNCTION MODULE NAME");

function = ft.getFunction();

JCO.ParameterList input = function.getImportParameterList();

input.setValue ( , "" );

input.setValue ( , "" );

input.setValue ( , "" );

String ret1 ="";

String ret2 ="";

String ret3 ="";

mConnection.execute(function);

{

ret1 = function.getExportParameterList().getString( "OUTPUT OF FUNCTION MODULE");

ret2 = function.getExportParameterList().getString( "OUTPUT OF FUNCTION MODULE");

}

mConnection.disconnect();

Vector vector = new Vector();

{

vector.add(ret1);

vector.add(ret2);

vector.add(ret3);

}

//GlobalContainer glCont = container.getGlobalContainer();

//glCont.setParameter("OUTBOUND PARAMETER",vector);

Alos use the bpm for this.

1) use global variable for using the responce of lookup.

Thanks

sudhir sharma

former_member335553
Active Contributor
0 Kudos

Sudhir

we need only mapping API's not jco's.

What would be the <b>content</b> that is returned ..

When i give my material number from file as input to RFC ,RFC should pick up the corresponding Zprod and Zoffer from the table and update in Mapping for the fields in file ..

So would the content be a string of these 2 values ?If yes How to spilt it up in UDF ?

former_member335553
Active Contributor
0 Kudos

Any thoughts

Former Member
0 Kudos

Hi Sudhir,

I had the same situation and what happens if the RFC look up has to return TABLE parameters other than import & export parameters.

Former Member
0 Kudos

<b>U cannot use try- catch block in UDF</b>

Former Member
0 Kudos

There is no problem with try-catch in UDF.

I have implemented this mapping lookup RFC API in one of our interface using the same sample code.

Former Member
0 Kudos

what sort of Error u are getting if u paste that it will help us to get in more details.

Reagrds

Farooq.

former_member335553
Active Contributor
0 Kudos

Hi

"<?xml version=\"1.0\"encoding=\"UTF-8\"?><ns0:Z_SD_LOOKUP_SNS xmlns:ns0=\"urn:sap-com:document:sap:rfc:functions\"> <MATNR/> </ns0:Z_SD_LOOKUP_SNS>";

I had closed the tags properly sry that was a typo and the error message is

"Ilegal start of expression public static void main(String[] args) throws expression"

Former Member
0 Kudos

u r doing Lookup...are u testing it in IR or java Editor????

Former Member
0 Kudos

<b>imports</b> java.io.;com.sap.aii.mapping.lookup.;

it should be import java.io.;com.sap.aii.mapping.lookup.;

import is the keyword not the imports..typo error...

Former Member
0 Kudos

My Mistake...in UDF we dont have to write the import..it display imports.

so that is not the issue.