on 07-05-2012 12:18 AM
Hi,
We have a source field Phone Number with the format
+CCCCC-AAAAA-PPPPPPPPPPPPPPPPPPPP+EEEEEEEEEE
CCCCC = optional country code with + as delimiter in the beginning (Max 5 length)
AAAAA = Area code (Max 5 length)
PPPPPPPPPPPPPPPPPPPP = Phone Number (Max 20 length)
EEEEEEEEEE = Optional extension (Max 10 length) with + as delimiter
On the target structure, we have three fields Area code, Phone number and extension. Country code doesn't need to map. Can we do this single UDF? or do we need three different UDFs?
Sample java code for UDF(s) would be very helpful.
Regards,
N@vin
Hi Navin,
If I got that right, since the country code and extension parts are optional, the input to the function when they are missing, can be: AAAAA-PPPPPPPPPPPPPPPPPPPP
If so, here is the UDF that produces four outputs:
for (int i = 0; i < input.length; i++) {
if (! input.equals(ResultList.CC)) {
String[] tokens = input[i].split("-");
if (tokens.length == 2) { //no country code part
countryCode.addValue("");
areaCode.addValue(tokens[0]);
String[] tokens2 = tokens[1].split("\\+");
if (tokens2.length == 1) {
phoneNumber.addValue(tokens[1]);
extension.addValue("");
}
else {
phoneNumber.addValue(tokens2[0]);
extension.addValue(tokens2[1]);
}
}
else { //country code found
countryCode.addValue(tokens[0].replace("+",""));
areaCode.addValue(tokens[1]);
String[] tokens2 = tokens[2].split("\\+");
if (tokens2.length == 1) {
phoneNumber.addValue(tokens[2]);
extension.addValue("");
}
else {
phoneNumber.addValue(tokens2[0]);
extension.addValue(tokens2[1]);
}
}
}
else {
countryCode.addContextChange();
areaCode.addContextChange();
phoneNumber.addContextChange();
extension.addContextChange();
}
}
Regards,
Greg
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
hi NAvin ,
that is a simmple by using standard functions "subString" and "concat"and also use udf by posted earlier poster
if you need any mapping example , you need to provide exatly example input and output values.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Greg,
Thanks for the code. I will try the mapping logic provided by you. It has to map three different fields on the target side.
You are right that country code and extension are optional. Not only that, length of each field is also varying.
Baskar - Considering above two requirements, please let me know if I can still use standards functions and achieve this.
Regards,
N@v!n
Hi Greg,
Thanks for the code. There is requirement where output of phoneNumber (3rd output from UDF) needs to be mapped to two different fields with first 3 numbers to phone prefix and last 4 numbers to line numbers. e.g., 4567890; 456 should go to one target field phone prefix and 7890 should go to another target field line number.
When I do substring (0,3) of 3rd output from UDF to phone prefix, it works fine. However I can't do substring (3,4) to send last 4 digits to line number. Can see if you can do substring of 3rd output form UDF and map it to two target fields?
Regards,
N@v!n
>When I do substring (0,3) of 3rd output from UDF to phone prefix, it works fine. However I can't do substring (3,4) to send last 4 digits to line number. Can see if you can do substring of 3rd output form UDF and map it to two target fields?
Are you using substring standard function or using substring in java string class? If you use substring standard function then do as follows..
for the first three numbers use substring (0,3) start position o character count 3
for the next four numbers use substring (3,7) start position 3 charater count 4
You can use simple standard function substring to extract each field from the source phone format string. You really don't need UDF. If you need UDF, then use the same substring method.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
78 | |
10 | |
9 | |
7 | |
6 | |
6 | |
5 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.