#
# Blake McNulty 02/02/2005
# Subroutine to reformat stored procedure paramater input fields.
# If a full key is entered make the field fixed length. 
# If a wildcard (%) is entered truncate trailing spaces.
# (Needed for compound "like" comparisons within the "where" clause)
#

sub sp_fmt {

  $fval  = @_[0];
  $fsize = @_[1];
  $fsp1;
  $fsp2;
  $idx;
  $fout;  

# print "<pre>IN:",$fval,":";

  $fval = substr($fval.$SP,0,$fsize);

  $fsp2  = index($fval,'%');

  if ($fsp2 eq -1) { $fout = $fval;  goto ENDIT; }

  $fsp1 = $fsize;

  do {
     $fsp1--;
     if (substr($fval,$fsp1,1) ne ' ') { goto NEXT1; }
     } while ($fsp1 ne 0);

NEXT1:
  
  $fsp1++;
  $fout = substr($fval,0,$fsp1);

ENDIT:

  return($fout);
 
} 

# Required or will cause errors (dont know why)
1;
