cancel
Showing results for 
Search instead for 
Did you mean: 

split the message in the message maping

RameshGulipall
Active Participant
0 Kudos

Hi All,

In my scenario mapping problem i.e source field is Account name and my target fields are Name1 and Name2.

If the Account Name is greater than 35 chars long it should be split over Name1 and Name2 fields.pls gudie me , how to split the message in the message maping.

Thanks and Regards,

Ramesh

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

Can u please give in detail if the length is greater than 35 characters,how do u wan the account name to be split as name1 and name2.U didnt specify the separator depending on which the name has to be split.

cheers

jithesh

RameshGulipall
Active Participant
0 Kudos

Hi jithesh,

If Account name is more than 35 Chars ,it can split as the name to be split as name1 and name2.

my target fields are name1 and name2 it can store only 35 chars only each name1 and name2.

split based on the size of account name.

thanks

ramesh

Former Member
0 Kudos

Ramesh,

If the requirement is first 35 chars of account name has to go Name1 and rest to name2,then you can use SUBSTRING function in the message mapping.

I hope it helps.

Thanks,

Joslyn.

bhavesh_kantilal
Active Contributor
0 Kudos

Ramesh,

Write 2 UDF's. Both will take the input as the Account Name.

First UDF, check if AccountName lenght is less than 35 , if yes, output it as such and map it to NAME1. Else, Split it to get 1st 35 charcters.

Second UDF, check if AccountName length is greater than 35 , Split it to get the charcters after 35 charcters and output it else, output a Blank String.

Regards,

Bhavesh

RameshGulipall
Active Participant
0 Kudos

Hi Joslyn,

Thanks for reply.

I done maping like this

1)Accountname--->substring-->name1 in this case i set substring starting postion is 0 and ending postion is 35.

2)Accountname->Substring-->name2 in in this case i set substring starting postion is 35 and ending postion is 70.

While testing map i got Runtime Mapping Exception.

Error is like this.

RuntimeException in Message-Mapping transformation: Runtime exception during processing target field mapping /ns0:target_fl_MT/name1. The message is: Exception:[java.lang.StringIndexOutOfBoundsException: String index out of range: 35] in class com.sap.aii.mappingtool.flib3.TextFunctions method substring[asdfghj, com.sap.aii.mappingtool.tf3.rt.Context@41b0ca]

pls help me this

Thanks,

ramesh

RameshGulipall
Active Participant
0 Kudos

HI Bhavesh,

Thanks for reply.

If u do not mind pls send the java code for this UDF.it will be usefuly .

pls help me .

Thaks,

ramesh

stefan_grube
Active Contributor
0 Kudos

> 1)Accountname--->substring-->name1 in this case

> se i set substring starting postion is 0 and ending

> postion is 35.

> 2)Accountname->Substring-->name2 in in this

> is case i set substring starting postion is 35 and

> ending postion is 70.

        Accountname
                    concat - substring(0,35) - trim - name1
constant(35 spaces)/

        Accountname
                    concat - substring(35,35) - trim - name2
constant(70 spaces)/

Regards

Stefan

bhavesh_kantilal
Active Contributor
0 Kudos

Just saw Stefan's Answer..

Guess it is a simpler way to do it coz u can avoid coding , but, maintaining a constant with exact spacing can sure be a problem

Nice to see a Solved Problem.

Regards,

Bhavesh

Answers (3)

Answers (3)

bhavesh_kantilal
Active Contributor
0 Kudos

Ramesh,

Assume a is the input parameter,

<b>UDF 1,</b>

int len=a.length();
String Name1="";
if(len>35){
Name1=a.substring(0,34);
}
else{
Name1=a;
}
return Name1;

<b>UDF2:</b>

int len=a.length();
String Name2="";
if(len>35){
Name2=a.substring(35,len-1);
}
else{
Name2="";
}
return Name2;

Regards,

Bhavesh

RameshGulipall
Active Participant
0 Kudos

Hi Bhavesh,

Thanks for your reply.i got out put.

Thanks

ramesh

henrique_pinto
Active Contributor
0 Kudos

Just some comments on Bhavesh solution:

> int len=a.length();

> String Name1="";

> if(len>35){

> Name1=a.substring(0,34);

> }

> else{

> Name1=a;

> }

> return Name1;

if you use substring(0, 34), you will get only the first 34 characters of the string. You need to use (0, 35).

Regards,

Henrique.

bhavesh_kantilal
Active Contributor
0 Kudos

Hi Henrque,

Bulls eye

Regards,

Bhavesh

RameshGulipall
Active Participant
0 Kudos

Hi ALL,

any help for java UDF.

thanks

Ramesh

henrique_pinto
Active Contributor
0 Kudos

Use substring method (not substring standard function) in UDF, like this:

UDF1 (String input is the input parameter):

if (input.length() > 35) {

return input.substring(0, 35);

}

return input;

UDF2:

if (input.length() > 35) {

return input.substring(35);

}

return null; // or return ""; , depending on your need

Regards,

Henrique.

Former Member
0 Kudos

Hi,

Can u please give in detail if the length is greater than 35 characters,how do u wan the account name to be split as name1 and name2.U didnt specify the separator depending on which the name has to be split.

cheers

jithesh