CREATE FUNCTION "DBA"."getid_kp_mall"()
returns integer
begin
  declare li_return integer;
  select max(mallnr) + 1 into li_return from kp_mall;
  if li_return is null or li_return < 1 then
    set li_return=1;
    while exists(select 1 from kp_mall where mallnr = li_return) loop
      set li_return=li_return+1
    end loop
  end if;
  return(li_return)
end