Skip to Content
avatar image
Former Member

Need UDF to concat 4 inputs of variable length

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?

Capture.PNG (2.2 kB)
Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

3 Answers

  • Best Answer
    Jun 03, 2015 at 08:26 AM

    Hi Chandrabhan

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

    UDF Basic Building Block

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

    Rgds

    Eng Swee

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Jun 03, 2015 at 10:17 AM

    Thanks Eng,

    The logic worked for me . 😊

    Add comment
    10|10000 characters needed characters exceeded

  • Jun 03, 2015 at 08:25 AM

    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

    Add comment
    10|10000 characters needed characters exceeded