cancel
Showing results for 
Search instead for 
Did you mean: 

Mapping - Split string separated by value ;

Former Member
0 Kudos

Hi,

I have a mapping where 4 source values makes the key for 1 target value.

In the target string (result after value mapping) i want to get the last value in the string "TargetValue1.

<i>SourceValue1;SourceValue2;SourceValue3;SourceValue4;TargetValue1</i>

Can this be done without UDF? If not how should the UDF look like?

Best Regards

/Claes

/

Message was edited by:

Claes Widestadh

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Claes,

Please elaborate your issues.I think you talking about concate 4 source value to single target?

Cheers!

Samarjit

Former Member
0 Kudos

Hi,

Yes I have concatenated 4 source values into one string to use them as key in a value mapping to get the target value. The result from the value mapping is a string with the 4 source value + the target value. What I want to do now after the value mapping is to spit this string to get only the target value.

The string looks like this

Source sting

example 1) CC;-;ADJ;fre;

example 2) CR;+;ADJH;TD;

Target string:

example 1) CC;-;ADJ;fre;<b>985</b>

example 2) CR;+;ADJH;TD;<b>553</b>

It is the value 985 or 553 that i want to map into the target field. The position for the target value (985, 553) is not a fixed position because of that the length of the source values can vary (see example obove). That means that I cant use the substring right?

/Claes

Message was edited by:

Claes Widestadh

null

null

Former Member
0 Kudos

Hi Claes,

Result of value mapping> concate with contant(give value "985" in properties)>target.

Cheers!

Samarjit

Former Member
0 Kudos

Hi Claes,

Use the Fix Mapping as shown

1.Source(concatned 4 source)->Fix/value Mapping(concatned 4 source+985)>(substring)--->TargetNode

Regards,

Ashwin M

Reward IF helfpul

Shabarish_Nair
Active Contributor
0 Kudos

try to incorporate the sample code below in a UDF;

String splits = "a;b;c;d;XXX";

String a[] = splits.split(";");

int lenS = a.length;

System.out.println(a[lenS-1]);

The result of the above code is XXX

Former Member
0 Kudos

Hi,

Check this UDF...

String strC = "CR;+;ADJH;TD;553";

int intC = strC.lastIndexOf(";");

strC = strC.substring(intC+1);

return(strC);

Cheers!

Samarjit

Former Member
0 Kudos

Hi Claes,

1.Source(concatned 4 source)->Fix/value Mapping(concatned 4 source+985)>(substring)/ UDF--->TargetNode

If UDF

a.substring(a.lastIndexOf(";")+1);

return a;

where a is input to UDF

Regards,

Ashwin M

Reward if useful

former_member190313
Active Participant
0 Kudos

hi

i guess u have to go for udf

as substring will not work in this case

regards

Sheetal

Former Member
0 Kudos

Hi Shabarish Vijayakumar,

I'm trying this UDF that you wrote but I doesn't get it to work.

I'm quite new to UDF´s. In this example what should I use as arguments, imports? Should I use value as cache?

if a use value as cache and a as argument i get this error.

MappingTemplate_.java:356: a is already defined in Split$(java.lang.String,com.sap.aii.mappingtool.tf3.rt.Container) String a[] = splits.split(";"); ^ 1 error

Thanks for all the help.

Best Regards

Claes

former_member190313
Active Participant
0 Kudos

hi Claes

You can use global container for this purpose.

You need to write two UDFs

In first UDF , give the concatenated value as input and put it in global container ( in one variable)

In the another UDF (where you will actually perform string operations to get last value) , use this value from global container.and perfor string operations

Regards

Sheetal

Please reward points for helpful anwers

Former Member
0 Kudos

Hi Sheetal,

Can you please show me how you mean?

What should i write in the first UDF. As you have noticed I´m quite new to UDF´s.

In the second UDF I use the code that Samarjit proposed but I don't know what I should write instead of XXXXXX to get the concatenated values "into" the UDF.

String strC =

XXXXXX

;

int intC = strC.lastIndexOf(";");

strC = strC.substring(intC+1);

return(strC);

Thank you for all the help.

Best Regards

Claes

Shabarish_Nair
Active Contributor
0 Kudos

http://help.sap.com/saphelp_nw04/helpdata/en/22/e127f28b572243b4324879c6bf05a0/content.htm

that sud help u define a UDF.

From your last post i am tryin to recreate the UDF,

Create a simple UDF (Simple Functions (Cache = Value) - ref above link)

and put the code as below;

String strC = a;

int intC = strC.lastIndexOf(";");

strC = strC.substring(intC+1);

return(strC);

former_member190313
Active Participant
0 Kudos

hi Claes

In the first UDF , take input as concatenated value and place this value in global container using

setParameter (String parName, inputValue);

In the second UDF , get this value from global container in one variable

using

localVaribleName (strC in ur case) = getParameter (String parName);

use this variable for furthur manipulation and map the output of this UDF (tsrC) to your final target field

regards

Sheetal

plz reward helpful answers

Former Member
0 Kudos

Thank you so much!

That works fine.

One last question. If i want to det the second value from the end (552). How can I solv this?

CR;+;ADJ;fre;<b>552</b>;68927

Best Regards

former_member190313
Active Participant
0 Kudos

hi

use split function of java

String splits = "a;b;c;d;XXX";

String a[] = splits.split(";");

int lenS = a.length;

System.out.println(a[lenS-2]);

Regards

Sheetal

Former Member
0 Kudos

Thank you.

This solved my problem

Answers (2)

Answers (2)

former_member190313
Active Participant
0 Kudos

hi

you can use the standard function like substring , index of where in you will get the last value from the concatenated string.

if u give the exact values i will tell you the mapping

regards

Sheetal

plz reward points for helpful answers

Former Member
0 Kudos

Hi Claes,

U can use Fix Mapping for this

Key Value

SourceValue1 TargetValue1

SourceValue2 TargetValue1

SourceValue3 TargetValue1

SourceValue4 TargetValue1

In the above case whatever comes ur sourcevalue of above four Target value will only 1....As Fix Mapping allows u to have Multiple keys for the same value

Regards,

Ashwin M

Reward if helpful