|
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 2.0.0.19 (Windows/20081209) |
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 programdoes that FUNCTION NumVal-Cdoesn'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 andprogram PICTURE clause.
[Prev in Thread] | Current Thread | [Next in Thread] |