Home > Archive > Cobol > June 2004 > Class Test for Valid Characters
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Class Test for Valid Characters
|
|
| Wes Jester 2004-06-29, 8:55 pm |
| I have set up a class test as
SPECIAL-NAMES.
CLASS ValidChar IS 'A' THRU 'Z',
'0' THRU '9'.
I need to verify that the input contains only these characters. I used a
full field name test and determined that errors were getting thru.
IF InMaster IS ValidChar
CONTINUE
ELSE
DISPLAY 'Error in Field'
END-IF
However, errors were showing up in the field.
When I test each character, I find that the backslash "\", X'E0', is considered
valid. HIGH_VALUEs, X 'FF' is also considered valid.
Does anyone know why these characters are considered valid cahracter within
the class test?
Wes
| |
| Colin Campbell 2004-06-29, 8:55 pm |
| Are you working in an ASCII or EBCDIC environment?
If it is EBCDIC, the upper case alphabetics are not all contiguous in
terms of their hex values, so you would have to test for
"A" THRU "I",
"J" THRU "R", and
"S" THRU "Z".
Hex 'E0' is higher than "R" and lower than "S".
It may be better (and less platform dependent) to test for
ALPHABETIC-UPPER, and if that is true, test for and eliminate the SPACE
character, or if it is false, test for NUMERIC.
Wes Jester wrote:
>I have set up a class test as
>SPECIAL-NAMES.
>
>CLASS ValidChar IS 'A' THRU 'Z',
> '0' THRU '9'.
>
>I need to verify that the input contains only these characters. I used a
>full field name test and determined that errors were getting thru.
>
>IF InMaster IS ValidChar
> CONTINUE
>ELSE
> DISPLAY 'Error in Field'
>END-IF
>
>However, errors were showing up in the field.
>
>When I test each character, I find that the backslash "\", X'E0', is considered
>valid. HIGH_VALUEs, X 'FF' is also considered valid.
>
>Does anyone know why these characters are considered valid cahracter within
>the class test?
>
>
>
>Wes
>
>
| |
| Binyamin Dissen 2004-06-29, 8:55 pm |
| On 29 Jun 2004 13:13:38 -0700 wes.jester@lmco.com (Wes Jester) wrote:
:>I have set up a class test as
:>SPECIAL-NAMES.
:>CLASS ValidChar IS 'A' THRU 'Z',
:> '0' THRU '9'.
:>I need to verify that the input contains only these characters. I used a
:>full field name test and determined that errors were getting thru.
:>IF InMaster IS ValidChar
:> CONTINUE
:>ELSE
:> DISPLAY 'Error in Field'
:>END-IF
:>However, errors were showing up in the field.
:>When I test each character, I find that the backslash "\", X'E0', is considered
:>valid. HIGH_VALUEs, X 'FF' is also considered valid.
:>Does anyone know why these characters are considered valid cahracter within
:>the class test?
I am assuming that you are using the EBCDIC character set.
'A' thru 'Z' = x'C1'-x'E9'. X'E0' is in that range
'0' thru '9' = x'F1'-x'F9'. No idea why x'FF' would be accepted.
Best (and machine independent) way to specify would be
'A', 'B', 'C', ....
--
Binyamin Dissen <bdissen@dissensoftware.com>
http://www.dissensoftware.com
Director, Dissen Software, Bar & Grill - Israel
| |
| Chuck Stevens 2004-06-29, 8:55 pm |
| You don't specify the machine, the compiler, or the native character set.
But this is not at all impossible, and in fact I can reproduce the problem
with the backslash "\" easily on a machine in which the native character set
is EBCDIC.
In that character set, "I" is hex C9, "J" is hex D1, "R" is hex D9 and "S"
is hex E2. The backslash "\" falls between "R" and "S" at hex E0. Thus,
"\" is indeed in the range "A" thru "Z" in the EBCDIC character set. If
ValidChar is changed to use the subranges of the alphabet rather than the
whole alphabet as a single subrange, the test against backslash works as I'd
expect it to.
If the character-set is ASCII, however -- "A" (hex 41) through "Z" (hex 5A)
follows "1" (hex 31) through "9" (hex 39) in the character-set ordering, and
both are followed by the backslash "\" (hex 5c). The ordering of the
literals in the CLASS specification isn't supposed to be significant, but
there could be some sort of bug somewhere that MIGHT be circumnavigable by
putting the literals in ascending order -- '1' THRU '9', 'A' THRU 'Z' .
I can't reproduce the behavior reported with "high-values".
-Chuck Stevens
"Wes Jester" <wes.jester@lmco.com> wrote in message
news:7f2ed50e.0406291213.4a6eefb0@posting.google.com...
> I have set up a class test as
> SPECIAL-NAMES.
>
> CLASS ValidChar IS 'A' THRU 'Z',
> '0' THRU '9'.
>
> I need to verify that the input contains only these characters. I used a
> full field name test and determined that errors were getting thru.
>
> IF InMaster IS ValidChar
> CONTINUE
> ELSE
> DISPLAY 'Error in Field'
> END-IF
>
> However, errors were showing up in the field.
>
> When I test each character, I find that the backslash "\", X'E0', is
considered
> valid. HIGH_VALUEs, X 'FF' is also considered valid.
>
> Does anyone know why these characters are considered valid cahracter
within
> the class test?
>
>
>
> Wes
| |
| Binyamin Dissen 2004-06-29, 8:55 pm |
| On Tue, 29 Jun 2004 14:13:06 -0700 Colin Campbell <cmcampb@adelphia.net>
wrote:
:>Are you working in an ASCII or EBCDIC environment?
:>If it is EBCDIC, the upper case alphabetics are not all contiguous in
:>terms of their hex values, so you would have to test for
:>"A" THRU "I",
:>"J" THRU "R", and
:>"S" THRU "Z".
:>Hex 'E0' is higher than "R" and lower than "S".
:>It may be better (and less platform dependent) to test for
:>ALPHABETIC-UPPER, and if that is true, test for and eliminate the SPACE
:>character, or if it is false, test for NUMERIC.
Would not work for 'Q3A5'.
:>Wes Jester wrote:
:>>I have set up a class test as
:>>SPECIAL-NAMES.
:>>CLASS ValidChar IS 'A' THRU 'Z',
:>> '0' THRU '9'.
:>>I need to verify that the input contains only these characters. I used a
:>>full field name test and determined that errors were getting thru.
:>>IF InMaster IS ValidChar
:>> CONTINUE
:>>ELSE
:>> DISPLAY 'Error in Field'
:>>END-IF
:>>However, errors were showing up in the field.
:>>When I test each character, I find that the backslash "\", X'E0', is considered
:>>valid. HIGH_VALUEs, X 'FF' is also considered valid.
:>>Does anyone know why these characters are considered valid cahracter within
:>>the class test?
--
Binyamin Dissen <bdissen@dissensoftware.com>
http://www.dissensoftware.com
Director, Dissen Software, Bar & Grill - Israel
| |
| JerryMouse 2004-06-29, 8:55 pm |
| Wes Jester wrote:
> I have set up a class test as
> SPECIAL-NAMES.
>
> CLASS ValidChar IS 'A' THRU 'Z',
> '0' THRU '9'.
>
> I need to verify that the input contains only these characters. I
> used a
> full field name test and determined that errors were getting thru.
>
> IF InMaster IS ValidChar
> CONTINUE
> ELSE
> DISPLAY 'Error in Field'
> END-IF
>
> However, errors were showing up in the field.
>
> When I test each character, I find that the backslash "\", X'E0', is
> considered valid. HIGH_VALUEs, X 'FF' is also considered valid.
>
> Does anyone know why these characters are considered valid cahracter
> within the class test?
-----
I don't think you can test a FIELD against a CLASS. Your test is probably
just testing the first character in the field.
Try:
PERFORM VARYING INDX FROM 1 BY 1 UNTIL INDX > FIELD-LEN
IF InMaster(INDX:1) ValidChar
CONTINUE
ELSE
DISPLAY "Error in Field"
EXIT PERFORM
END-PERFORM.
| |
| Chuck Stevens 2004-06-29, 8:55 pm |
| "JerryMouse" <nospam@bisusa.com> wrote in message
news:reKdnS8brsB2eHzdRVn-ug@giganews.com...
> I don't think you can test a FIELD against a CLASS. Your test is probably
> just testing the first character in the field.
Ummm... that's not the way I see it ...
ANSI X3.23-1985 page VI-56, paragraph 6.3.1.2, Class Condition: "The class
condition determines whether an operand ... contains only the characters in
the set of characters specified by the CLASS clause".
This is stated a bit more clearly and a bit more specifically in ISO/IEC
1989:2002 on page 133, paragraph 8.8.4.1.3, Class condition, general rule
2g: "If class-name-1 is specified, the condition is true if the content of
the data item referenced by identifier-1 consists entirely of the characters
listed in the definition of class-name-1 in the SPECIAL-NAMES paragraph."
-Chuck Stevens
| |
| Binyamin Dissen 2004-06-30, 3:55 am |
| On Tue, 29 Jun 2004 16:58:12 -0500 "JerryMouse" <nospam@bisusa.com> wrote:
:>Wes Jester wrote:
:>> I have set up a class test as
:>> SPECIAL-NAMES.
:>> CLASS ValidChar IS 'A' THRU 'Z',
:>> '0' THRU '9'.
:>> I need to verify that the input contains only these characters. I
:>> used a
:>> full field name test and determined that errors were getting thru.
:>> IF InMaster IS ValidChar
:>> CONTINUE
:>> ELSE
:>> DISPLAY 'Error in Field'
:>> END-IF
:>> However, errors were showing up in the field.
:>> When I test each character, I find that the backslash "\", X'E0', is
:>> considered valid. HIGH_VALUEs, X 'FF' is also considered valid.
:>> Does anyone know why these characters are considered valid cahracter
:>> within the class test?
:>I don't think you can test a FIELD against a CLASS. Your test is probably
:>just testing the first character in the field.
You certainly can.
It is no different than NUMERIC or ALPHABETIC, which apply to an entire field.
--
Binyamin Dissen <bdissen@dissensoftware.com>
http://www.dissensoftware.com
Director, Dissen Software, Bar & Grill - Israel
| |
| Lueko Willms 2004-06-30, 3:55 pm |
| .. Am 29.06.04
schrieb wes.jester@lmco.com (Wes Jester)
auf /COMP/LANG/COBOL
in 7f2ed50e.0406291213.4a6eefb0@posting.google.com
ueber Class Test for Valid Characters
WJ> CLASS ValidChar IS 'A' THRU 'Z',
WJ> '0' THRU '9'.
WJ>
WJ> I need to verify that the input contains only these characters. I
WJ> used a full field name test and determined that errors were getting
WJ> thru.
WJ>
WJ> IF InMaster IS ValidChar
Sort of "why simply, if it can be done with complications?", eh?
There is no need to specify your own class.
Standard COBOL allows you to write:
IF InMaster IS ALPHABETIC-UPPER or NUMERIC THEN
---- do something about it ...
yours,
Lüko Willms http://www.mlwerke.de
/--------- L.WILLMS@jpberlin.de -- Alle Rechte vorbehalten --
"Kein Land kann seine Probleme in dieser globalisierten Welt allein
auf sich gestellt lösen. Entweder wir retten uns alle zusammen oder
wir gehen zusammen unter. Heute mehr denn je gilt das Wort von José
Martí: Das Vaterland ist die ganze Menschheit."
- Fidel Castro, Caracas (Veneuzuela), 3. Februar 1999
| |
| JerryMouse 2004-06-30, 3:55 pm |
| Chuck Stevens wrote:
> "JerryMouse" <nospam@bisusa.com> wrote in message
> news:reKdnS8brsB2eHzdRVn-ug@giganews.com...
>
>
> Ummm... that's not the way I see it ...
>
> ANSI X3.23-1985 page VI-56, paragraph 6.3.1.2, Class Condition: "The
> class condition determines whether an operand ... contains only the
> characters in the set of characters specified by the CLASS clause".
>
> This is stated a bit more clearly and a bit more specifically in
> ISO/IEC 1989:2002 on page 133, paragraph 8.8.4.1.3, Class condition,
> general rule 2g: "If class-name-1 is specified, the condition is
> true if the content of the data item referenced by identifier-1
> consists entirely of the characters listed in the definition of
> class-name-1 in the SPECIAL-NAMES paragraph."
[slaps side of head]
Of course. What was I thinking?
| |
| Wes Jester 2004-06-30, 3:55 pm |
| Thanks to all who answered this question. I should have known to
specify EBCDIC. After 35 years in this business, I seem to be
overlooking the obvious and basic.
Wes
wes.jester@lmco.com (Wes Jester) wrote in message news:<7f2ed50e.0406291213.4a6eefb0@posting.google.com>...
> I have set up a class test as
> SPECIAL-NAMES.
>
> CLASS ValidChar IS 'A' THRU 'Z',
> '0' THRU '9'.
>
> I need to verify that the input contains only these characters. I used a
> full field name test and determined that errors were getting thru.
>
> IF InMaster IS ValidChar
> CONTINUE
> ELSE
> DISPLAY 'Error in Field'
> END-IF
>
> However, errors were showing up in the field.
>
> When I test each character, I find that the backslash "\", X'E0', is considered
> valid. HIGH_VALUEs, X 'FF' is also considered valid.
>
> Does anyone know why these characters are considered valid cahracter within
> the class test?
>
>
>
> Wes
| |
| Binyamin Dissen 2004-06-30, 3:55 pm |
| On 30 Jun 2004 10:08:00 GMT l.willms@jpberlin.de (Lueko Willms) wrote:
:> There is no need to specify your own class.
:> Standard COBOL allows you to write:
:> IF InMaster IS ALPHABETIC-UPPER or NUMERIC THEN
What is the result if InMaster contains 'Q3X5'?
--
Binyamin Dissen <bdissen@dissensoftware.com>
http://www.dissensoftware.com
Director, Dissen Software, Bar & Grill - Israel
| |
| docdwarf@panix.com 2004-06-30, 3:55 pm |
| In article <7f2ed50e.0406300344.19db9e57@posting.google.com>,
Wes Jester <wes.jester@lmco.com> wrote:
[snip]
>After 35 years in this business, I seem to be
>overlooking the obvious and basic.
.... or maybe your memory is just getting... porous.
DD
| |
| Lueko Willms 2004-06-30, 3:55 pm |
| .. Am 30.06.04
schrieb postingid@dissensoftware.com (Binyamin Dissen)
bei /COMP/LANG/COBOL
in hpb5e01erbp0bqqvc620iaksocpacumnoj@4ax.com
ueber Re: Class Test for Valid Characters
:>> Standard COBOL allows you to write:
:>> IF InMaster IS ALPHABETIC-UPPER or NUMERIC THEN
BD> What is the result if InMaster contains 'Q3X5'?
Oh, yeah. I got your point and withdraw my suggestion.
Yours,
Lüko Willms http://www.mlwerke.de
/--------- L.WILLMS@jpberlin.de -- Alle Rechte vorbehalten --
"Es sind nicht die Generäle und Könige, die die Geschichte machen,
sondern die breiten Massen des Volkes" - Nelson Mandela
|
|
|
|
|