[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [open-cobol-list] editing numeric data from alphanumeric strings

From: Bill Klein
Subject: Re: [open-cobol-list] editing numeric data from alphanumeric strings
Date: Fri, 9 Jan 2009 11:49:49 -0600

The NUMVAL functions (NumVal, NumVal-C, and (new) NumVal-F) do not TELL you
the number of decimal points, but they do support input with any number of
decimal points that would be valid in a COBOL data item (i.e. 18 in older
COBOL and 31 digits in current COBOL).

You can get the decimal part of a numeric-edited input field by using a
combination of NumVal functions and INTEGER-OF functions.  This would allow
you to "move" the output of a combination of functions to a
   Pic SV9(31)
receiving item to get all (and just) the decimal portions of an input field.

P.S.  I understand that there are MANY "de-editing" routines around -
especially for shops that started using '74 or earlier COBOL.  I was only
pointing out that OpenCOBOL includes the intrinsic function(s) to do most of
what is wanted by such routines. 

> -----Original Message-----
> From: Michael [mailto:address@hidden 
> Sent: Friday, January 09, 2009 11:29 AM
> Cc: address@hidden
> Subject: Re: [open-cobol-list] editing numeric data from 
> alphanumeric strings
> NUMGET has more of a free input format I think, where the NumVal-C 
> function requires a more specific input format, other than 
> that it does 
> about the same thing. Most importantly, if NUMGET doesn't do 
> what I want 
> it to do in one program, I can change it's functionality, and 
> I couldn't 
> do that with NumVal. Finally this routine was initially written using 
> Cobol74, where functions didn't exist and I've been using it for 20 
> years. What I've learned over the years, is that there are 
> many methods 
> that add to ones madness, and oddly, we stick to what we know.
> You might convince me to change my ways. Using NumVal-C, Can 
> it return 
> to the caller the number of decimal places found in the input string?
> Using NUMGET the number of decimal places is not predetermined, the 
> input string can optionally have/not have a decimal, and if 
> it does have 
> a decimal, it can be anywhere in the numeric portion of the input 
> string. Here's a NUMGET example where the user input from the screen 
> must be numeric, and no more than two decimal places: <<Here the user 
> has entered a discount amount.>>
>      Move Sc1-Disc-Amt To Num-1.
>      Call "NUMGET" Using Num-1 Num-2 N-Dec N-Err.
>      If N-Err Not = Zero Or N-Dec Greater Than 2 Or Num-2 Negative
>          Move "Invalid Number" To Screen-Message
>          Go To 7110-Error.
>      Compute Wk1-Disc-Amt = Num-2 / 10 ** N-Dec.
>      If Wk1-Disc-Amt Greater Than Wk1-Unit-Price
>          Move "Discount Amount Exceeds Unit Price"
>              To Screen-Message
>          Go To 7110-Error.
>      Compute Wk1-Net-Price = Wk1-Unit-Price - Wk1-Disc-Amt.
> You are correct, using standard Cobol is good practice.
> -- 
> Michael Anderson,
> J3k Solutions
> Sr.Systems Programmer/Analyst
> 832.515.3868
> Bill Klein wrote:
> > I haven't' followed all your logic, but can you tell me 
> what your program
> > does that 
> >   FUNCTION NumVal-C
> > doesn't do?  (Especially if used in conjunction with TEST-NumVal-C)
> >
> > It would seem to me that using the "native" COBOL language 
> syntax to do this
> > is usually the best way to go.
> >
> > In fact, ever since the '85 Standard, if you input actually 
> comes in - in a
> > way that matches the PICTURE clause of a numeric-edited 
> item, you can simply
> > MOVE it to a numeric receiving item to "de-edit" it.  I 
> know that with real
> > user input, this often doesn't happen as "leading spaces" 
> are too often
> > "typed in" as trailing spaces, causing a "mis-match" 
> between user input and
> > program PICTURE clause. 
> >
> >
> >   
> --------------------------------------------------------------
> ----------------
> Check out the new Marketplace.
> It is the best place to buy or sell services for
> just about anything Open Source.
> _______________________________________________
> open-cobol-list mailing list
> address@hidden

reply via email to

[Prev in Thread] Current Thread [Next in Thread]