Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Java code help needed for If-elseif statement

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

replied

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

0 View this answer in context

Helpful Answer

by
Not what you were looking for? View more on this topic or Ask a question