cancel
Showing results for 
Search instead for 
Did you mean: 

Mapping Problem with IF...Else

Former Member
0 Kudos

HI,

im having problems with my if then else condition.

What i want to have. (ORDERS IDOC)

IF E1EDKA1-PARVW = WE and

E1EDKA1-LIFNR = "XX" then CONSTANT ("true")

else Constant ("false").

If i use only one E1EDKA1 segment ... it works.

If i use many E1EDKA1 segments and use if without else ... it works.

But i cant get it with if then else. I will allways get the else value.

any ideas ?

Gordon

Message was edited by:

Gordon Breuer

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi

i think u can do it with graphical mapping.

whatever u have done is correct. just change the context.

try this.

PARVW(context=<b>E1EDKA1</b>)

equals

Constant(WE)

<b>and</b>

LIFNR(context=<b>E1EDKA1</b>)

equals

Constant(XX)

the <b>and</b> operator goes into the IF

Then is filled with constant (true)

Else is filled with constant (false)

& output goes to target field.

Map E1EDKA1 properly.

Thanks,

Maheshwari.

Former Member
0 Kudos

@Maheshwari. : no ...same result. have you tested it ?

you dont have to test with E1EDKA1 WE only. Most orders have PARVW AG, RE, LF and many more.

@Chilla. Your UDF is not complete. The "(" and ")" is missing and it´s only working if i have only one E1EDKA1 segment with PARVW "WE".

try the following test.

E1EDKA1 - AG (LIFNR Field is not available)

E1EDKA1 - WE (LIFNR is available with xx)

but ... this way seems to be the right one, lets go and complete this issue together.

Thanks you,

chilla !

Former Member
0 Kudos

Hi,

I just gave example , plz implement with your business requirement.

OR plz give full details.

Regards

Chilla..

Former Member
0 Kudos

HI

full details as already said.

PARVW = WE and LIFNR = xx

but note that E1EDKA1 segment could be exists more than once.

Example

E1EDKA1-PARVW = AG

E1EDKa1-LIFNR = is not existing / visible

E1EDKA1-PARVW = WE

E1EDKa1-LIFNR = xx

E1EDKA1-PARVW = LF

E1EDKa1-LIFNR = 4711

false: if LIFNR is not filled with xx and PARVW = WE

true: if one of the E1EDKA1 is filled with LIFNR = xx and PARVW = WE.

right ?

Former Member
0 Kudos

HI

Ok , i will try to give code, mean while clarify , what is the target node occurrence

Regards

Chilla

Former Member
0 Kudos

HI,

<b>In your example data only one true and two false right?</b>

try the below UDF

-


use parvw - removecontext -- UDF -- split byvalue --target node

-


use lifnr -- remove context --- /

while creating UDF ---Input parvw,lifnr , select the queue option for User defined function

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

if parvw(i).equals("WE") && lifnr(i).equals("xx"){

result.addValue("true");

}else

{

result.addValue("false");

}

}

Note the "true" and "false" are not equal to boolean values do not compare.

Regards

Chilla

reward points...

Message was edited by:

Chandra Sekhar Chilla

Former Member
0 Kudos

Gordon,

wirte UDF with input two strings 1.PARVW 2.LIFNR. use context or queue in UDF to pass all entries to UDF.

UDF.

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

{

if((PARVW(i).equals("WE")) and ((LIFNR(i).equals("XX")));

reusltlist.addValue("true");

else

reusltlist.addValue("false");

}

Message was edited by:

Sreeram Reddy

Former Member
0 Kudos

sorry everythin wont work.

@chilla: same result. What about the starting context of PARVW and LIFNR ?

@Sreeram: what´s that for a function ? AG ? 2x true ???

Former Member
0 Kudos

it should be flase. what is the error you r getting

Message was edited by:

Sreeram Reddy

Former Member
0 Kudos

false ? OK

and why AG ?

have you tested this function ? What about context and other splitbyvalue options ? can you give me detaield grafik design ?

Former Member
0 Kudos

HI,

No need , i just modified my UDF see above ,Use WE not AG

Also given the correct graphic.

plz clarify the target node occur and its parent node occur

if parent of target node is more 0.. ubound or >0.. then map with the left side parent to right side parent or empty constant with right side parent.

Sure it will work

<b>---- use parvw - removecontext -- UDF -- split byvalue --target node

-


use lifnr -- remove context --- /</b>

Regards

Chilla

<i>reward points if it is helpful..</i>

Former Member
0 Kudos

@Maheshwari. : its not working+

@chilla: i cant follow you, can you give me a detailed description ?

Former Member
0 Kudos

Gordon ,

what is the error you are getting in mapping

Former Member
0 Kudos

HI

First clarify the target node occurrence

Chilla

Former Member
0 Kudos

no error occur: only the value false will appear

@chilla: The target field is the E1EDKA1-ORGID. ORGID has 0..1. The previos node is the segment E1EDKA1. E1EDKA1 has 0..12

Former Member
0 Kudos

HI,

Plz

map side parent node to targt parent node OR empty constant to taget node

no context change parvw -remove context- UDF-- splitbyvalue - taget node

no context change lifnr -- removecontext /

try with WE not AG.

<b>Please give graphic of your mapping and UDF code</b>

Regards

Chilla

Message was edited by:

Chandra Sekhar Chilla

Former Member
0 Kudos

what do you mean by "map side parent node to targt parent node OR empty constant to taget node" ?

grafikcode:

parvw -rmvcon-udf(param1) - splitbyvalue(each)-ORGID

lifnr-mapwdflt-rmvcon-udf(param2)

udf:

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

if (parvw(i).equals("WE") && lifnr(i).equals("xx")){

result.addValue("true");

}else{

result.addValue("false");

}

}

but UDF has errors!

ERROR:

.java:1136: cannot resolve symbol symbol : method parvw (int) location: class com.sap.xi.tf.ORDERS05_2_ORDERS05_ if (parvw(i).equals("WE") && lifnr(i).equals("xx")){ ^

and the same with lifnr !

Former Member
0 Kudos

HI,

plz change with "[]" . do not use ""

Check

Chilla

Former Member
0 Kudos

Gordon,

if (parvw(i).equals("WE") && lifnr(i).equals("xx")){

replace with []

Message was edited by:

Sreeram Reddy

Message was edited by:

Sreeram Reddy

Former Member
0 Kudos

Okay the udf is OK but it´s "false" again.

here is a logging of my UDF-out Queue.

1. SUPPRESS

2.

3.

4. (bold)[true]

logging of ORGID Queue

1. null

2. false

3. (bold)false

4. true

4. (bold)true

Former Member
0 Kudos

now how many values you need at targetside because you 2 values here.

Former Member
0 Kudos

only one value !

if xx then true if not false!

really simple

Gordon

Former Member
0 Kudos

need to change UDF a bit.

{

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

{

if (parvw(i).equals("WE") && lifnr(i).equals("xx"))

{

result.addValue("true");

}

}

result.addValue("false");

}

Former Member
0 Kudos

damn ... great Job guy´s. Its working now.

Here my final UDF... maybe someone needs this,too.

{

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

{

if (parvw(i).equals("WE") && lifnr(i).equals("xx"))

{

result.addValue("true");

}

}

result.addValue("false");

}

points rewarded to both of you!

Gordon

Message was edited by:

Gordon Breuer

Former Member
0 Kudos

Cool it works at last

Former Member
0 Kudos

HI,

The same only i have given.use WE.

Regards

Chilla

<b>remember points rewarded if it is helpful..</b>

<b>SDN/BPX is a community that lives for and from its users. Which means when asking a question, you also assume the responsibility to assign the points. Its recommended that you assign 6 or 10 points once to the answer/person that helped you the most. Assign 2 points to everyone that contributed something

https://www.sdn.sap.com/irj/sdn/wiki?path=/display/home/rulesofEngagement</b>

Former Member
0 Kudos

i think you have done a great job and 6 points ok ?

Former Member
0 Kudos

OK

Message was edited by:

Chandra Sekhar Chilla

Answers (4)

Answers (4)

Former Member
0 Kudos

Ok.. i got it.

try this one.

add if-then-else before checking equals condition of LIFNR

PARVW(context=E1EDKA1)

equals

Constant(WE)

and

<b>if</b> LIFNR -> <b>exists </b><b>then</b> LIFNR

<b>else</b> constat(blank)

equals

Constant(XX)

the and operator goes into the IF

Then is filled with constant (true)

Else is filled with constant (false)

& output goes to target field.

This shd work now

Thanks,

Maheshwari.

Former Member
0 Kudos

Hi Gordon,

take LIFNR as input....... use mapwithdefault func.......in mapwithdefault, use default value as space(' ')......take its output and compare with "XX".....then you can use if then else........

Thanks,

Rajeev Gupta

Former Member
0 Kudos

HI... can you explain more detailed ?

i´m allready using mapwithdefault "but" i think this is an context problem, too ?

Maybe you can show me how to setup the context for "PARVW" and for "LIFNR".

Thanks.

Gordon

Former Member
0 Kudos

Hi,

we can solve this in the following ways

--parvw - change context to its parent node which is having 0..unbound / 0..999 more

and use your if else/if elsewithout -- splitbyvalue-- target node

OR

--parvw - (change context to its parent node which is having 0..unbound / 0..999 more or root) instead use removecontext --

and use your if else/if elsewithout -- splitbyvalue --target node

Second solution

use same as above , instead above ifelse/ifwithoutelse write UDF with queue option

but before UDF removecontext and after UDF use splitbyvalue..

<b>right side parent node which is having 0.. unbound or 0..more should be mapped with empty constant</b>

Please let me know the result..

Regards

Chilla..

Former Member
0 Kudos

i havent understand your solution. Can you explain me more detailed ?

parvw context = E1EDKA1 or IDoc or ORDERS05 ?

I´m already using remove context!

Gordon

Message was edited by:

Gordon Breuer

henrique_pinto
Active Contributor
0 Kudos

Maybe you can make it work with standard functions if you use Exists standard function on the LIFNR field before you do the value comparison.

Regards,

Henrique.

Former Member
0 Kudos

I am not sure if it works by change context

Former Member
0 Kudos

Hi,

Can you please explain what you have done , so that i will try to give exact solution..

Regards

Chilla

<i>reward points if it is helpful..</i>

Former Member
0 Kudos

OKay i will try.

PARVW(context=idoc)

equals

Constant(WE)

and

LIFNR(context=E1EDKA1) - mapwithdef. - removecontext

equals

Constant(xx)

the and operator goes into the IF

Then is filled with constant (true)

Else is filled with constant (false)

This way is working WITHOUT ELSE but not working with it.

Former Member
0 Kudos

Hi,

try to do same with before target node use splitbyvalue

and target node parent node if it is more occurrence then mapwith constant or left side unbound to right side unbound

regards

Chilla

Former Member
0 Kudos

sorry but that is the same result.

I put the splitbyvalue behind the IFthenelse node and from the splitvalue into the target ... right ?

Former Member
0 Kudos

Hi,

try with same and change the lifnr context to Idoc.

Chilla

Former Member
0 Kudos

same result.

IDOC ? should i remove the removecontext ?

Gordon

Former Member
0 Kudos

Hi,

see below

parvw -- remove context -- UDF \ splitbyvalue -- target node

lifnr -- remove context -- above UDF /

For UDF --use input two string arrays : select queue option

implement you logic

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

write code here .. because i am not having full scope of your rquirement

}

regards

chilla.

Former Member
0 Kudos

explain u r logic , ican give UDF

Former Member
0 Kudos

i have to go now... maybe we can solve this tomorrow ?

Gordon

Former Member
0 Kudos

Hi Gordon,

see both PARVW and LIFNR will have E1EDKA1 as context by default....so dont worry about context......

PARVW->Mapwithdefault->equalS(compare with WE)->

LIFNR ->Mapwithdefault->equalS(compare with XX) ->AND->Ifthenelse->creatif->Target Node above your constant target field

PARVW->Mapwithdefault->equalS(compare with WE)->

LIFNR ->Mapwithdefault->equalS(compare with XX) ->AND->Ifthenelse->splitbyvalue->Constant target field.

Thanks,

Rajeev Gupta

Former Member
0 Kudos

you need to write UDF for this.

Former Member
0 Kudos

@RAJEEV GUPTA : nothing happens...same result. Have you tested it ?

@Chilla: can we go on with our solution ?

Former Member
0 Kudos

HI

Yes please tell your logic, so that i can give UDF

Regards

Chilla..

Former Member
0 Kudos

HI,

try the below UDF

-


use parvw - removecontext -- UDF -- split byvalue --target node

-


use lifnr -- remove context --- /

while creating UDF ---Input parvw,lifnr , select the queue option for User defined function

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

if parvw<i>.equals("WE") && lifnr<i>.equals("xx"){

result.addValue("true");

}else

{

result.addValue("false");

}

}

Note the "true" and "false" are not equal to boolean values do not compare.

Regards

Chilla

<i>reward points...</i>

Former Member
0 Kudos

you need use and operator

IF E1EDKA1-PARVW = WE and operator E1EDKA1-LIFNR = "XX" then assign for true for IF part false assingto Else part

Former Member
0 Kudos

Hi. Open your Message mapping and in the test tab give the necessary test values. Come back to design tab. Now right click on the if then else step and choose the option "display queue". This will show the input and output for the particular step.

You can debug with this tool easily

Regards,

Jai Shankar

Former Member
0 Kudos

HI... i had this test several times this morning but without any success.

Addition to my post:

The E1EDKA1 segment exists 5 times and LIFNR is only filled (exists) for the PARVW =WE.

Gordon

add:

I´m using the add operator like described in my first post !

Message was edited by:

Gordon Breuer

Former Member
0 Kudos

standarded function wont help it will gives only frist value. you needto useUDF with Context or Queues . where you pass the input value as Queue and process whole Queue and retrun the values.

Former Member
0 Kudos

sure ?

than i have to create a UDF.

Former Member
0 Kudos

yes you have write a UDF with Context or Queue based.