CREATE FUNCTION "DBA"."get_pa_leping_tun_konto"( in a_lepnr integer, in a_kuup date )
returns char(7)
begin
  declare ls_konto char(7);
  select first pa_leping_tun.konto into ls_konto from pa_leping_tun where pa_leping_tun.lepnr=a_lepnr and pa_leping_tun.kuup1 <= a_kuup order by pa_leping_tun.kuup1 desc;
  return ls_konto
end