on 11-16-2005 6:39 PM
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.
Hi,
How about using concat standard function and using space as delimiter.
Hope it helps.
Regards,
Satish
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
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
User | Count |
---|---|
91 | |
10 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.