I can see three doubts in your code
1) you are using a while select statement, whereas I believe you are supposed to return a single value; hence you should use select firstonly
2) you are should put a semicolon at end of your select statement;
3) you ReturnType for the method is Real, whereas you are returning PurchParmTable.AutomaticInvoiceReference ; I am doubtful if AutomaticInvoiceReference is a Real Type field ??