Skip to Content
0
Nov 20, 2020 at 11:08 AM

mapping error in sap cpi

65 Views Last edit Nov 20, 2020 at 05:35 PM 2 rev

Hi All,

I have a small issue in the mapping where am expecting the value as 0.74 but am receiving the value as 4.99 can you help me here please.

Logic:
I have four variables like sectionID, sectionWeight ,objectWeight ,selfRating in which am checking what is the value for section ID and then dividing it by 4 or 3 or 2 as per how many times it exist then am doing a calculation with that value divide by 100 and multiplying with self rating for all the consecutive times. With that value then am dividing it by 100 and mulitpling by section weight separate.

Script:

import com.sap.it.api.mapping.*;
import java.text.*;
import java.lang.*;
import java.math.BigDecimal;
// MappingTrace trace = container.getTrace();
def void comptValues(String[] sectionID, String[] sectionWeight, String[] objectWeight, String[] selfRating, Output sum8, MappingContext context){
    
	 
 // MappingTrace trace = container.getTrace();
	Double gsum8 	= 0.00;
	Double gsum9 	= 0.00;
	Double gsum10 	= 0.00;	
	Double gsum11 	= 0.00;
	Double gsectionWeight8 = 0.00;
	
	String weit1;
	String weit2;
	String weit3;
	String weit4;
	
	for(int i=0;i<sectionID.length;i++)
	{
		int tSectionID 		= 0; 
		Double tsectionWeight = 0.00;
		
			try
			{
				tSectionID = Integer.parseInt(sectionID[i]); 
			}
			catch(Exception e)
			{
				tSectionID = 0;
			} 	
			
			try
			{
				tsectionWeight = Double.parseDouble(sectionWeight[i]);
			}
			catch(Exception e)
			{
				tsectionWeight = 0.00;
			}
			
				if (tSectionID == 8)
					{
						gsectionWeight8 = 	tsectionWeight;
						weit1 = '1';
					} 
				
				else if (tSectionID == 9)
					{
					 	gsectionWeight8 = 	tsectionWeight;
						weit2 = '1';
					} 		


				else if (tSectionID == 10)
					{
						gsectionWeight8 = 	tsectionWeight;
						weit3 = '1';
					}
					
				else if (tSectionID == 11)
					{
						weit4 = '1';
					}
				
	} 


// check if all 4 non objective competencies are available


    if((weit1 == '1') && (weit2 == '1') && (weit3 == '1') && (weit4 == '1'))
	{
	    gsectionWeight8 = gsectionWeight8/4;
	}
	else if((weit1 == '1') && (weit2 == '1') && (weit3 == '1'))
	{
	    gsectionWeight8 = gsectionWeight8/3;
	}
	else
	{
	    gsectionWeight8 = gsectionWeight8/2;
	}


	NumberFormat df = new DecimalFormat("#0.00");
	for(int i=0;i<sectionID.length;i++)
	{
		int tSectionID 				= 0;
		Double tObjectWeight 	= 0.00; 
		Double tsum8 			= 0.00;
		Double tsum9 			= 0.00;
		Double tsum10 			= 0.00;	
        Double tsum11 			= 0.00;		
		int tselfRating 			= 0;
		 
	 
			try
			{
				tSectionID = Integer.parseInt(sectionID[i]);
			}
			catch(Exception e)
			{
				tSectionID = 0;
			}
			 
			try
			{
				tObjectWeight = Double.parseDouble(objectWeight[i]);
			}
			catch(Exception e)
			{
				tObjectWeight = 0.0;
			}
			
			try
			{
				tselfRating = Integer.parseInt(selfRating[i]);
			}
			catch(Exception e)
			{
				tselfRating = 0;
			}
			
			if(tSectionID == 8)
			{	 
				tsum8	=	(tObjectWeight/100)*tselfRating;
				gsum8	=	gsum8 +  tsum8;  
			}
		    else if(tSectionID == 9)
		    {
		    	tsum9	=	(tObjectWeight/100)*tselfRating;
				gsum9	=	gsum9 +  tsum9;  
		    }
			else if(tSectionID == 10)
			{
		    	tsum10	=	(tObjectWeight/100)*tselfRating;
				gsum10	=	gsum10 +  tsum10;  	
			}
			else if(tSectionID == 11)
			{
		    	tsum11	=	(tObjectWeight/100)*tselfRating;
				gsum11	=	gsum11 +  tsum11;  	
			}
			
	
		}


// Calculate weight using section weight seperately	
	gsum8 = (gsum8/100)*gsectionWeight8;
	
	gsum9 = (gsum9/100)*gsectionWeight8;
	
	gsum10 = (gsum10/100)*gsectionWeight8;
	
	gsum11 = (gsum11/100)*gsectionWeight8;
		
	gsum8 = gsum8 + gsum9 + gsum10 + gsum11;
	
	sum8.addValue(""+(df.format(gsum8))) ;  
	
	  
}

Input payload is also attached.

input.txt

Do let me know please where am going wrong your input is highly appreciated.

Regards,

Sandhya

Attachments

input.txt (9.8 kB)