cancel
Showing results for 
Search instead for 
Did you mean: 

Query regarding mapping (aggregated)

Former Member
0 Kudos

Hi,

I need some help in mapping.

SOURCEis as below:

<E1EDP01>

<E1EDP05>

<KSCHL>ZRTP</KSCHL>

<KRATE>100</KRATE>

</E1EDP05>

<E1EDP05>

<KSCHL>ZIPP</KSCHL>

<KRATE>200</KRATE>

</E1EDP05>

</E1EDP01>

TARGET

<E1EDP01>

<E1EDP05>

<KSCHL>ZRTP</KSCHL>

<KRATE>300</KRATE>

</E1EDP05>

</E1EDP01>

target KRATE shuld be the summation of KRATE for ZRTP and ZIPP.

Please help.

regards,

Piyush

Accepted Solutions (1)

Accepted Solutions (1)

markangelo_dihiansan
Active Contributor
0 Kudos

Hello,

You can use the statistic function called sum

e.g


KRATE --> removeContext --> sum --> KRATE

Hope this helps,

Mark

Former Member
0 Kudos

Hi,

I need to do a sum only for ZRTP and ZIPP.

Rest should be passed as it is.

Former Member
0 Kudos

You can use If else conditon or write UDF to do that.

markangelo_dihiansan
Active Contributor
0 Kudos

Hello,

You can use the mapping below:


Krate --> removeContext ----------------------------> \
Krate --> removeContext --> equalsS:ZRTP --> or --> ifThenElse --> sum --> Krate
Krate --> removeContext --> equalsS:ZIPP ---> /       /
Constant: 0 ---------------------------------------> /

Hope this helps,

Mark

Former Member
0 Kudos

Hi Mark,

I have been unable to make this work.

Also would like to tell you that E1EDP01 is not the root node of the xml.

regards,

Piyush

markangelo_dihiansan
Active Contributor
0 Kudos

Hello,

What is the error that you are getting? The equalsS that is used means the equals under the text functions.

Regards,

Mark

Former Member
0 Kudos

Hi Mark,

Instead of removecontexts, I have moved the context of KSCHL and KRAT one context above.

rest I have done as you mentioned.

But the target is summing up all the KRATEs.

regards,

Piyush

markangelo_dihiansan
Active Contributor
0 Kudos

Hello,

Yup, it is summing all of the KRATES, but the ones that does not have ZIPP and ZRTP are all equated to 0. So only the ones that have these two values are getting summed.

Hope this helps,

Mark

RKothari
Contributor
0 Kudos

Hello,

You can try using the below UDF:

Make sure KRATE and KSCHL are at same context level.

int i,sum=0;

for(i=0;i<KRATE.length;i++)
{
	if((KSCHL<i>.equals("ZRTP")) || (KSCHL<i>.equals("ZIPP")))
	{
		sum = sum + KRATE<i>;
	}
}

result.addValue(""+sum);

Former Member
0 Kudos

Hi Rahul,

At which level should this UDF be used?

regards,

Piyush

RKothari
Contributor
0 Kudos

Hello,

You can use it at ED1EP05 context level.

Make sure both input fields are at the same level.

-Rahul

Former Member
0 Kudos

Hi Rahul,

Can you elaborate on this solution.

I need help in creation of this UDF.

regards,

Piyush

RKothari
Contributor
0 Kudos

Input values are KRATE and KSCHL fields which are at context level of E1EDP05.

KSCHL--\
KRATE---UDF--->Krate

-Rahul

markangelo_dihiansan
Active Contributor
0 Kudos

Hello,

Apologies for the mistype, I have corrected the mapping now:


Krate --> removeContext ----------------------------> \
KSCHL --> removeContext --> equalsS:ZRTP --> or --> ifThenElse --> sum --> Krate
KSCHL --> removeContext --> equalsS:ZIPP ---> /       / 
Constant: 0 ---------------------------------------> / 

Hope this helps,

Mark

Former Member
0 Kudos

Hi Rahul,

I have tried doing this but it returns the summation only for the first row. Rest are blank.

I have used the below UDF at KRATE level:

int i, sum=0, ret=0;

for(i=0;i<KSCHL.length;i++)

{

if((KSCHL<i>.equals("ZRTP")) || (KSCHL<i>.equals("ZIPP")))

{

sum = sum + Integer.parseInt(KRATE<i>.trim());

}

}

result.addValue(""+sum);

Let me provide you with the complete Source and target:

SOURCE:

<?xml version="1.0" encoding="UTF-8"?>

<INVOIC02>

<IDOC BEGIN="1">

<E1EDP01 SEGMENT="1">

<POSEX>000010</POSEX>

<MENGE>12.000</MENGE>

<MENEE>LTR</MENEE>

<E1EDP05 SEGMENT="1">

<ALCKZ>+</ALCKZ>

<KSCHL>ZRTP</KSCHL>

<KOTXT>RTP at Port</KOTXT>

<BETRG> 100</BETRG>

<KRATE> 100</KRATE>

<MEAUN>K15</MEAUN>

</E1EDP05>

<E1EDP05 SEGMENT="1">

<ALCKZ>+</ALCKZ>

<KSCHL>ZIPP</KSCHL>

<KOTXT>RTP at Port</KOTXT>

<BETRG> 300</BETRG>

<KRATE> 300</KRATE>

<MEAUN>K15</MEAUN>

</E1EDP05>

<E1EDP05 SEGMENT="1">

<ALCKZ>+</ALCKZ>

<KSCHL>ZIPPTP</KSCHL>

<KOTXT>RTP at Port</KOTXT>

<BETRG> 300</BETRG>

<KRATE>500</KRATE>

<MEAUN>K15</MEAUN>

</E1EDP05>

</E1EDP01>

</IDOC>

</INVOIC02>

TARGET:

<?xml version="1.0" encoding="UTF-8"?>

<INVOIC02>

<IDOC BEGIN="1">

<E1EDP01 SEGMENT="1">

<POSEX>000010</POSEX>

<MENGE>12.000</MENGE>

<MENEE>LTR</MENEE>

<E1EDP05 SEGMENT="1">

<ALCKZ>+</ALCKZ>

<KSCHL>SUMRTP</KSCHL>

<KOTXT>RTP at Port</KOTXT>

<BETRG> 100</BETRG>

<KRATE> 800</KRATE>

<MEAUN>K15</MEAUN>

</E1EDP05>

<E1EDP05 SEGMENT="1">

<ALCKZ>+</ALCKZ>

<KSCHL>ZIPPTP</KSCHL>

<KOTXT>RTP at Port</KOTXT>

<BETRG> 300</BETRG>

<KRATE>500</KRATE>

<MEAUN>K15</MEAUN>

</E1EDP05>

</E1EDP01>

</IDOC>

</INVOIC02>

Please help.

regards,

Piyush

Former Member
0 Kudos

Hi Mark,

Thanks.

I am just trying out Rahul's method.

Let me see if it works fine.

thanks for the update.

regards,

Piyush

RKothari
Contributor
0 Kudos

Hello,

Yeah, sorry I forgot to encorporate the Else statement.

Please try the below code:

int i, sum=0, ret=0;

for(i=0;i<KSCHL.length;i++)
{
if((KSCHL<i>.equals("ZRTP")) || (KSCHL<i>.equals("ZIPP")))
{
sum = sum + Integer.parseInt(KRATE<i>.trim());
}
}
if(sum > 0)
{
result.addValue(""+sum);
}
else
{
  ret = Integer.parseInt(KRATE<i>.trim());
result.addValue(""+ret);
}

Former Member
0 Kudos

Hi Rahul,

It gives the same output as the sum is alwaus greater than 0.

OUPUT that I am getting is:

<E1EDP01 SEGMENT="1">

<DELCO>LTR</DELCO>

<E1EDP05 SEGMENT="1">

<ALCKZ>+</ALCKZ>

<KSCHL>ZRTP</KSCHL>

<KOTXT>RTP at Port</KOTXT>

<BETRG>700</BETRG> -


SUMMED VALUE

<KRATE>400</KRATE>

<MEAUN>K15</MEAUN>

</E1EDP05>

<E1EDP05 SEGMENT="1">

<ALCKZ>+</ALCKZ>

<KSCHL>ZIPP</KSCHL>

<KOTXT>RTP at Port</KOTXT>

<MEAUN>K15</MEAUN>

</E1EDP05>

<E1EDP05 SEGMENT="1">

<ALCKZ>+</ALCKZ>

<KSCHL>ZIPPTP</KSCHL>

<KOTXT>RTP at Port</KOTXT>

<MEAUN>K15</MEAUN>

</E1EDP05>

</E1EDP01>

RKothari
Contributor
0 Kudos

Hello,

I guess the final code ...u want to print the output for each value of KSCHL with condition that ZRTP and ZIPP values must have KRATE = sum and rest the same value of KRATE as source.

int i, sum=0, ret=0;
 
for(i=0;i<KSCHL.length;i++)
{
if((KSCHL<i>.equals("ZRTP")) || (KSCHL<i>.equals("ZIPP")))
{
sum = sum + Integer.parseInt(KRATE<i>.trim());
}
}

for(i=o;i<KSCHL.length;i++){
if((KSCHL<i>.equals("ZRTP")) || (KSCHL<i>.equals("ZIPP")) )
{
	result.addValue(""+sum);
}
else
{
 	ret = Integer.parseInt(KRATE<i>.trim());
	result.addValue(""+ret);
}
}

Former Member
0 Kudos

Hi Rahul,

I had done exactly the same just before I saw ur post.

And it works

Thanks a lot for the time you have spent!!!!!!!!!!

Can you just answer my last query.

How do I pass a single row for ZRTP and ZIPP to the target.? i.e if source has 2 rows with ZRTP and ZIPP, I want to pass the summation to a single row in the target

My udf is as below:

int i, sum=0, ret=0;

int flagSumMapped=0; //flag to check if sum has already been mapped to the target

for(i=0;i<KSCHL.length;i++)

{

if((KSCHL<i>.equals("ZRTP")) || (KSCHL<i>.equals("ZIPP")))

{

sum = sum + Integer.parseInt(KRATE<i>.trim());

}

}

for(i=0;i<KSCHL.length;i++)

{

if((KSCHL<i>.equals("ZRTP")) && (flagSumMapped==0))

{

flagSumMapped = 1;

result.addValue(""+sum);

}

else if((KSCHL<i>.equals("ZIPP")) && (flagSumMapped==0))

{

flagSumMapped = 1;

result.addValue(""+sum);

}

else if(!(KSCHL<i>.equals("ZRTP")) && !(KSCHL<i>.equals("ZIPP")))

{

result.addValue(""+KRATE<i>.trim());

}

}

regards,

Piyush

Edited by: Piyush Mathur SAP on Feb 17, 2011 12:57 PM

RKothari
Contributor
0 Kudos

If you want a single row for ZRTP and ZIPP in target,

You can try to suppress the more than 1 occurance of E1EDP05 segment.

Try using the below UDF when populating E1EDP05 segment.

I guess all the later occurance must be suppressed for ZRTP and ZIPP values.

int i;

for(i=0;KSCHL.length;i++)
{
if(KSCHL<i>.equals("ZRTP") || KSCHL<i>.equals("ZIPP") )
{
     if(i==0)
{result.addValue(""+i);}
else{result.addValue(ResultList.SUPPRESS);}
}
else
{ result.addValue(""+i)}

}

Former Member
0 Kudos

It works

Man!!!!!!!!

you are a rockstar

i recommend that you please write some blogs and share your immaculate knowledge of mapping.

Please refer some sample dos to me for mapping.

Thanks a ton for you time and efforts.

regards,

Piyush

Answers (1)

Answers (1)

Former Member
0 Kudos

E1EDP01 is not root node -- That is understtod by default.

The logic suggested by Mark should work.

Let us know what error are you getting?

---Div