cancel
Showing results for 
Search instead for 
Did you mean: 

Need UDF to concat 4 inputs of variable length

Former Member
0 Kudos

Hi Experts,

I have a requirement where i need to concat 4 fields as an input to get the desired reuslt.

Input1- fix length

Input2 - fix length

Input3- Variable length

Input4- Variable length.

I want the desired output of input3 to be of length 10 and and of input4 to be of length 18.

If the length is less than the desired output it should add spaces in the end.

For eg;

Input1-3300

Input2-01

Input3-JPOW

Input4-SEMISOFT COAL

Than utput need to be 330001JPOW      SEMISOFT COAL   

Can you please suggest how to achieve this?

Accepted Solutions (1)

Accepted Solutions (1)

engswee
Active Contributor
0 Kudos

Hi Chandrabhan

Check out the last UDF listed in the following article on padding trailing spaces.

For concatenation of the 4 values, you can just use the + operator.

Rgds

Eng Swee

Answers (2)

Answers (2)

Former Member
0 Kudos

Thanks Eng,

The logic worked for me .

Harish
Active Contributor
0 Kudos

Hi,

Try the below UDF

input - input field

length - what length you need

int l = Integer.parseInt(length);

int itf = 0;

if(input.length<l)

{

itr = l - input.length;

for(int i=0;i<itr;i++)

{

input = input + " ";

}

}

return input;

Check the syntax as I did not wrote the code in editor.

regards,

Harish