No need for the scratchpad. Just add a class member to store the last value.
Code:
class ACFTestFunc extends COM.ibm.db2.app.UDF
{
int lastValue;
public void testIt(int inValue, int result) throws Exception
{
set(2, lastValue);
lastValue = inValue;
}
}
You may want to use the FINAL CALL clause in the function declaration so that you can initialize "lastValue" to something on the first invocation of the UDF.
Also note that the object will be destroyed at the end of the SQL statement execution. So you can carry values between one call to the function to the next call - within the same SQL statement. (It may work across SQL statements because DB2 does some caching, but it is unreliable at best.)