cancel
Showing results for 
Search instead for 
Did you mean: 

Substring Function without the length!

Former Member
0 Kudos

I know I have seen this before, but cannot find it when searching.

I need to do something similar to the Substring function, where I start from position 4, but the length behind this position is variable. Due to the IDOC it only passes the value...

I think I possibly saw a UDF for this somewhere - unless I can use some standard mapping!

It is probably very simple - but it is late in the day and my eyes are square! = )

<i> I need a drink......</i>

Can anyone help?

Message was edited by:

Barry Neaves

Accepted Solutions (1)

Accepted Solutions (1)

MichalKrawczyk
Active Contributor
0 Kudos

hi Barry,

if I get it right - in your messge mapping do this:

idoc value - length function -> second parameter to substring function

(and the first will be constant 4)

Regards,

michal

Former Member
0 Kudos

Michal

I am a bit confused!

I have the mapping as:

Idoc - length - substring - target

what is "second parameter to substring function (and the first will be constant 4)"

All of this just to future proof the interface....

MichalKrawczyk
Active Contributor
0 Kudos

uuups sorry

my bad

you need a udf with two input parameter

lenght, value form idoc

int i = Integer.parseInt(lenght);

String c = valuefromIDOC.substring(4,i);

return String;

Regards,

michal

henrique_pinto
Active Contributor
0 Kudos

For substring function, you have 1 input and 2 parameters (you set the parameters by double-clicking the function box).

I also didn't understand how you can pass the output of length function two 2nd parameter of substring function (since it is a parameter and not an expected input).

You could always create a UDF...

...
public String UDSubstring(String a,String b,String c,Container container){
  int d = Integer.parseInt(b);
  int e = Integer.parseInt(c);
  if ((e == 0) && (a.length() >= d)) {
    return a.substring(d);
  }
  else if ((e > d) && (a.length() >= e)) {
    return a.substring(d, e);
  }
  else return "";
}
...

They don't bite, you know...

Regards,

Henrique.

<b>Edit:</b> followed by Michal's correction...

Former Member
0 Kudos

I guess it is getting late and/or I am being stupid - Take your pick 😛

I am mapping field VARYF from HR Infotype.

VARYF > UDF > Format Number > Target Field

I am chopping the first four characters off of VARYF (unsuccesfully despite the excellent help I am receiving from Michal and Henrique - you will be rewarded!)

I am trying to use Michal's suggestion:

public String SubstringWithoutLength(String a,String b,Container container){
int i = Integer.parseInt(6);
String c = VARYF.substring(4,i);

But I guess I am doing something wrong!

What should String A (VARYF?) and String B (Length?) be?

I assume String C is the result?

I need to go home!!!

Thanks to Michal and Henrique for your help so far!

MichalKrawczyk
Active Contributor
0 Kudos

Hi,

public String SubstringWithoutLength(String a,String b,Container container){

int i = Integer.parseInt(b);

String c = a.substring(4,i);

a - valuefromidoc

b - length from length function

Regards,

michal

Former Member
0 Kudos

Barry,

Just do like this:

Create a SubstringWithoutLength <b>VALUE</b> UDF with input parameters as 'a' and 'b'. Then add this code:

You import java.*; in the UDF

int i = Integer.parseInt(a);

String c = b.substring(4,i);

return c;

Basically you are passing the lenght in the 'a' variable and the value in the 'b' variable. In mapping you map like this:

VARYF>Lengh(Standard Function)>

VARYF--> SubstringWithoutLength --> Result

You give this two as your input paramters to your funciton. Then it should work like a BOOM.

---Satish

Answers (0)