on 12-16-2009 8:09 AM
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
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
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.
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..
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
> 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
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
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 "";
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?
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..
I modified the code...
this is my queue: http://www.flickr.com/photos/45449397@N03/4190045694/
Isn't it ok?
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.
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
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 );
}
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.
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 " ";
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
Hi,
Go for std. fun "FixedValue" table option. there you can provide your key fields and their respective results.
Regards,
Sarvesh
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
84 | |
23 | |
11 | |
9 | |
8 | |
5 | |
5 | |
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.