cancel
Showing results for 
Search instead for 
Did you mean: 

Java code help needed for If-elseif statement

Former Member
0 Kudos

HI All,

Apologies for posting such a trivial thing but I am a novice in Java.

All I need is to code an If elseIF statement.

I tried the code below



String w = "SAPA";
String x = "SAPB";
if (a==w) ;
{Channel channel = LookupService.getChannel("BS_PROD","CC_RFC_LOOKUP");}
 else if (a==x) 
{ Channel channel = LookupService.getChannel("BS_PROD","CC_RFC_LOOKUP_ECQ"); }

It came back with the error

Source code has syntax error:  D:/usr/sap/XRD/DVEBMGS02/j2ee/cluster/server0/./temp/classpath_resolver/Map695b77619ad011dd8d0b001a4b52813a/source/com/sap/xi/tf/_MM_TRANSMISSION_CHECK_TO_GENIUS_.java:324: 'else' without 'if' else if (a==x) ^ 1 error

Appreciate if you could let me know the correct code.

Many thanks

Shirin

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

I commented the ElseIF part of the code and the UDF works fine then, so I guess problem is somewheer the way I have coded the ELSEIF statement.

if (a==w) ;
Channel channel = LookupService.getChannel("BS_IFMS_GENIUS_UAT","CC_RFC_LOOKUP");
// else if (a==x) 
//{ Channel channel = LookupService.getChannel("BS_IFMS_GENIUS_UAT","CC_RFC_LOOKUP_ECQ"); }

Regards

Shirin

Former Member
0 Kudos

Hi Shirin,

Now the problem is not with the if and else if.

Now the Channel channel is defined with in the if condition and else if condition.

In this case if and else if conditions are not satisfying so compiler is not finding channel variable in the program. So it is giving the error at accessor = LookupService.getRfcAccessor(channel);

You can solve this problem by declaring the Channel as follows

RfcAccessor accessor = null;

ByteArrayOutputStream out = null;

Channel channel = null;

try

{

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

if (a==w)

{ channel = LookupService.getChannel("BS_PROD","CC_RFC_LOOKUP");}

else if (a==x)

{ channel = LookupService.getChannel("BS_PROD","CC_RFC_LOOKUP_ECQ"); }

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

accessor = LookupService.getRfcAccessor(channel);

By declaring the Channel as above you can avoid this error.

I think your conditions are not satisfying with the a value.

Regards

Sridhar Goli

Answers (2)

Answers (2)

Former Member
0 Kudos

HI Aamir,

After I removed the semi-colon iIt came back with the following error

Source code has syntax error:  D:/usr/sap/XRD/DVEBMGS02/j2ee/cluster/server0/./temp/classpath_resolver/Map1d9b43e09ad111dd84b7001a4b52813a/source/com/sap/xi/tf/_MM_TRANSMISSION_CHECK_TO_GENIUS_.java:328: cannot resolve symbol symbol : variable channel location: class com.sap.xi.tf._MM_TRANSMISSION_CHECK_TO_GENIUS_ accessor = LookupService.getRfcAccessor(channel); ^ 1 error

Just for reference my entire Jave UDF looks like this:

//write your code here
String w = "SAPA";
String x = "SAPB";
  String content = "";
MappingTrace importanttrace;
importanttrace = container.getTrace() ;
//Filling the string with our RFC-XML (With Values)
String m = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><ns0:ZIFMS_GET_NEXT_NUMBER xmlns:ns0=\"urn:sap-com:document:sap:rfc:functions\"><I_NR_RANGE_NR>01</I_NR_RANGE_NR><I_OBJECT>ZIFMS_INT</I_OBJECT></ns0:ZIFMS_GET_NEXT_NUMBER>";

RfcAccessor accessor = null;
ByteArrayOutputStream out = null;
try
{
//1. Determine a channel (Business System, Communication channel)
if (a==w) 
{Channel channel = LookupService.getChannel("BS_PROD","CC_RFC_LOOKUP");}
 else if (a==x) 
{ Channel channel = LookupService.getChannel("BS_PROD","CC_RFC_LOOKUP_ECQ"); }

//2. Get a RFC accesor for a channel.
accessor = LookupService.getRfcAccessor(channel);

//3. Create a xml input stream representing the FM request message.
InputStream inputstream = new ByteArrayInputStream(m.getBytes());

//4. Create xml Payload
XmlPayload payload = LookupService.getXmlPayload(inputstream);

//5. Execute Lookup
Payload result = accessor.call(payload);
InputStream in = result.getContent();

//This are the extra step which i dont know what it mean
//out = new ByteArrayOutputStream(1024);
//byte[] buffer = new byte1024;
//for (int read = in.read(buffer); read > 0; read = in.read(buffer))
//{
//out.write(buffer,0,read);
//}
//content = out.toString();
try {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document document = builder.parse(in);
NodeList list = document.getElementsByTagName( "E_NUMBER" );
Node node = list.item(0);
if (node != null)
{
node = node.getFirstChild();

if (node != null)
{
content = node.getNodeValue();
}
}
} catch (Exception e) {
importanttrace.addWarning("Error while closing accesor" + e.getMessage());
}

}
catch (LookupException e)
{
importanttrace.addWarning("Error While lookup" + e.getMessage());
}
//This exception is not to be catch at this step as there is no try step before this
//catch (IOException e)
//{
//importanttrace.addWarning("Error" + e.getMessage());
//}
finally
{
if(out!=null)
try{
out.close();
} catch (IOException e) {
importanttrace.addWarning("Error while closing system" + e.getMessage());
}
}
//7. close the accessor in order to free resources
if (accessor!=null) {
try{
accessor.close();
} catch (Exception e) {
importanttrace.addWarning("Error while closing accesor" + e.getMessage());
}
}

return content;

Former Member
0 Kudos

>>if (a==w) ;

This wont have semi colon in the end.remove the semi colon

it must be

if (a==w)

Thanx

Aamir