cancel
Showing results for 
Search instead for 
Did you mean: 

UDF help

Former Member
0 Kudos

Hi XI gurus,

I am not an expert with JAVA programming so I'm having this problem regarding the UDF that I need to create. I need to group transactions according to 2 different fields. For example:

Source

Material Price Date

Cotton 1.00 02-28-11

Wood 5.50 01-08-11

Metal 10.0 01-25-11

Cotton 1.00 01-25-11

Wood 5.50 01-25-11

I need to group the transactions that have equal Material and Price.

Output should be:

Idoc1

Cotton 1.0 02-28-11

Cotton 1.0 01-25-11

Idoc2

Wood 5.50 01-08-11

Wood 5.50 01-25-11

Idoc3

Metal 10.0 01-25-11

Is this possible via UDF?

Any help would be greatly appreciated. Thanks!

Accepted Solutions (1)

Accepted Solutions (1)

rajasekhar_reddy14
Active Contributor
0 Kudos

First you have to write logic for IDoc segment like below.

material>removecontext->sort>splitby value(valuechange)->collapsecontect---->IDoc.

This logic will genarate one IDoc same material,like multiple IDocs for Multiple different materials.

Regards,

Raj

Former Member
0 Kudos

Hi Raja, how will i proceed with the Price field? I need to group the transactions based on Material and Price. If the Material and Price are the same, the transactions will be grouped to create one idoc. in the samples that you gave, only the Material was used..

Former Member
0 Kudos

Hi,

Concatenate Material and price and then use the above logic for sorting.

So, ur mapping will be like :

material-->removecontext

concat->sort>splitby value(valuechange)->collapsecontect-->IDoc.

price-->removecontext

Regards

Edited by: Shiladitya Sarkar on May 23, 2011 7:09 AM

Former Member
0 Kudos

hi,

material>removecontext->sort>splitby value(valuechange)->collapsecontect---->IDoc is not working

if i check display queue, yes the output is correct. cotton cotton wood wood metal.

but when i'm using the test tab, the order of the idoc is still the same. cotton wood metal cotton wood.

i need to sort the whole idoc, not just the value of the material.

Former Member
0 Kudos

Hi

For the child fields use this function

valueKeyQueue - should be material

valueQueue - should be for example price or date

valueQueue - this entire structure material>removecontext->sort>splitby value(valuechange)->collapsecontect---->I

don't forget splitByValue after the call to the UDF


public static void findValuesByKeysForSearchKeys(String[] valueKeyQueue, String[] valueQueue, String[] searchKeyQueue, ResultList result) throws StreamTransformationException{
		for (int i = 0; i < searchKeyQueue.length; i++) {
			// Is the current entry a context change?
			if (searchKeyQueue<i>.equals(ResultList.CC)) {
				// add the context change itself to the result queue
				result.addValue(searchKeyQueue<i>);
			} else {
				// find the value in the valueQueue
				boolean found = false;
				int j = 0;
				while (j < valueKeyQueue.length && !found) {
					if (valueKeyQueue[j].equals(searchKeyQueue<i>)) {
						found = true;
						if (j<valueQueue.length)
							result.addValue(valueQueue[j]);
						else
							result.addValue("");
					} else {
						j++;
					}
				}

				if (!found) {
					result.addValue("");
				}
			}
		}
	}

Answers (1)

Answers (1)

baskar_gopalakrishnan2
Active Contributor
0 Kudos

you can use standard function to achieve this.

examples field ---> removecontext --> sort ---> splitbyvalue(value change) -> idoc1 like that.

Former Member
0 Kudos

I agree with Baskar!

As Baskar said to me some times ago, try to use standard function anytime (if is

possible)

Former Member
0 Kudos

this can be done if i'm sorting just 1 field. in this case, i'm sorting 2 fields to group the transactions to create multiple idocs.