Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Help !! Numeric field in COBOL

3 views
Skip to first unread message

su...@aquas.com

unread,
Jul 29, 1997, 3:00:00 AM7/29/97
to

Hi,

i need immediate help regarding handling of numeric field in COBOL85
on
HP 3000 platform.

I have a field like 9(12)V9(6). I want to check if the field is
numeric or if it has any alphanumeric character. Is there a function
call
i can use to do a quick check ?

I am reading a field from input file as 9(12)V9(6). I am then putting
this field in the database (ingres). Before putting in Ingres database
i want to perform a check to make sure that the field is NUMERIC.

Please let me know if there is a function which can be used. If not,
do
you have a code which does this check ? THanks, Sunil

-------------------==== Posted via Deja News ====-----------------------
http://www.dejanews.com/ Search, Read, Post to Usenet

William Lynch

unread,
Jul 30, 1997, 3:00:00 AM7/30/97
to

If the field is WS-DOLLAR-AMOUNT, you can code:

IF WS-DOLLAR-AMOUNT NUMERIC ...

or

IF WS-DOLLAR-AMOUNT NOT NUMERIC ...

It's a good edit check for any numeric field from outside your system.

Bill Lynch


Bruce D. Sinclair

unread,
Jul 30, 1997, 3:00:00 AM7/30/97
to

If it's a DISPLAY usage data item, COBOL has the NUMERIC class
test for determining if the item is a valid numeric data item. For
example,
if the data item's data-name is VALUE01, then

IF VALUE01 IS NUMERIC
{put in database}
ELSE
{display error message}
END-IF

verifies that VALUE01 contains only valid digits. If the data item were
signed, the NUMERIC class test also validates that the item has a
valid sign in the correct position (leading or trailing, combined or
separate).
Some COBOL implementations extend the NUMERIC class test to work
for PACKED-DECIMAL (aka COMP-3) usage data items. If the data item
is BINARY (aka COMP or COMP-4) usage, then there is no way to validate
the item (other than it conforms to the PICTURE restrictions), so few,
if any, implementations allow a NUMERIC class test on such items.

--Bruce Sinclair, Liant Software Corporation

su...@aquas.com wrote in article <8702222...@dejanews.com>...

Bill Herron

unread,
Jul 30, 1997, 3:00:00 AM7/30/97
to

> i need immediate help regarding handling of numeric field in COBOL85 on
> HP 3000 platform.

This problem is general to all COBOL situations.

> I have a field like 9(12)V9(6). I want to check if the field is numeric
or if it has any
> alphanumeric character. Is there a function call i can use to do a quick
check ?

How about using the IS NUMERIC condition on the field:

01 WS-FIELD PIC 9(12)V9(6).

IF WS-FIELD IS NUMERIC
THEN
save to database.

If that doesn't work, you can try a less elegant approach:

01 WS-FIELD PIC 9(12)V9(6).
01 WS-FIELD-CHAR REDEFINES WS-FIELD
PIC 9(01)
OCCURS 18 TIMES.

Then use a loop to see if each WS-FIELD-CHAR is greater than 0 or less than
9. The problem here is that you may get an error if an alphabetic is in
one of these positions.

So use

01 WS-FIELD-CHAR REDEFINES WS-FIELD
PIC X(01)
OCCURS 18 TIMES.

Then check to see if each WS-FIELD-CHAR is greater than '0' and less than
'9'.

There may be other solutions to this (and I'm sure my fellow posters will
have them). This should get you on the right track, though.

Bill


-------------==== Posted via Sexzilla News ====------------------
http://www.sexzilla.com Search, Read, Post to Usenet
-------------==== With A Whole Lot More ====------------------


Sabine Rother-Scholz

unread,
Jul 30, 1997, 3:00:00 AM7/30/97
to

Bill Herron wrote:
>
> > i need immediate help regarding handling of numeric field in COBOL85 on
> > HP 3000 platform.
>
> This problem is general to all COBOL situations.
>
> > I have a field like 9(12)V9(6). I want to check if the field is numeric
> or if it has any
> > alphanumeric character. Is there a function call i can use to do a quick
> check ?
>
> How about using the IS NUMERIC condition on the field:
>
> 01 WS-FIELD PIC 9(12)V9(6).
>
> IF WS-FIELD IS NUMERIC
> THEN
> save to database.
>

(snip)

How about

01 WS-FIELD-X.
05 WS-FIELD PIC 9(12)V9(6).

IF WS-FIELD-X IS NUMERIC ....

Testing a numeric-defined field could be a problem. But group-fields are
always handled as alpha-numeric.

Greetings
Sabine

LeFew

unread,
Jul 30, 1997, 3:00:00 AM7/30/97
to

It sounds as if you are answering your own question. Redefine your field
as alphanumeric (some compilers will allow a 'type' trap if the data is
alphanumeric) and simply ask "if field numeric...else...!

0 new messages