IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Need some help on Special names...


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
smita V

New User


Joined: 05 Nov 2007
Posts: 11
Location: hyderabad

PostPosted: Thu Apr 07, 2011 2:55 pm
Reply with quote

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
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Thu Apr 07, 2011 3:14 pm
Reply with quote

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
View user's profile Send private message
smita V

New User


Joined: 05 Nov 2007
Posts: 11
Location: hyderabad

PostPosted: Thu Apr 07, 2011 3:32 pm
Reply with quote

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
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Thu Apr 07, 2011 4:50 pm
Reply with quote

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
View user's profile Send private message
GuyC

Senior Member


Joined: 11 Aug 2009
Posts: 1281
Location: Belgium

PostPosted: Thu Apr 07, 2011 5:09 pm
Reply with quote

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
View user's profile Send private message
smita V

New User


Joined: 05 Nov 2007
Posts: 11
Location: hyderabad

PostPosted: Thu Apr 07, 2011 7:16 pm
Reply with quote

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
View user's profile Send private message
Ronald Burr

Active User


Joined: 22 Oct 2009
Posts: 293
Location: U.S.A.

PostPosted: Fri Apr 08, 2011 3:12 am
Reply with quote

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
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts Capturing COBOL job and program names... All Other Mainframe Topics 2
No new posts Read file names from existing file th... DFSORT/ICETOOL 6
No new posts Problem while sending special charact... JCL & VSAM 4
No new posts Unable to retrieve Datasets Names usi... CLIST & REXX 20
No new posts Column names in SYSIBM tables DB2 5
Search our Forums:

Back to Top