View previous topic :: View next topic
|
Author |
Message |
smita V
New User
Joined: 05 Nov 2007 Posts: 11 Location: hyderabad
|
|
|
|
I need to check an alphanumeric string whether it consists of any Special characters. If so will post an error as special characters are not allowed.
I coded following:
ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
SPECIAL-NAMES. CLASS HAS-INVALID-CHARS '*' '(' ')' '!' '@' '^'
'$' '#' '&' '+' '=' '{' '}' '[' ']' ':' ';' '/' '\' '?' '>'
'<' '%' '`' '_' '|'.
PROCEDURE DIVISION.
IF CA-MAP-TI(1) EQUAL '2'
IF CA-MAP-REIN-ACCT-NO HAS-INVALID-CHARS
Post error.
I am testing the code by giving values to CA-MAP-REIN-ACCT-NO as 1234%678, !@#$%^&*. But the code is not posting the error.
When I am using the variable with relative byte for e.g CA-MAP-REIN-ACCT-NO(1:1) and giving values @1234567, it is posting the error with above code.
I want to know why the code is not working when I am using the variable without relative positioning. How can I make this work?
The special character can be in any of the 8 bytes.
Thanks in advance.
[/img][/url][/code][/quote] |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
Because without using reference modification, you are comparing '@1234567" to a single character. This comparison will always be false. You can make it work by using reference modificaition on each character of CA-MAP-REIN-ACCT-NO to do the comparison. |
|
Back to top |
|
|
smita V
New User
Joined: 05 Nov 2007 Posts: 11 Location: hyderabad
|
|
|
|
If I have to check each character using reference modification then I can do it with the help of 88 level clause also. what is the benefit of Special names over 88 level clause? |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
I can't answer that question because I've never had a need to use SPECIAL-NAMES data in the way you did. Of course, I've only been writing COBOL for 36 years, so there may yet come a day when I need to use it .... |
|
Back to top |
|
|
GuyC
Senior Member
Joined: 11 Aug 2009 Posts: 1281 Location: Belgium
|
|
|
|
Code: |
77 CA-MAP-REIN-ACCT-NO pic x(8).
move "!@#$%^&*" to CA-MAP-REIN-ACCT-NO
IF CA-MAP-REIN-ACCT-NO HAS-INVALID-CHARS
Post error. |
should work.
If it doesn't work maybe CA-MAP-REIN-ACCT-NO is not defined as X(8) containing spaces at the end.
class is used not as "has invalid chars", but as "consist solely out of invalid chars"
you can use INSPECT for what you're trying to do.
Code: |
move invar to testvar
INSPECT Testvar CONVERTING "%*&!..."
TO " "
if testvar <> invar
display "error"
end-if |
|
|
Back to top |
|
|
smita V
New User
Joined: 05 Nov 2007 Posts: 11 Location: hyderabad
|
|
|
|
I coded as given below and it is working now:
ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
SPECIAL-NAMES. CLASS WS-VALID-CHARS IS '0' THRU '9'
'A' THRU 'Z'.
PROCEDURE DIVISION.
IF CA-MAP-TI(1) EQUAL '2'
IF CA-MAP-REIN-ACCT-NO WS-VALID-CHARS
NEXT SENTENCE
ELSE
Post error.
Thanks for your help. |
|
Back to top |
|
|
Ronald Burr
Active User
Joined: 22 Oct 2009 Posts: 293 Location: U.S.A.
|
|
|
|
Close, but not quite correct.
'A' thru 'Z' (hex 'C1' thru hex 'E9') includes the non-alphabetic, non-numeric values x'CA', x'CB', x'CC', x'CD', x'CE', x'CF', x'D0', x'DA', x'DB', x'DC', x'DD', x'DE', x'DF', x'E0', and x'E1'.
What you probably SHOULD have coded, is
Code: |
SPECIAL-NAMES. CLASS WS-VALID-CHARS IS
'A' THRU 'I'
'J' THRU 'R'
'S' THRU 'Z'
'0' THRU '9'. |
And, if a SPACE is also valid, you should include that, as well. |
|
Back to top |
|
|
|