on 02-16-2011 12:09 PM
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
Hello,
You can use the statistic function called sum
e.g
KRATE --> removeContext --> sum --> KRATE
Hope this helps,
Mark
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
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
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
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);
}
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>
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);
}
}
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
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)}
}
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
93 | |
10 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.