cancel
Showing results for 
Search instead for 
Did you mean: 

need help on udf by my requirement

former_member191435
Contributor
0 Kudos

Hi folks,

I am working on file to idoc

My input file has 1 field and output Idoc has 5 records.

in my input Account field has length 16. in this length 16. this field is mapping to all the fields of output.

for example account field has 1234 67 86 34 33. I need to map 1234 to field 1

67 to field 2

86 to field 3

34 to filed 4

33 to field 5.

for every space we need to split and need to map output field. after completing this I need to sort the field 1 of output. please explain me. Account data may very

examples input file :

1238 67 86 34 33

1234 66 86 34 33

need output as 1234 67 86 34 33

1238 66 86 34 33

here only first field is sorted i.e 1234 and 1238 ....remainiing fields need to be same

ur help is highly appreciated.

Thanks,

enivass

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

Since you can have spaces any where in the file/field, use "String Tokenizer" concept, you will not need java mapping, you can use graphical mapping and write UDF by selecting "All values of the Queue/Context"

Here are some useful links:

http://java.sun.com/j2se/1.4.2/docs/api/java/util/StringTokenizer.html

http://www.javafaq.nu/java-example-code-195.html

http://www.devdaily.com/java/edu/pj/pj010006/ - Concept

http://download-llnw.oracle.com/javase/1.4.2/docs/api/java/util/StringTokenizer.html - Concept

http://www.java-examples.com/java-stringtokenizer---specify-delimiter-example - with Delimiter

Regards,

Pavan

Answers (1)

Answers (1)

former_member200962
Active Contributor
0 Kudos
for example account field has 1234 67 86 34 33. I need to map 1234 to field 1 
67 to field 2
86 to field 3
34 to filed 4
33 to field 5.

Can achieve this without UDF also

Source --> replaceString (replace space so that you now have 123467863433) --> Substring (0,3) --> Field1

Change the value of start and end position in substring and map it to the respective target fields.

Regards,

Abhishek.

former_member191435
Contributor
0 Kudos

hi Abhisekh,

thanx for ur reply.

We cant use subsctring because in input file space will come in any location it is not in perticular location. sometimes it may comes input as 12 34567 88 76 6 like this also.

thanks,

enivass

baskar_gopalakrishnan2
Active Contributor
0 Kudos

As of I know there is no list objects in UDF. so you might have to do java mapping for this case.

You have to basically create a string array using java StringTokenizer class. Once you create the array of string you can assign those values to the target fields.

// Insert the below code in your java mapping

This code does for you

String[] output;

StringTokenizer Token = new StringTokenizer("Your input string goes here");

int count=0;

while (Token.hasMoreElements()){

output [count++] = (String)Token.nextElement();

}

// After creating string array you can assign like this to the target fields

output[0] = field1

output[1] = field2

...

...

output[5] = field6

Note: Add square bracket before and after count variable in the while block. This editor removing it.