[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: Michael
Subject: Re: [open-cobol-list] editing numeric data from alphanumeric strings
Date: Fri, 09 Jan 2009 11:28:52 -0600
User-agent: Thunderbird (Windows/20081209)

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

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.

reply via email to

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