cancel
Showing results for 
Search instead for 
Did you mean: 

Graphical Message Mapping - check indicator

Former Member
0 Kudos

Hi experts,

In my graphical message mapping I need to check if an indicator is set in 1 of the 5 possible indicator fields.

Based on the indicator, I need to fill to a specific field with a value.

What is the quickest way to accomplish this? I can build a lot of IF statements, but I hope there is an easier way to do it.

Thanks a lot

Dimitri

Accepted Solutions (1)

Accepted Solutions (1)

former_member200962
Active Contributor
0 Kudos
I can build a lot of IF statements, but I hope there is an easier way to do it.

Checking for the values 1-5 will be easier in an UDF using a statement like:

if(a.equals("1")||a.equals("2")||so on till 5);

{

return sourcenode;

}

Regards,

Abhishek.

Former Member
0 Kudos

Hi Abhishek,

The thing is that I do not know java at all...

What I need is this:

the data entering the system is a flat structure with a lot of records..

5 indicator fields are present and can be filled with an X. Based on filled indicator fields, a value from another field must be mapped to the target. And this must be in a loop.

Hopefully this is easy in java.

Thanks a lot

Dimitri

former_member200962
Active Contributor
0 Kudos
Based on filled indicator fields, a value from another field must be mapped to the target.

Will the indicator fields have some constant value (say if it is 123 or 456 then populate the target)

You can design a UDF which will have two inputs....one will be the indicator field and the other will be the field which you want to map to target in case the indicator field passes the test.

Regards,

Abhishek.

Former Member
0 Kudos

Hi Abhishek,

Indeed, that's the principle. The only problem is my java knowledge...

Former Member
0 Kudos

If you have 5 indicator fields then you have to go for UDF.

If you are new to UDF creation then go through this link page 37 onwards..

http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/be05e290-0201-0010-e997-b6e55f954...

You need to put conditions based on different values in each indicator.

e.g.

While creating udf you need to create 5 arguments with name idicator1, idicator2,idicator3,... idicator5 (you can choose any name)

if (indicator1.eauals('X') || indicator2.eauals('X') || indicator3.eauals('X') || .... indicator4.eauals('X') )

{

return "1";

}

return "0";

Now use one if conditions and check if the result returned by udf is 1 then map the desired field to target.

Map all indicator to 5 input fields of UDF as shown below..

indicator1 
indicator2      
indicator3    UDF ---> equalS ( 1)--> if--then (map desired source field)---->target.
indicator4
indicator5

Former Member
0 Kudos

Hi Sarvesh,

Thanks again for the quick reply!

I started building the UDF...

But I think I already need to map the correct source to the target in the UDF, no?

Former Member
0 Kudos

> I started building the UDF...

Good..

> But I think I already need to map the correct source to the target in the UDF, no?

Yes, you can do it. Just add one more variable (argument) in your UDF for your correct source and map it to UDF and in the code you can return the same when your conditions are true. e.g. Let's say your source variable name is src_var then use return src_var; instead of return 1;

Regards,

Sarvesh

Former Member
0 Kudos

This is my code

if (RegTH.equals('X') {

map sourceA_field to output field;

} else if RegHI.equals('X') {

map sourceB_field to output field;

} else if RegLO.equals('X') {

map sourceC_field to output field;

} else if RegPE.equals('X' ) {

map sourceD_field to output field;

} else if RegLOW.equals('X') {

map sourceE_field to output field;

}

So I have defined 6 parameters. 5 for mapping the input fields an 1 for the output, but how can that be?

depending on the indicator field, a specific source field must be mapped to the target

Former Member
0 Kudos

Since you have 5 different source fields as well therefore you need to define 5 more arguments in UDF and you need to map all of them.

So in total you will have 10 arguments (5 indicator + 5 source fields) and do your coding as mentioned below, then simply map this UDF to the target field.

if (RegTH.equals('X') 
{
       return sourceA_field;
 } 
else if  RegHI.equals('X') 
{
       return sourceB_field;
 }
 else if RegLO.equals('X')
 {
      return sourceC_field;
 } 
else if RegPE.equals('X' ) 
{
   return sourceD_field;
}
 else if RegLOW.equals('X') 
{
    return sourceE_field;
}
  return "";

Former Member
0 Kudos

this is my code

if (RegTH.equals('X'))

{

return ExpTH;

}

else if (RegHI.equals('X'))

{

return ExpHI;

}

else if (RegLO.equals('X'))

{

return ExpLO;

}

else if (RegPE.equals('X' ))

{

return ExpPE;

}

else if (RegLOW.equals('X'))

{

return ExpLOW;

}

else

{

return " ";

}

I tested it and in the queue, the X is clearly mentioned. Nut the return of the function is null.

Should I collapse the context of every field before I map it to the UDF?

Or should the parameter fields have the same name as the name in the Data Type?

Former Member
0 Kudos

Some modification in the code..

if (RegTH.equals('X'))

{

return ExpTH;

}

else if (RegHI.equals('X'))

{

return ExpHI;

}

else if (RegLO.equals('X'))

{

return ExpLO;

}

else if (RegPE.equals('X' ))

{

return ExpPE;

}

else if (RegLOW.equals('X'))

{

return ExpLOW;

}

return " ";

else

{

return " ";

}

Don't use the code mentioned in bold letters. Try this and let us know..

Former Member
0 Kudos

I modified the code...

this is my queue: http://www.flickr.com/photos/45449397@N03/4190045694/

Isn't it ok?

Former Member
0 Kudos

Can't say why null is showing. May be in PI it shows like that, But since you are able to see the queue then it means UDF is working file.

Are you getting the correct result when you see the target field queue?

Former Member
0 Kudos

in the queue of the target field, a blank is mentioned. But I expected the value 1111. So there is still something wrong I think

Former Member
0 Kudos

I was about to write this that you will face this blank issue.

You have to remove those blank vaues. We have to choices to do that either we modify the current UDF or we write one more very samll advanced UDF of type "queue".

If we go for option 2 then the new UDF2 code will be like this..

while creating the udf just select the type as queue (you will see 3 options: single value, context & queue)

I guess the default argument will be "var1", if yes you can leave it as it is and the just copy and paset the code.

for (int i = 0; i < var1.length; i++ )
{
if (! var1<i>.equals(""))
result.addValue( var1<i> );
}

Now the mapping will be something like this..

Source --> old UDF--->RemoveContext--->new UDF --->Target.

But if you like to go for option 1 then first change the type of UDF to Queue and then in the code modify the "return" statement e.g.

if (RegTH.equals('X')) 
{
result.addValue( ExpTH );
} 
else if (RegHI.equals('X')) 
{
result.addValue( ExpHI );
}
else if (RegLO.equals('X'))
{
result.addValue( ExpLO );
} 
else if (RegPE.equals('X' )) 
{
result.addValue( ExpPE );
}
else if (RegLOW.equals('X')) 
{
result.addValue( ExpLOW );
}
result.addValue( ResultList.SUPPRESS );

Note: for option 1 you have to set context of source value to their heighest level, so that there shouldn't be a context change. Or you can use RemoveContext.

Former Member
0 Kudos

This is the queue for the UDF: http://www.flickr.com/photos/45449397@N03/4189386151/

And this is the queue for the target field: http://www.flickr.com/photos/45449397@N03/4189386149/

Strange that I see the SUPPRESS value in the target

Former Member
0 Kudos

hmmm... I think you have chosen option 1, if yes please modify the code like this..

if (RegTH.equals('X')) 
{
result.addValue( ExpTH );
} 
else
{
result.addValue( ResultList.SUPPRESS );
}

else if (RegHI.equals('X')) 
{
result.addValue( ExpHI );
}
else
{
result.addValue( ResultList.SUPPRESS );
}

else if (RegLO.equals('X'))
{
result.addValue( ExpLO );
} 
else
{
result.addValue( ResultList.SUPPRESS );
}

else if (RegPE.equals('X' )) 
{
result.addValue( ExpPE );
}
else
{
result.addValue( ResultList.SUPPRESS );
}

else if (RegLOW.equals('X')) 
{
result.addValue( ExpLOW );
}
else
{
result.addValue( ResultList.SUPPRESS );
}

Former Member
0 Kudos

I got an error saying ELSE without IF...

But I want to go for IF .... OR IF.... OR... I assume that is also feasible

Former Member
0 Kudos

Use ONLY "if" instead of "else if" all the way..

Former Member
0 Kudos

and like this?

if (RegTH.equals('X'))

{

result.addValue( ExpTH );

}

if (RegHI.equals('X'))

{

result.addValue( ExpHI );

}

if (RegLO.equals('X'))

{

result.addValue( ExpLO );

}

if (RegPE.equals('X' ))

{

result.addValue( ExpPE );

}

if (RegLOW.equals('X'))

{

result.addValue( ExpLOW );

}

Former Member
0 Kudos

I now added some values to all the source fields and to just 1 indicator source field: http://www.flickr.com/photos/45449397@N03/4189432071/

Still, the queue of the target is empty as you can see completely on the right.

Former Member
0 Kudos

Hello again,

The UDF is pretty simple, You made a mistake wihile creating it (even me couldn't look it). The problem is you are using X in single coats, it should be in double coats i.e. "X".

Secodly no need to go for advanced UDF. So change back it to Single Value options and replace the below code in your UDF.

if (RegTH.equals("X")) 
{
return ExpTH;
} 
else if (RegHI.equals("X")) 
{
return ExpHI;
}
else if (RegLO.equals("X"))
{
return ExpLO;
} 
else if (RegPE.equals("X" )) 
{
return ExpPE;
}
else if (RegLOW.equals("X")) 
{
return ExpLOW;
}
return " ";

Former Member
0 Kudos

Hi Sarvesh,

As you already suggested, the solution can be a UDF. But your solution is even more simple...

Just right-click on the target segment and choose Duplicate Subtree.

Next, if the relevant indicator field is set to X in the source, map constant value 1 to the target segment.

If no value 1 is mapped, the target structure will not appear in the target message.

Thanks a lot!!

Dimitri

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi,

Go for std. fun "FixedValue" table option. there you can provide your key fields and their respective results.

Regards,

Sarvesh