cancel
Showing results for 
Search instead for 
Did you mean: 

Context value

Former Member
0 Kudos

Hi All,

How to read the second value of a context supressing the first one:

for eg:

<N1>1,2<N1>

<N2>3,4<N2>

output will be 2 and 4.Please give your inputs not able to do with graphical?

Regards,

Nkumar

Accepted Solutions (0)

Answers (3)

Answers (3)

Former Member
0 Kudos

Hi Kumar,

Create a Value user defined function and name it as GetAfterComma. Take one argument as a.

Add this code:

Imports: java.*;

//write your code here

int k = a.length();

int i = a.indexOf(".");

i = i +1;

a = a.substring(i,k);

return(a);

Map like this:

Input field --> UDF --> target field.

So if input is 2,4 then you will have ouput as 4.

Regards,

---Satish

baskar_gopalakrishnan2
Active Contributor
0 Kudos

You can write simpe udf. Another way to achieve this.....

// pass input String as method argument and return type String

int index1 = input.indexOf(",");
String output = input.substring(index1+1, input.length());
return output;

Edited by: Baskar Gopal on Jul 19, 2011 2:03 PM

former_member854360
Active Contributor
0 Kudos

use standard function copyvalue

You can use standard function copyvalue

You can use CopyValue() to copy the value of a position in the source structure and assign it to a target field

see this link for an perfect example

http://help.sap.com/saphelp_nw04/helpdata/en/26/d22366565be0449d7b3cc26b1bab10/content.htm

sourcefield--copyvalue(1)-mapwithdefault--targetfield

Input

ContextChange

2

4

Contextchange

5

7

Contextchange

Output

ContextChange

4

Contextchange

7

Contextchange

Former Member
0 Kudos

Hi Debasish,

Actually I am getting same 4 nodes carrying differnt value but want to take 2nd and 4th node only.Here I tried copyvalue but not working only getting 1 node...also if 2 nodess coming want to take second node with the target..please suggest

Edited by: NKumar1 on Jul 19, 2011 4:00 PM

former_member854360
Active Contributor
0 Kudos

Hi KUMAR,

USE the below UDF with execution type All values of context

also make sure input to this UDF .........no contextchange between your four or two values.

public void calculate(String[] var1, ResultList result, Container container) throws StreamTransformationException{

if(var1.length>=4)
{
result.addValue(var1[1]);
result.addValue(var1[3]);
}
else
{
result.addValue(var1[1]);
}
}

Please let know if its helps you

pedro_baroni3
Active Contributor
0 Kudos

Hi NKumar1,

If your values are numbers, you can use the graphical mapping as below:

N1

Constant (",") -> replaceString() -> ceil() -> {target field}

Constant (".")

Best Regards.

Pedro Baroni