Arthur Frank wonders about checking a character to see
if is of a certain type, as referenced by this snippet
of his post:
> Is there an easy way, in COBOL, to determine if the 1st
> character of a string is not a letter (A-Z)?
There are numerous ways to to this. I would like to show you
one way, which when understood, can be used to solve all sorts
of interesting problems with cobol without having to resort
to total 'brute force'.
In cobol you can define your own class as shown by the
code I copied from a running program below. In this instance
I have 3 different classes defined (valid-op, num-lit, num-pic).
There are also built-in classes that you can use like 'numeric' and
'alphabetic'. The cobol manual will help you with the predefined
classes (I always have to look myself).
SPECIAL-NAMES.
CONDITION-CODE IS C-CODE
CLASS VALID-OP IS "=","#","<",">","{","}","~","!","(",")"
CLASS NUM-LIT IS "0","1","2","3","4","5","6","7","8","9",
".",","
CLASS NUM-PIC IS "0","1","2","3","4","5","6","7","8","9",
".",",","Z","z".
In your code you can test one or more characters for membership in
the defined class. This is some code from the same program checking
a substring to see if the characters are all of the 'num-lit' class:
IF WS-PARM-WORK (1:WS-PARM-LEN) NUM-LIT
If all the chars are in the NUM-LIT class then we get a 'true' condition
else we get a 'false' condition evaluation.
Duane Percox wk: 650.372.0200x608 fax: 650.372.3386
[log in to unmask]
www.qss.com
qwebs.qss.com
* To join/leave the list, search archives, change list settings, *
* etc., please visit http://raven.utc.edu/archives/hp3000-l.html *
|