cancel
Showing results for 
Search instead for 
Did you mean: 

counter value for LineItem duplication

former_member193466
Participant
0 Kudos


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.

Accepted Solutions (1)

Accepted Solutions (1)

former_member191435
Contributor
0 Kudos

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

former_member193466
Participant
0 Kudos

Hi Sreenivas,

The above code is not working..

Do I need to give any input for this? if so what can I give in this case.

Kindly let me know on this.

former_member191435
Contributor
0 Kudos

Hi VR,

Can you please take the rootnode and use this udf ---> then split by each value---> target field.

If it is still not working please let me know....

Thanks,

Sreenivas

former_member193466
Participant
0 Kudos

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

former_member191435
Contributor
0 Kudos

can you please paste your udf here...

There is a semicolon prob in the udf that u r using....

Thanks,

Sreenivas

former_member184720
Active Contributor
0 Kudos

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();

former_member193466
Participant
0 Kudos

Hareesh/Sreenivas,

Its amazing worked..

but when there is second Header it should start with 1 for first Line Item in that Header.

It means I have to control the values based on Headers.

can you please let me know how can I restrict?

former_member191435
Contributor
0 Kudos

can you please let me know... the output that you required..

header --1

detail --1

detail--2

detail --3

then header-2

detail ---?

please clarify

former_member193466
Participant
0 Kudos

Yes Sreenivas...

Header-->1st Header
detail --1

detail--2

detail --3

Header --> 2nd Header

detail --1

detail --2

detail --3

detail --4

and so on.....

former_member191435
Contributor
0 Kudos

then not require UDF...

Please do below mapping.... it will work...

Thanks,

Sreenivas

former_member184720
Active Contributor
0 Kudos

are you not getting this output if you use standard "counter" function. I believe you should get it.

can you show the input &output xml?

former_member191435
Contributor
0 Kudos

Hi Hareesh,

I dont think so it will work with counter function.... Index function will do that....

Thanks,

Sreenivas Veldanda.

former_member193466
Participant
0 Kudos

No Sreenivas and Hareesh..

Counter and Index are giving same result in this case which are not expected...

I believe this can be done by the UDF provided by you,,but that counter value to be reset based on the header repeats..can you pls help me out...

below is the result I got with Index:

former_member191435
Contributor
0 Kudos

Hi VR,

Please check this

former_member193466
Participant
0 Kudos

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

former_member184720
Active Contributor
0 Kudos

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("");
}

former_member193466
Participant
0 Kudos

Hareesh,

Sorry, again the same result is giving..for other Headers --> LineItems are not starting with 1.

can you please tell me if I can change the counter UDF provided by Sreeni..

Thank you.

former_member184720
Active Contributor
0 Kudos

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

former_member193466
Participant
0 Kudos

No Hareesh, I cannot add the UDF as I am already using differet UDF to produce LineItems for each Header.

former_member184720
Active Contributor
0 Kudos

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

former_member184720
Active Contributor
0 Kudos

btw..I don't know why the line items are created based on header..

if it doesn't help please share all the details..

your sender structure

target structure

condition to create to each field like header/line items..

It would be very difficult to suggest a solution without having proper details..

former_member193466
Participant
0 Kudos

Hareesh..Thanks alot..its worked out..

Have put the reset of the container UDF for the last line item..

It ws working fine..really Thanks alot Sreeni Hareesh..

Answers (1)

Answers (1)

former_member184720
Active Contributor
0 Kudos

Hi V R - As you have confirmed that you are on 7.0 you can still use global container.

So below blog should be helpful.

Message was edited by: Hareesh Gampa

former_member193466
Participant
0 Kudos

Hi Hareesh, I had gone through the thread but got no idea on how to use it.

if we create any UDF, it is asking for some input. can you please elaborate me on this.

former_member184720
Active Contributor
0 Kudos

As shown below, you can delete the Arguments while creating UDF. This way it doesn't ask for any input paramters.

former_member193466
Participant
0 Kudos

Hareesh, but it is not giving the values as expected, can you please provide me the UDF for this.

Thank you.