re: ssn indexing
Posted in 1994
jack, here's my stab at this - it does a little more error checking in the char_to_int (rename ssn_to_int) routine. just out of curiousity, why did you use the MOD function? function int_to_ssn(i_ssn) #_inputs define i_ssn integer #_outputs define c_ssn char(11) # 123-45-6789 let c_ssn = i_ssn if(length(c_ssn)=9) then let c_ssn = c_ssn[1,3] clipped,"-", c_ssn[4,5] clipped,"-", c_ssn[6,9] clipped return c_ssn else return "-1" end if end function function ssn_to_int(c_ssn) #_inputs define c_ssn char(11) # 123-45-6789 #_outputs define i_ssn integer #_locals define tmp char(9) define i integer # make sure the string is the right length if(length(c_ssn)=11) then # gather all the numeric characters into tmp let tmp = null for i = 1 to 11 if(c_ssn[i] >= 0) and(c_ssn[i] <= 9) then let tmp = tmp clipped, c_ssn[i] clipped end if end for # make sure tmp is long enough if (length(tmp)=9) then return tmp else return -1 end if else # error condition return -1 end if end function > > > Based on the recent post suggesting SSN as an index, I thought of the > following method to turn a known-format character string into an integer > key to make it faster. It's also a reason to use MOD which somebody (not > here) recently claimed was a useless appendage to any data processing language: > > > MAIN > > DEFINE ssn CHAR(11), i_ssn INTEGER, c_ssn CHAR(11) > > PROMPT "Enter ssn " for ssn > > LET i_ssn=char_to_int(ssn) > LET c_ssn=int_to_char(i_ssn) > > DISPLAY "Integer : ", i_ssn > DISPLAY "Character : ", c_ssn > > END MAIN > > FUNCTION int_to_char(i_ssn) > > DEFINE i_ssn INTEGER, > int1 INTEGER, > c_ssn CHAR(11) > > # I go to integer here first - otherwise it gets rounded. > # it could have been built as one long string, which MIGHT have saved a > # micro second or two, but I try to make clarity my watchword. > > LET int1 = i_ssn / 1000000 # XXX________ > LET c_ssn[1,3] = int1 > > LET int1 = (i_ssn/10000) MOD 100 # XXX_XX_____ > LET c_ssn[5,6] = int1 > > LET int1 = i_ssn MOD 10000 # XXX_XX_XXXX > LET c_ssn[8,11] = int1 > > LET c_ssn[4,4]="-" # XXX-XX_XXXX > LET c_ssn[7,7]="-" # XXX-XX-XXXX > > RETURN c_ssn > > END FUNCTION > > FUNCTION char_to_int(c_ssn) > > DEFINE i_ssn INTEGER, > c_ssn CHAR(11) > > # I haven't checked RETURN c_ssn might work just as well. > > LET c_ssn=c_ssn[1,3], c_ssn[5,6], c_ssn[8,11] # lose the "-" > LET i_ssn = c_ssn > > RETURN i_ssn > > END FUNCTION > > cheers > j. > _____________________________________________________________________________ > Jack Parker | > Hewlett Packard, BSMC Boise, Idaho, USA| He who talks most, talks least. > jparker@hpbs3645.boi.hp.com | > _____________________________________________________________________________ > Any opinions expressed herein are my own and not those of my employers. > _____________________________________________________________________________ > -- regards, +----------------------------------------------------------------------------+ | . . | Bob Baskett | | ... ... | Software Engineer | | ..... ..... | Business Systems Integration Group | | .. ... .. | Semiconductor Products Sector | | . . . | Mesa, AZ | | | President, Informix Users Group Of Arizona | | Motorola, Inc. | | +----------------------------------------------------------------------------+ | Sun 690MP 4.1.3, Online 5.01, 4.10.UD1 Tools, Fourgen v4.10.UC1 | +----------------------------------------------------------------------------+