cancel
Showing results for 
Search instead for 
Did you mean: 

How to write UDF for the below logic

Former Member
0 Kudos

Hi experts,

I need to write a UDF function for the following Requirement. Kindly help me in this pls.

My Conterxt Structure will Contain Five Diffrent Context and Each will contain number of context.In target side we are having Five Field.

We need to map the Context value to this Five Fields.

Regard's

Preethi.

Accepted Solutions (1)

Accepted Solutions (1)

ambrish_mishra
Active Contributor
0 Kudos

Hi Preethi,

Try this,

Pass this queue to collapseContext, then use a UDF...with additional parameter(fieldIndex) as below:

fieldIndex is actually the field number you want to populate. It will be a constant with values 1 to 5... use the same UDF for all 5 fields, Just change fieldIndex from 1 to 5.

int index = Integer.parseInt(fieldIndex[0]);

for (int i=0; i<input.length;i++)

     if (index == i+1)

          result.addValue(input[i]);

I have just written an un-compiled code but this should work.

Hope it helps!

Ambrish

Former Member
0 Kudos

Hi Ambrish,

Thanks for your valuable Answer. Using this Only i can map the First value of the each context. For next value also the mapping should take place. Whether we need to gine all the values in the Queue.

Regard's

Preethi.

markangelo_dihiansan
Active Contributor
0 Kudos

Hello,

Thank you for the response. copyValue would not work in your case. Would you like to share the target structure so that we could visualize it?

Regards,

Mark

Former Member
0 Kudos

Hi Mark,

Here i have Attached MY target structure.

Preethi.

markangelo_dihiansan
Active Contributor
0 Kudos

Hello Preethi,

This is how I did it (version PI 7.11), not the cleanest but it should give you an idea:

1. Declare variables under attributes and methods:

2. Declare a two UDFs, storeValue and GetValue:

3. Mapping for root:

4. Mapping for row and field1

It does not matter that my source structure is different. What is important is what you are passing to the UDF for storeValue has no context changes and it includes the count per context change. For field2, just change the constant to 2..field3 constant is 3 and so on...

See output:

Hope this helps,

Mark

markangelo_dihiansan
Active Contributor
0 Kudos

Hello,

Below is an optimized code in which it takes into account that you will be adding fields in the future:

StoreValue code

GetValue code

Still the same mapping for MT_Target, but for row the counting starts at 0 instead of 1, field2 is 1, field 3 is 2 and so on...

You can only test this mapping in the test tab though. Right-clicking and selecting display queue will not work.

Regards,

Mark

Former Member
0 Kudos

Hi Mark Using this UDF i can achive the first level of mapping for MT in Receiver.

But the Second level for Field and Row is getting a issue. Since My Sender Structure is

MT_TEST

Header

   inta

   intb

Also in Sender side iam using FCC.Tell me whether in FCC we can design with Record Set Name and Struture

SO that i need to get

MT_TEST

inta

intb

How to achive this in FCC. Help me.

Regard's

Preethi.

markangelo_dihiansan
Active Contributor
0 Kudos

Hello Preethi,

The structure I set is just an example. What passes through the UDF I provided is more important. Probably you could design it like this:

Root

-->Header

-----> inputB (0..unbounded)

-->Details

-----> inputA (0..unbounded)

Make sure that in the file, there is a value that distinguishes between header and detail records.

Hope this helps,

Mark

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi Amrish,

If i am putting Collapse Context before UDF i am getting only the First value of the Context.

But before doing this i need to get the first value of the Five context in One Context nad the Second Value int five contest in Another Context.

Pls kindly help me to do this Experts.

Preethi.

ambrish_mishra
Active Contributor
0 Kudos

Hi Preethi,

With collapse context, you will get the first value of each context from the source input queue.

For populating the second field, you pass constant value 2 and for third field, pass 3 and so on....

revert back else I will prototype and show it to you.

Ambrish