CREATE FUNCTION "dba"."if_gateway"( in id_obj integer default 0)
RETURNS INTEGER
BEGIN
  DECLARE li_gateway INTEGER;
  declare ls_marve char(50);
  if id_obj>0 then
    select marve into ls_marve from kp_obj where objnr=id_obj;
    if Length(ls_marve)>4 then
      if Substr(ls_marve,5,2)='42' then
        set li_gateway=1;
      end if;
    end if;
  end if;
  if li_gateway is null then
    set li_gateway=0
  end if;
  return li_gateway;
END