cancel
Showing results for 
Search instead for 
Did you mean: 

Output last value in Context - PI Mapping

0 Kudos

Hi Experts,

I'm a PI starter.I need your help in mapping.

I need to output the last value in a context.Kindly help me do this.

It has several contexts.I know we need a UDF to identify the last index in a context & output the value. If there is no way of doing this thorugh graphical mapping, please help me write a UDF.

Accepted Solutions (0)

Answers (2)

Answers (2)

anupam_ghosh2
Active Contributor
0 Kudos

Hi Harry,

                Please check this wonderful article to understand more on context and queues

http://scn.sap.com/people/rohit.kalugade/blog/2008/12/08/context-and-queue-in-message-mapping-udf

you can solve these problems yourself.

Please rate the blog if you it useful.

Regards

Anupam

Former Member
0 Kudos

Hi,

U have to write a UDF for this:

Execution type: all values of a context

int a = var1.length;

result.addValue(var1[a-1]);

Thanks

Amit Srivastava

Former Member
0 Kudos

Hi Amit,

Considering Harry's requirement, the UDF provided by you should have ResultList.addSuppress().

Execution type: all values of a context

for(int i=0;i<var1.length-1;i++)

{

     ResultList.addSuppress();

}

Thats it.

Short and Sweet

Thanks & Regards,

Tejas Bisen


Former Member
0 Kudos

Hi,

If u see properly Harry wants to output the last value of each context and the UDF provided above is exactly doing the same. What's ur point?

The code which u have provided above is just suppresing all the values?

Thanks

Amit Srivastava

Former Member
0 Kudos

Hi Amit,

The UDF I have provided would Suppress all values except the Last one since the Loop will run from 0 to n-1 values of the queue.

You can try the same. If we do ResultList.addValue("Any Value")

It will output only the first value of the Context.

I hope you got the point. I tried this in my Mapping today with a similar requirement.

Thanks

Tejas Bisen

Former Member
0 Kudos

Hi,

Indeed, it will work (i havent seen the condition for the last run) but do u really think that it's a good solution to have a for loop and suppressing each value except the last one...on the other side u can go directly and fetch the last value of a context without using any loop??

Thanks

Amit Srivastava

Former Member
0 Kudos

Hi Amit,

If the other values are not suppressed, only the first value of the context would be passed.

Also to correct my program a little ..instead of ResultList.addSuppress() it should be result.addSuppress(). Please have a look at the function i have implemented.

Here my condition is if null or no value comes I need to suppress or else allow a particular node to be created. If we don't loop and suppress other values in the context.

I think the only difference in your and my approach is I have using it at node level and then populating values under the node.

In the Function you provided, you are just passing the value that needs to go.

Your Function is also right Amit. I just tested it on my system

Thanks,

Tejas Bisen

Former Member
0 Kudos

HI Tejas,

Glad to know that my UDF is working

i guess u r not getting my point but anywayz i am ending this discussion here becoz this 1 line of code doesnt need anymore explantion from both of us.

Thanks

Amit Srivastava