cancel
Showing results for 
Search instead for 
Did you mean: 

UDF to comapre all the value in Context and send a single Output Value

Former Member
0 Kudos

Hi,

I get a response structure from an RFC and needs to send the status from the Response to target structure.

Response

RETURN

Row 0.....unbounded

Status 0.....1

Target

STATUS 0.....1

The Row value repeats to unbounded where the Status field gets the Value E or S.If all the values in the Repeated Rows are S then i need to send the status in a target field File Transfer Success .If all the values or E or some rows have Status E and some have S i need to send the status as File Transfer Failed.

The Output should be a single Value comparing all the Values in the Input and should return a single value FileTransferSuccess or FileTransfer OK.

How to write UDF for the above requirement

Thanks and Regards,

Rajesh

Accepted Solutions (1)

Accepted Solutions (1)

shweta_walaskar2
Contributor
0 Kudos

Hi Rajesh,

Create a context UDF with input as an array for Status fields,then your UDF should look something like:

boolean flag = true;

for(int i=0;i<Status.length;i++)

{

if(Status<i>.equals("E"))

flag = false;

}

if(flag == false)

result.addValue("FileTransferFailed");

else

result.addValue("FileTransferSuccess");

Best Regards,

Shweta

baskar_gopalakrishnan2
Active Contributor
0 Kudos

@ Shweta: Small correction in the code

flag is declared as boolean, so dont use equal sign to check boolean. (Not a good practice)

boolean flag = true;

for(int i=0;i<Status.length;i++)

{

if(Status.equals("E"))

flag = false;

}

if(flag){

result.addValue("FileTransferSuccess");

}

else{

result.addValue("FileTransferFailed");

}

Former Member
0 Kudos

Hi Swetha,

Thanks a lot.It helped but we need to include

if(Status<i>.equals("E"))

Thanks a lot for the helpful answers.

Thanks and Regards,

Rajesh

Answers (2)

Answers (2)

stefan_grube
Active Contributor
0 Kudos

if should work with standard function also.

something like this:

status - removecontexts - equals (constant(E)) - createif - exists - if(E/S) - status

Former Member
0 Kudos

First of all you need to map the output of the Status field from the source structure to node function removeContext to bring all the Status values in a single context. Then pass the output of this removeContext function to the UDF that I have written below.

Pass the output of this UDF to the target side STATUS field. Its as simple as that.

THE COMPLETE CODE OF THE UDF IS AS FOLLOWS:

public void func(String[] instr,ResultList result,Container c)

{

int len=instr.length;int flag=0;

for(int i=0;i<len;i++)

{

if(instr<i>.equalsIgnoreCase("S"))

{}

else

{flag=1;}

}

if(flag==1)

result.addValue("File Transfer Failed");

else

result.addValue("File Transfer Success");

}

Edited by: 007biswa on Feb 11, 2011 2:25 PM

Former Member
0 Kudos

Hi Rajesh,

Please follow my instructions and have a look at the code once again as i made 1 change in it.

I HAVE TESTED IT.....IT WORKS ABSOLUTELY FINE.

PLEASE LET ME KNOW IF YOU ARE ABLE TO DO WHAT YOU WANTED

THANKS

BISWAJIT