PREV operator creates a property that returns the value of another property at the start of the current session (or at the time of the previous event in event mode) - i.e., the value that existed before the changes that were made in the current session.
It's important to understand that
PREV is not a built-in property with composition but an operator. Thus, in particular
PREV(f(a)) is not equal to
Expression whose value defines the property for which the previous value must be obtained.
f = DATA INTEGER (A);
// outputs all changes f(a) in the session one by one
FOR CHANGED(f(A a)) DO
MESSAGE 'In this session f(a) changed from ' + PREV(f(a)) + ' TO ' + f(a);
date = DATA DATE (Document);
price = DATA NUMERIC[14,2] (Document, Article);
// write in the price of the document the last used price in the database
// PREV is important to ignore the prices entered in this document
// this is especially important if the last used price is materialized, then the platform can simply read this value from the table
price(Document d, Article a) <- PREV((GROUP LAST price(d, a) ORDER date(d), d));