cancel
Showing results for 
Search instead for 
Did you mean: 

How to make calculation in Mapping with multiple segments

Former Member
0 Kudos

HI All,

I am working on IDOC to JDBC where I need to do some calculations as:

E1MARMM segment is repeating with fields in IDOC

E1MARMM---0..Unbound

--MSGFN

--MEINH

--UMREZ

--UMREN

I need to make a calculation as below:

(E1MARMM-UMREZ(PF)/E1MARMM-UMREN)/ (E1MARMM-UMREZ(CS)/E1MARMM-MREN)

E1MARMM-UMREZ(PF) means E1MARMM--UMREZ value where MEINH value equals to PF

E1MARMM-UMREZ(CS) means E1MARMM--UMREZ value where MEINH value equals to CS

Ex: I am creating 2 segments where as in IDOC it has more than 2 segments with other caluclations with other Units.

E1MARMM:

MSGFN--005

MEINH--PF

UMREZ-520

UMREN-1

E1MARMM

MSGFN--005

MEINH--CS

UMREZ--4

UMREN--1

By calculation I need to get output as 13 -


(520/1) / (4/1)

How can I achieve this?

Thanks

Rajeev

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

see the changes I made in the below code to avoid that error


for (int i = 0; i < a.length; i++) {
if (a<i>.equals(ResultList.SUPPRESS )|| a<i>.equals("null")) {
// your sentence
result.addValue("");
} else {
// your sentence
result.addValue(a);
}
}

Answers (2)

Answers (2)

Former Member
0 Kudos

HI,

Below UDF should help you

Input Parameters, MEINH, UMREZ, UMREN

Context : queue


float temp1 =0;
float temp2 =0;

for(int i=0; i<MEINH.length;i++)
{
    if(MEINH(i).equals('PF'))
         temp1 = Float.parseFloat(UMREZ(i))/Float.parseFloat(UMREN(i));
    elseif(MEINH(i).equals('CS'))
         temp2 = Float.parseFloat(UMREZ(i))/Float.parseFloat(UMREN(i));
}
result.addValue(String.valueOf(temp1/temp2));

Thanks

Swarup

Former Member
0 Kudos

Hi All,

source:

E1MARMM

MSGFN--

MEINH--

UMREZ--

UMREN--

IDOC is multiple segments with values:

E1MARMM:

MSGFN--005

MEINH--PF

UMREZ-520

UMREN-1

E1MARMM

MSGFN--005

MEINH--CS

UMREZ--4

UMREN--1

E1MARMM

MSGFN--005

MEINH--PL

UMREZ--4

UMREN--1

Can any one let me know how can I write a UDF to track each filed value segment by segment?

I need to work around this calculation as I think I cant achieve using normal graphical Mapping.

Thanks

Rajeev.

markangelo_dihiansan
Active Contributor
0 Kudos

Hi,

You can try this mapping:


MEIN --> equalsS --> ifWithoutElse --> removeContext --> sum ----> div ----------> div --> formatNumber: 0.00 --> TargetMessage 
Constant: PF ->/          /                                         /               /
UMREZ -----------------> /                                         /               /
                                                                  /               /
MEIN --> equalsS --> ifWithoutElse --> removeContext --> sum --> /               /
Constant: PF ->/          /                                                     / 
UMREN -----------------> /                                                     /
                                                                              /
MEIN --> equalsS --> ifWithoutElse --> removeContext --> sum ----> div -->   /
Constant: CS ->/          /                                         /
UMREZ -----------------> /                                         / 
                                                                  /
MEIN --> equalsS --> ifWithoutElse --> removeContext --> sum --> /
Constant: CS ->/         /
UMREN -----------------> /

Hope this helps,

Edited by: Mark Dihiansan on Sep 16, 2009 10:38 AM

Edited by: Mark Dihiansan on Sep 16, 2009 10:39 AM

Former Member
0 Kudos

Hi All,

I made a condition as stated by mark and I struck in between could any one input there experence..

After caluclations I need to pass the value to the target. Every thing is fine if there are some values comming up..If there are no values then I am getting SUPRESS how can I get rid of this and pass a constant value to the target field when ever there is no value (SUPRESS)???

I want to evaluate if value exist then pass orelse constant..

Thanks

Rajeev

Former Member
0 Kudos

hi

In your source use the function standar MapWithDefault (indicate the constant value) . after your values

Former Member
0 Kudos

hi,

I tried with that function as well

MAPWITHDEFAULT but no sucess, using this function my results are: If value exist it pases the value.. If not then SUPRESS...

I am using all graphical functions.. with div and so on...finally the result is mapped to target field.... Before this target field I want to evaluate if it is null then I want to pass constant orelse pass value..

Any input to supress this supress value.

Thanks

Rajeev

Former Member
0 Kudos

Well you can use this UDF


for (int i = 0; i < a.length; i++) {
if (!a<i> = null || !a<i>.length() > 0){
 result.addValue(a<i>);}
else
{result.addValue("your constant")
}
}

Edited by: Luis Ortiz on Sep 17, 2009 2:52 PM

Former Member
0 Kudos

Hi All,

No its not working out.. What is this supress and what is the difference between supress and NUll?

How can I get rid of these ?

I used mapwithdefault but still supress is passing to target and the target is 1:1 hence It cant produce target element.

Any suggestions are appreciated.

THanks

Rajeev

Former Member
0 Kudos

Hi

I don't understand what do you want exactly. could you explain more clearly?.. You want to avoid SUPPRESS?

Former Member
0 Kudos

Hi Luis,

Yes I want to avoid SUPRESS I dont know whats the reason behind getting this supress!..

I am doing a MM where I need to make calculations as mentioned above..I am using GM and able to calculate but at the end if the values are present then its fine if there are no values passed from source then it is showing supress and I am unable to catch supress in my UDF to pass constant.

How to get rid of this supress.. and NUll values... I wrote your function but still not successful.. I used MAPWITHDEFAULT even but not able to stop supress.....

ANy inputs?

Thanks

Rajeev

Former Member
0 Kudos

hI..

Well you can identify the supress with this sentence "ResultList.SUPPRESS". One question your UDF is in context or in queue?


for (int i = 0; i < a.length; i++) {
if (a<i>.equals(ResultList.SUPPRESS)) {
 //   your sentence
 //  e.g result.addValue("false");
} else {
 //   your sentence
 // e.g  result.addValue(a<i>);
}
}

Former Member
0 Kudos

Till now there was no need of UDF but to get rid of this supress value I need to create UDF and using your code its worked... while testing again I encoutered null value.. In order to ovid null I need to use MAPBYDEFAULY function.. but is it possible to use these two conditions in one UDF?

I tried by writing

for (int i = 0; i < a.length; i++) {

if (a<i>.equals(ResultList.SUPPRESS || a<i> = null)) {

// your sentence

result.addValue("");

} else {

// your sentence

result.addValue(a<i>);

}

}

I got a error message in UDF stating opertor || cant be applied..

is it so I cant use same function to validate NULL ??

Thanks

Rajeev

Former Member
0 Kudos

Hi

Oh..I made a litle mistake , the sentence that kubra rewrote is correct.

Also you need to review java sentence ,beause is necesary

Former Member
0 Kudos

HI All,

Thanks alot for your inputs.. I awarded points.

Thanks

Rajeev

Former Member
0 Kudos

Hi

Try With this

 

UMREZ----------->
UMREN------------div...........................then
MEINH ----Equal$ (PF) -------------------------------if--------------------->Target 
MEINH ----Equal$ (CS) ---- ------ifwithoutelse........else
UMREZ------------
UMREN------------divt----Then