on 02-03-2010 10:46 AM
Hi all,
is there any way to develop a counter customer function in a graphical message mapping so every context change of a field the counter initializes?
Imagine i have the following structure:
1 DATA
1.1 DETAIL
1.2 DETAIL
2 DATA
2.1 DETAIL
2.2 DETAIL
[...]
and i wanna count DETAIL fields but initialize the counter every DATA field. Is there any way to do it?
Thanks a lot.
Hi,
If your Source structure is
<?xml version="1.0" encoding="UTF-8"?>
<ns0:MT_DATA xmlns:ns0="http://yash.com.YH1309">
<DATA>
<DETAIL/>
<DETAIL/>
</DATA>
<DATA>
<DETAIL/>
<DETAIL/>
<DETAIL/>
</DATA>
</ns0:MT_DATA>
and You want the Target as
<?xml version="1.0" encoding="UTF-8"?>
<ns0:MT_DATA xmlns:ns0="http://yash.com.YH1309">
<DATA>
<DETAIL>COUNTER=1</DETAIL>
<DETAIL>COUNTER=2</DETAIL>
</DATA>
<DATA>
<DETAIL>COUNTER=1</DETAIL>
<DETAIL>COUNTER=2</DETAIL>
<DETAIL>COUNTER=3</DETAIL>
</DATA>
</ns0:MT_DATA>
Create the below UDF with one argument (DETAIL) and select Execution type all values of a Context
for (int i =1;i<=DETAIL.length;i++)
{
result.addValue("COUNTER=" + i);
}
but if you want Your Target as
<?xml version="1.0" encoding="UTF-8"?>
<ns0:MT_DATA xmlns:ns0="http://yash.com.YH1309">
<DATA>
<DETAIL>1</DETAIL>
<DETAIL>2</DETAIL>
</DATA>
<DATA>
<DETAIL>1</DETAIL>
<DETAIL>2</DETAIL>
<DETAIL>3</DETAIL>
</DATA>
</ns0:MT_DATA>
So please Follow abhishek salvi's reply
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Ok, this is what i did:
UDF - Execution Type: All values of a context
public void counterContext(String[] CONTEXT, String[] ELEMENT, ResultList result, Container container) throws StreamTransformationException{
for (int i =1;i<=CONTEXT.length;i++)
{
for (int j = 1; j<=ELEMENT.length;j++)
{
result.addValue(j);
}
}
}
And it's working perfect!
Thank you very much for your help.
Use function Statistic- Count for mapping Detail.
Also change the Context leve of Detail for Header.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Well, maybe i didn't explain what i want to achieve properly.
If i have this message:
...DATA
......DETAIL
......DETAIL
......DETAIL
...DATA
......DETAIL
......DETAIL
i want to convert it as follows:
...DATA
......DETAIL = COUNTER = 1
......DETAIL = COUNTER = 2
......DETAIL = COUNTER = 3
...DATA
......DETAIL = COUNTER = 1
......DETAIL = COUNTER = 2
What is happening now is this:
...DATA
......DETAIL = COUNTER = 1
......DETAIL = COUNTER = 2
......DETAIL = COUNTER = 3
...DATA
......DETAIL = COUNTER = 4
......DETAIL = COUNTER = 5
is any way to create a counter that initializes it's starting value every context change?
Thank you in advance!
Use function index. No UDF required.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Roger,
Try using this udf:
UDF should be an advanced one and shoudl for all values in a context
Provide Details as the input to this udf
int counter=0;
for (int i=0;i<input.length;i++)
result.addValue(counter++);
Regards
Suraj
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
81 | |
10 | |
10 | |
9 | |
7 | |
6 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.