cancel
Showing results for 
Search instead for 
Did you mean: 

String manipulation in Mapping

Former Member
0 Kudos

Hi All,

Scenario is Idoc to file.

Source field

E1EDKT2-TDID -> Z002

E1EDKT2-TDLINE -> text.

Target field:

1.KLAGERMRK

2.LAGER

Logic:

TDLIne field value is passed to two target fields based on the below logic:

If the length of TDLINE is more than 15,truncate to 15 and pass the vhe Vaue in the text type "Z002" contains less than or equal to 15 characters: the first letter can either be "E" or " " which shoudl be mapped to KLAGERMRK field while the remaining 14 characters to the LAGER field

Note: suppose if the length of TDLINE id less than 15 (like 10) ,use the same logic as mentioned above and pass the remaining 9 characters to LARGER field.

In my mapping FOr the first logic,I have used substring and If then else function and I am able to check whether first character is E or not.

But for second logic, In substring If I mention start position as 2 and offset as 14,then if the input field value length is less than 15,it throws error.. I guess I have to calulate the length of input field dynamically and do this...

Please help me with your solution

Thanks in Advance

Regards

Kiruthi

Accepted Solutions (0)

Answers (4)

Answers (4)

Former Member
0 Kudos
But for second logic, In substring If I mention start position as 2 and offset as 14,then if the input field value length is less than 15,it throws error.. I guess I have to calulate the length of input field dynamically and do this...

You must be getting stringOutOfBound exception. Instead of substring function use this UDF:

Set var1 as the input.

int x = var1.length - 1;

if (var1.length() < 16)
{
	String var2 = var1.substring(1,x);
        return var2 ;
}
else
{
return "";
}

Hope this helps!!!

Regards

Soumen...

Former Member
0 Kudos

HI,

To decide the length of a field dynamically please use the length.

If u use the Substring function , and it happens that the length is less then u specified in the substring then it wil throw a exception.

So to avoid it, if string is str then,

if(str.length()<15)

{

// do what u want

}

else

{

// do what u want.

}

So it will nt throw exception.

I hope this will solve ur problem

Babu

stefan_grube
Active Contributor
0 Kudos

> But for second logic, In substring If I mention start position as 2 and offset as 14,then if the input field value length is less than 15,it throws error.. I guess I have to calulate the length of input field dynamically and do this...

Add a string with 15 spaces, trim after the substring function.

Former Member
0 Kudos

Hi,

You can create an udf to solve this:

>>I am able to check whether first character is E or not.

Take TDLINE as input check for the first character using indexOf() function, pass '0' as input to the index function for eg: indexOf(0).

>>In substring If I mention start position as 2 and offset as 14,then if the input field value length is less than 15,it throws error.. I guess I have to calulate the length of input field dynamically and do this

In UDF you can use substring() with passing only the start index, in your case pass str.substring(2)

Regards,

Yuga