cancel
Showing results for 
Search instead for 
Did you mean: 

mapping requirement about grouping with restriction

Former Member
0 Kudos

Hi,experts:

There is a complex mapping requirement.

There are 2 document types(A and B) in the source records.

I need collect the amount with the document which is type A.

The source records are as follows:

Doc_No Doc_Type Doc_Itm_No Amount

0001 A 0010 3

0001 A 0020 4

0002 B 0010 5

0002 B 0020 6

0003 A 0010 11

0003 A 0020 22

The target records should be:

Doc_No Doc_Type Amount

0001 A 7

0003 A 33

The source and the target data type are the same as follows:

Documents 1...unbound

---Doc_No 1...1

---Doc_Type 1...1

---Doc_Itm_No 1...1

---Amount 1...1

Q1: How to create the target top node(Documents) with restriction(Doc_Type = 'A')?

Without the restriction,i can handle it well as follows:

removecontext(Doc_No)->sort->splitbyvalue(value changed)->collapsecontexts->Documents

Q2:How to collect the amount?

Regards

Ming

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

hi ming,

do this mapping

Q1: How to create the target top node(Documents) with restriction(Doc_Type = "A")?

Doc_type-->(if equals "A")


>(remove context)-->(createif)----->Documents

q2. How to collect the amount?

Doc_type(Documents context) + Amount(Document's context)--->UDF1>(SplitByValue)->Doc_type

Doc_type(Documents context) + Amount(Document's context)--->UDF2>(SplitByValue)-->Amount

//****************************UDF1***********************//

public void get_batch_name(String[] Doc_type,String[] Amount,ResultList result,Container container){

//write your code here

Hashmap myHashmap=new Hashmap();

for(int i=0; Doc_type.length(), Amount.length())

{

if(myHashmap.get(Doc_type<i>==null))

{myHashmap.add(Doc_type<i>, Amount<i>);}

else

{

String amt= amt+myHashmap.get(Doc_type<i>);

myHashmap.put(Doc_type<i>,amt);

}

}

Set s=myHashmap.keySet();

Iterator i=s.iterator();

while(i.hasNext())

{

result.addValue(i.next());

}

}

//********************UDF2***************************//

public void get_batch_name(String[] Doc_type,String[] Amount,ResultList result,Container container){

//write your code here

Hashmap myHashmap=new Hashmap();

for(int i=0; Doc_type.length(), Amount.length())

{

if(myHashmap.get(Doc_type<i>==null))

{myHashmap.add(Doc_type<i>, Amount<i>);}

else

{

String amt= amt+myHashmap.get(Doc_type<i>);

myHashmap.put(Doc_type<i>,amt);

}

}

Arraylist s=myHashmap.values();

String array[]=s.toArray();

while(int i=0;i<array.length();i++)

{

result.addValue(array<i>);

}

}

Message was edited by: self

sudeep dhar

Former Member
0 Kudos

Hi,sudeep:

About Q1,your solution doesn't work fine.

For example(Attention to the number of records):

The source records are as follows:

Doc_No Doc_Type

0001 A

0001 A

0002 B

The target records should be:

Doc_No Doc_Type

0001 A

Base on my current mapping about the top node "Documents":

<b> removecontext(Doc_No)->sort->splitbyvalue(value changed)->collapsecontexts->Documents</b>

i can get the target records as follow:

Doc_No Doc_Type

0001 A

0002 B

But you know,i want to add the restriction(Doc_Type = 'A').

After adding the restriction that you did above as follows:

<b> removecontext(Doc_No)->sort->splitbyvalue(value changed)->collapsecontexts->exists

and

Doc_Type->(if equals 'A')->remove context

and->createif->Documents</b>

But the targets records are as follow:

Doc_No Doc_Type

0001 A

0002 B

It seems that there is sth wrong with the synchronization between Doc_No and Doc_Type.

Regards

Ming

Former Member
0 Kudos

hi ming,,,

regarding Q1, do the following

Doc_type(Documents context) + Amount(Document's context)--->UDF1>(remove context)->Document

try this.....and query further

Former Member
0 Kudos

Hi,sudeep:

I solved the issue by the standard function as follows:

1 removecontexts(Doc_No) and removecontexts(Doc_Type) ->SortByKey

2 removecontexts(Doc_No)->sort->splitbyvalue(value changed)

1 and 2->formatByExample->collapseContexts->(if Doc_Type = 'A')->createif->Documents

Anyway,thank you very much for your help.Points are rewarded.:-)

Regards

Ming

Former Member
0 Kudos

thanks ming.......

Answers (0)