cancel
Showing results for 
Search instead for 
Did you mean: 

Count issue in mapping sap cpi

former_member229127
Participant
0 Kudos

HI Guys,

I need to implement a logic in an interface where below is the logic:
we need to check how many times a empld is repeating and count the amount. For an example in the file the price is different so we need to count and send the output as 15000.

i have written the logic like below but am not getting the expected result can you help me please where am going wrong.

import com.sap.it.api.mapping.*;
def void countValues(String[] EmpID, String[] Price, Output resPrice, MappingContext context){
int gPrice = 0;
boolean flag = false;
for(int i=0;i<EmpID.length;i++)
{
int tEmpID = 0;
int tPrice = 0;
try
{
tEmpID = Integer.parseInt(EmpID[i]);
}
catch(Exception e)
{
tEmpID = 0;
}
try
{
tPrice = Integer.parseInt(Price[i]);
}
catch(Exception e)
{
tPrice = 0;
}
// Price Logic
if(tEmpID == )
{
gPrice = tPrice;
flag = true;
}
if(flag==true)
{ break;
}
}
for(int i=0;i<EmpID.length;i++)
{
int tEmpID = 0;
int tPrice = 0;
//int tPrice = 0;
try
{
tEmpID = Integer.parseInt(EmpID[i]);
}
catch(Exception e)
{
tEmpID = 0;
}
try
{
tPrice = Integer.parseInt(Price[i]);
}
catch(Exception e)
{
tPrice = 0;
}
// sectionWeight Logic
if(tEmpID == )

{
resPrice.addValue(""+tPrice);
}
}
}

Regards,
Sandhya

yatanveersingh
Active Participant
0 Kudos

HI Sandhya,

I believe you are reading a file, so once the CPI process reads the file, it might come up as XML, is my understanding right ?

Yatan

former_member229127
Participant
0 Kudos

Hi yatanveersingh ,

Yes your understanding is correct and we will read it as XML file and this logic am handling in message mapping.

Regards,

Sandhya

yatanveersingh
Active Participant
0 Kudos

can you post the XML you are getting and what is your requirement. You can use groovy, javascript, XSLT to get the data you want.

former_member229127
Participant
0 Kudos

Hi yatanveersingh,

I have attached the input payload in the form of xml and yes am using udf in the mapping but am not able to achieve it can you please check the code which i have written and let me know where am going wrong.
file.txt

Regards,
Sandhya

Accepted Solutions (0)

Answers (3)

Answers (3)

yatanveersingh
Active Participant

Hi Sandhya,

" Check how many times a empld is repeating and count the amount"

Inside the contentmodifier use property and use the below 2 xpath

count of empid = count(/root/row/EmpID)

count the amount = sum(/root/row/Price)

Yatan

former_member229127
Participant
0 Kudos

Hi yatanveersingh ,

Can i know how we can count the amount through Content Modifier.

Please can you explain me something more.

Regards,
Sandhya

yatanveersingh
Active Participant
0 Kudos

If you use the content modifier after you read the file, the XML data will go as body to the content modifier, inside content modifier we are using xpath to count and add the values in xml and updating the value in the property variable, this property variable you can use later in your process.

former_member229127
Participant
0 Kudos

HI yatanveersingh ,

Thanks for this ! but in my requirement there will be multiple empld so i need to group them at a place and then count the price value how it is possible for this in content modifier for an example i have attached the source file.
file.txt
Regards,
Sandhya

yatanveersingh
Active Participant
0 Kudos

what are you doing in your iflow, can you show.

former_member417122
Discoverer
0 Kudos

mm.jpgHi Sandhya,

If you are using Mapping you could use standard mapping functions to achieve this. If i understood correctly you want to send total price value on target side? something like this ?

Sriprasadsbhat
Active Contributor
0 Kudos

Hello Sandya,

Please share the expected output also so that its easy to suggest some solution.

Regards,

Sriprasad Shivaram Bhat