cancel
Showing results for 
Search instead for 
Did you mean: 

Mapping question - How to pad data field with blanks

Former Member
0 Kudos

My structure is defined with a specific length ex:

Item 1:unbounded

str1 length 10 type-string

str2 length 5 type- string

I'm mapping str1 and str2 to result field (target) of length 40. If my data in str1 is ABC and str2 123, I would like to to retain the specified length and map it as "ABC 123 "

I have this requirement for all the fields in rather a lengthy structure. Any idea on how I can accomplish this via message mapping object.

Thanks.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

How about using concat standard function and using space as delimiter.

Hope it helps.

Regards,

Satish

Former Member
0 Kudos

Satish, the input value is a variable...it can be 123 or 1245 and therefore I will not know how many blanks to pad with. I'm hoping to avoid tedious process here. I have over 80 fields with similar requirements. I'm hoping XI has std. solutions for such requirements.

Any ideas?

Former Member
0 Kudos

Hi Parimala,

I don't think there is any standard function do this...

But you can write user defined function to do this.

Take the same example with two fields.

Field1 max. length 10

Field2 max. length 5

Take a case where your input is less than max length.

Field1 = 123456 (length = 6 < 10)

Field2 = 123 (length = 3 < 5)

Define a user defined function with 2 parameters

1. Field

2. max. length of field

in your user defined function get the length for the input field (actual length)

To pad the missing spaces just

loop starting from actual length till max length and keep adding spaces with in the loop.

In mapping editor..

Pass field1 and field2 sperately to this user defined function and pad the spaces.

Then you can use standard concat function to concatenate field1 and field2.

field1->userdefinedfunction(output1)

field2->userdefinedfunction(output2)

concat(output1 and output2)->target.

Refer the link for right padding.

or define a simple user defined function with 2 inputs

a - input field

b - maxlength

Code...

while( a.length() < Integer.parseInt(b)){

a = a + " ";

}

return a;

Regards

Anand

Message was edited by: Anand Torgal

Former Member
0 Kudos

Thank you for your reply.

I ended up creating padWithBlanks function witht the following code:

String newStr = "";

String tmp = "";

int bLen = Integer.parseInt(b);

int aLen = a.length();

int newLen = bLen - aLen;

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

tmp = tmp.concat(" ");

newStr = a.concat(tmp);

return newStr;

You probably would have done this in 3 lines

Former Member
0 Kudos

while( a.length() < Integer.parseInt(b)){

a = a + " ";

}

return a;

You can use this code it does the same.

Anand

Answers (0)