out boolean OUT_Active; {default form to 'RM_Customer_Maintenance';} {default window to 'RM_Customer_Maintenance';} { Used for AutoGen Number } local string l_prefix; local integer l_prelength; local integer l_length; local long l_number; local integer i; local string char; OUT_Active = false; l_prelength = 8; { Max Length of Prefix part of Number } l_length = 4; { Length of Numeric part of Number } l_number = 1; { First Number in AutoGen Sequence } if empty('Customer Name' of window 'RM_Customer_Maintenance' of form 'RM_Customer_Maintenance') or not empty('Customer Number' of window 'RM_Customer_Maintenance' of form 'RM_Customer_Maintenance') then abort script; end if; clear l_prefix; for i = 1 to length('Customer Name' of window 'RM_Customer_Maintenance' of form 'RM_Customer_Maintenance') do char = substring('Customer Name' of window 'RM_Customer_Maintenance' of form 'RM_Customer_Maintenance', i, 1); if isalpha(char, false) then l_prefix = l_prefix + upper(char); if length(l_prefix) = l_prelength then exit for; end if; end if; end for; { Calculate Next Number } range clear table RM_Customer_MSTR; clear table RM_Customer_MSTR; 'Customer Number' of table RM_Customer_MSTR = l_prefix+pad(str(0), LEADING, str(0), l_length); range start table RM_Customer_MSTR; fill table RM_Customer_MSTR; 'Customer Number' of table RM_Customer_MSTR = l_prefix+pad(str(10^l_length-1), LEADING, str(0), l_length); range end table RM_Customer_MSTR; get last table RM_Customer_MSTR; if err() = OKAY then l_number = value('Customer Number' of table RM_Customer_MSTR) + 1; end if. range clear table RM_Customer_MSTR; { Insert Next Number } 'Customer Number' of window 'RM_Customer_Maintenance' of form 'RM_Customer_Maintenance' = l_prefix+pad(str(l_number), LEADING, str(0), l_length); focus 'Customer Number' of window 'RM_Customer_Maintenance' of form 'RM_Customer_Maintenance'; force change 'Customer Number' of window 'RM_Customer_Maintenance' of form 'RM_Customer_Maintenance';