Newbie question : Checking for numeric field value
Posted in 2000
Topics: Connectivity: ESQL/C, 4GL & Embedded SQL
4GL Gurus: I have a data field being loaded into my Informix 7.20 server that I need to insure contains a numeric value. I checked the 4GL 6.0 manual and wasn't able to find a reference for a NUMERIC check. Does one exist or is there some substitute that I should use. Thanks!
> I have a data field being loaded into my ? What do you mean with "loaded" Is this a uoload or a user entry ? 1: If it's a user entry and your datafield is of type CHAR you can force the entry to numbers by using a special field in your form.frm [t006] t006 = FORMONLY.anumber Type Integer; In your 4GL program user do a INPUT F_charvar FROM anumber 2: If you have todo a converson from a string to a number use a function something like this: Function strtodec( F_str ) Define F_str Char(60), F_chr Char( 1), F_stx Smallint, F_dec Float, # Decimal deler F_idx Smallint, F_len Smallint, F_sgn Smallint, # Sign + - F_dgt Smallint, # One digit F_flt Float Let F_sgn = 1 # Positive number Let F_stx = FALSE # Hunting for start f number Let F_dec = 0 # No decimal digits yet Let F_flt = 0 # Start at 0 Let F_idx = 1 Let F_len = Length( F_str ) While( F_idx <= F_len ) Let F_chr = F_str[F_idx] Case When in_strng( F_chr, "0123456789" ) Let F_stx = TRUE Let F_dgt = F_chr If( F_dec )Then Let F_dec = F_dec * 10 Let F_flt = F_flt + (F_dgt / F_dec) Else Let F_flt = F_flt * 10 + F_dgt End if When NOT F_dec And F_chr = '.' Let F_stx = TRUE Let F_dec = TRUE When NOT F_stx And F_chr = '-' Let F_stx = TRUE Let F_sgn = -1 When F_stx Exit while End case Let F_idx = F_idx + 1 End while If( F_stx )Then Let F_flt = F_flt * F_sgn Else Initialize F_flt To NULL End if Return F_flt End function bibi ARthur In article <01bf6f42$1e87bc80$02b0b286@pcmis1>, "David Murray" <pcmis1@localnet.com> wrote: > 4GL Gurus: > > I have a data field being loaded into my Informix 7.20 server that I need > to insure contains a numeric value. I checked the 4GL 6.0 manual and wasn't > able to find a reference for a NUMERIC check. Does one exist or is there > some substitute that I should use. > > Thanks! > Sent via Deja.com http://www.deja.com/ Before you buy.
Sorry for the ambiguity. The data is being loaded into the server via a batch 'LOAD', so I can't simply modify the screen to prevent the situation. Additionally, I may not be able to convert the non-numeric data to it's numerical equivalent. (A23 -> ?.) I simply want to detect data that isn't numeric and write it to a report for later analysis. The load process will continue minus the 'bad' rows. Hopefully, this info will help 'stimulate' answers. ;*) <arthur_apw@my-deja.com> wrote in message news:87h32p$t1g$1@nnrp1.deja.com... > > I have a data field being loaded into my > ? What do you mean with "loaded" > Is this a uoload or a user entry ? > > 1: If it's a user entry and your datafield is of type CHAR > you can force the entry to numbers by using a special field > in your form.frm > [t006] > t006 = FORMONLY.anumber Type Integer; > In your 4GL program user do a INPUT F_charvar FROM anumber > > 2: If you have todo a converson from a string to a number > use a function something like this: > Function strtodec( F_str ) > Define > F_str Char(60), > F_chr Char( 1), > F_stx Smallint, > F_dec Float, > # Decimal deler > F_idx Smallint, > F_len Smallint, > F_sgn Smallint, > # Sign + - > F_dgt Smallint, > # One digit > F_flt Float > > Let F_sgn = 1 > # Positive number > Let F_stx = FALSE > # Hunting for start f number > Let F_dec = 0 > # No decimal digits yet > Let F_flt = 0 > # Start at 0 > Let F_idx = 1 > Let F_len = Length( F_str ) > > While( F_idx <= F_len ) > Let F_chr = F_str[F_idx] > Case > When in_strng( F_chr, "0123456789" ) > Let F_stx = TRUE > Let F_dgt = F_chr > If( F_dec )Then > Let F_dec = F_dec * 10 > Let F_flt = F_flt + (F_dgt / > F_dec) > Else > Let F_flt = F_flt * 10 + F_dgt > End if > When NOT F_dec And F_chr = '.' > Let F_stx = TRUE > Let F_dec = TRUE > When NOT F_stx And F_chr = '-' > Let F_stx = TRUE > Let F_sgn = -1 > When F_stx > Exit while > End case > Let F_idx = F_idx + 1 > End while > > If( F_stx )Then > Let F_flt = F_flt * F_sgn > Else > Initialize F_flt To NULL > End if > > Return F_flt > End function > > > bibi > ARthur > > > > In article <01bf6f42$1e87bc80$02b0b286@pcmis1>, > "David Murray" <pcmis1@localnet.com> wrote: > > 4GL Gurus: > > > > I have a data field being loaded into my Informix 7.20 server that I > need > > to insure contains a numeric value. I checked the 4GL 6.0 manual and > wasn't > > able to find a reference for a NUMERIC check. Does one exist or is > there > > some substitute that I should use. > > > > Thanks! > > > > > Sent via Deja.com http://www.deja.com/ > Before you buy.
Which version of the database do you have? Does it support VIOLATIONS? I've not used them, but they are supposed to be for exactly this sort of thing. Also, DBLOAD and HPL can handle errors in the input data. So can SQLCMD (available from the IIUG archives), at least up to a point. David Murray wrote: > Sorry for the ambiguity. The data is being loaded into the server via a > batch 'LOAD', so I can't simply modify the screen to prevent the situation. > Additionally, I may not be able to convert the non-numeric data to it's > numerical equivalent. (A23 -> ?.) I simply want to detect data that isn't > numeric and write it to a report for later analysis. The load process will > continue minus the 'bad' rows. Hopefully, this info will help 'stimulate' > answers. ;*) > > <arthur_apw@my-deja.com> wrote in message > news:87h32p$t1g$1@nnrp1.deja.com... > > > I have a data field being loaded into my > > ? What do you mean with "loaded" > > Is this a uoload or a user entry ? Very important questions, which David answered as 'LOAD'. -- Jonathan Leffler (jleffler@informix.com, jleffler@earthlink.net) Guardian of DBD::Informix v0.95 -- see http://www.perl.com/CPAN #include <disclaimer.h>