create procedure lib_string_sub (
                     strg_in varchar( 32765),
                     strg_beg smallint,
                     strg_len smallint)
                   returns (
                     strg_out varchar( 32765))
  as
    declare variable strg_chr char( 1);
    declare variable strg_cpy varchar( 32765);

    begin
      /*
        get substring
          strg_beg : 1 ..
      */

      if (   (strg_in is null)
          or (strg_beg is null)
          or (strg_beg <= 0)
          or (strg_len is null)
          or (strg_len <= 0))
        then
          strg_out = null;
        else
          begin
            strg_cpy = strg_in;
            while (1 < strg_beg)
              do
                begin
                  strg_cpy = substring( strg_cpy from 2);
                  strg_beg = strg_beg - 1;
                end

            strg_out = '';
            while (0 < strg_len)
              do
                begin
                  strg_chr = substring( strg_cpy from 1 for 1);
                  if (strg_chr || '.' <> '.')
                    then
                      begin
                        strg_out = strg_out || strg_chr;
                        strg_cpy = substring( strg_cpy from 2);
                        strg_len = strg_len - 1;
                      end
                    else
                      begin
                        strg_len = 0;
                      end
                end
          end

      suspend;
    end