on 02-05-2014 2:25 AM
Hi We have target structure with Header and LineItem. But we have to populate 4 LineItems for each Header.
So i have duplicated the other 3 Line Items using 1st Line Item and is fine.
But here I would need to send a unique value for the each Line Item.
I know this can be acived through counter, but if there are many Line Items : say 1st Line Item has come for 20times and 1st duplicated LineItem should have the value of 21 and so on.
Please suggest how we can achieve this.
Hi VR,
Please follow below UDF...
/*This will come in Graphical Mapping select functions tab and maintain title as Counter and execution type as Single Values*/
Public Sting Counter(Container container) throws StreamTransformationExcwption{
GlobalContainer scontainer = container.getGlobalContainer();
Object o = scontainer.getParameter("counter");
Integer x ;
if(o == null)
{
x = new Integer(1);
scontainer.setParameter("counter",x);
}else
{
x = (Integer)o;
x = new Integer(x.intValue() + 1);
scontainer.setParameter("counter",x);
}
return x.toString();
}
Thanks,
Sreenivas
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Sreenivas,
Getting below error.
Source code has syntax error:
E:/usr/sap/XID/DVEBMGS20/j2ee/cluster/server0/./temp/classpath_resolver/Map9f4ce3b18ff611e390f0005056880005/source/com/sap/xi/tf/_CullinanMonthlyCSV_CullinanMonthlyRcvdTransactions_MM_.java:1026: ';' expected
Public Sting Counter(Container container) throws StreamTransformationException{
^
1 error
Hi V R - I don't think it's a semicolon problem.
Don't put this statement in your UDF.
"Public Sting Counter(Container container) throws StreamTransformationExcwption{"
I think sreeni might have typed it manually. I can see a typo "Sting".. it should be "String"
Just paste the below code in your UDF -
GlobalContainer scontainer = container.getGlobalContainer();
Object o = scontainer.getParameter("counter");
Integer x ;
if(o == null)
{
x = new Integer(1);
scontainer.setParameter("counter",x);
}else
{
x = (Integer)o;
x = new Integer(x.intValue() + 1);
scontainer.setParameter("counter",x);
}
return x.toString();
Hi Sreenivas,
No, in Source structure its a file with only detail records only i.e.file is CSV file.
From that we are generating each Header with multiple Line Items,
Strcture in Mapping as below :
In the above structure, Line Items will come more than once, so here if i give index or count for 1st line Item then only the related Line Items are gincrementening no the other Line Items in the same header.
Please help
i think this should fix your issue -
Go with the UDF suggested by Sreeni for counter field..
in addition when you map the detail field use the below UDF-
GlobalContainer scontainer = container.getGlobalContainer();
Object o = scontainer.getParameter("counter");
Integer x ;
x = new Integer(0);
scontainer.setParameter("counter",x);
for(int i=0;i<var1.length;i++)
{
result.addValue("");
}
Hi - No it should work.
Did you check the screenshot which i provided? is that not what you are expecting.
steps :
Map the UDF provided by Sreeni to your sequence number field
map my udf from source detail - target detail (only first detail segment)
for the other 4 duplicated details map directly. don't use UDF
don't change anything in the UDF. especially the name "counter" should be same in both the UDF's
modified------
That UDF doesn't do anything to your queue.. it just reset the counter to "0".
Give a try and let me know...
If you are really worried, add the below lines in your existing UDF.. but make sure you add these lines only for first instance of line item
GlobalContainer scontainer = container.getGlobalContainer();
Object o = scontainer.getParameter("counter");
Integer x ;
x = new Integer(0);
scontainer.setParameter("counter",x);
Message was edited by: Hareesh Gampa
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
85 | |
10 | |
10 | |
9 | |
6 | |
6 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.