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

how to validate whether a field has alphanumeric valueornot?


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

New User


Joined: 05 May 2008
Posts: 5
Location: mumbai

PostPosted: Wed Jun 04, 2008 8:57 pm
Reply with quote

i have a variable say A(6). how can i check whether the value present in the variable is alphanumeric or not? is there any special syntax for that?
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Wed Jun 04, 2008 9:27 pm
Reply with quote

what is A(6)? that is not a variable name or picture clause.

besides, everything is alphanumeric in singlebyte types.
Back to top
View user's profile Send private message
CICS Guy

Senior Member


Joined: 18 Jul 2007
Posts: 2146
Location: At my coffee table

PostPosted: Wed Jun 04, 2008 9:34 pm
Reply with quote

Try looking at Checking for Alphanumeric data
Back to top
View user's profile Send private message
mmwife

Super Moderator


Joined: 30 May 2003
Posts: 1592

PostPosted: Thu Jun 05, 2008 5:26 am
Reply with quote

Hi ashesh,

Just remember when reading the above thread, that 'A' THRU 'Z' and 'a' THRU 'z' will contain "junk" values.

If you have an IBM "green card" (or whatever its equivalent is these days) it will show you what the ranges need to be to eliminate those "junk" values.
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19243
Location: Inside the Matrix

PostPosted: Thu Jun 05, 2008 6:22 am
Reply with quote

Hello,

Quote:
how can i check whether the value present in the variable is alphanumeric or not
First, you need to define what are all of the "good" values for a byte (are lower-case letters valid or junk?). Then you need to define any other rules (for example, is an embedded space valid or not?).

Once the rules are defined, you can then implement code to enforce them. If you post all of the rules, we may be able to offer suggestions.
Back to top
View user's profile Send private message
yogeshwar_ade

Active User


Joined: 31 Aug 2006
Posts: 103
Location: INDIA

PostPosted: Thu Jun 05, 2008 8:08 am
Reply with quote

ashesh choudhury wrote:
i have a variable say A(6). how can i check whether the value present in the variable is alphanumeric or not?


Ashesh, if I am not wrong A(6) is your Picture Clause. 'A' is for ALPHABATIC PIC.


You can use SPECIAL-NAME for this one.


Yogeshwar
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19243
Location: Inside the Matrix

PostPosted: Thu Jun 05, 2008 8:37 am
Reply with quote

Hello,

Please post your SPECIAL-NAME solution for the posted requirement.
Back to top
View user's profile Send private message
ashesh choudhury

New User


Joined: 05 May 2008
Posts: 5
Location: mumbai

PostPosted: Thu Jun 05, 2008 9:15 am
Reply with quote

Thanks for your replies.
Actually in the field everything EXCEPT special charecters are allowed.so can anybody provide a way to check whether the field contains any special charecter or not.
for example ,"ABC990' is allowed
but "*-/+@?" is not allowed.
Is there any way for ensuring this?
Back to top
View user's profile Send private message
yogeshwar_ade

Active User


Joined: 31 Aug 2006
Posts: 103
Location: INDIA

PostPosted: Thu Jun 05, 2008 10:05 am
Reply with quote

dick scherrer wrote:
Hello,

Please post your SPECIAL-NAME solution for the posted requirement.



Here it is...

Code:

 ENVIRONMENT DIVISION.                         
 CONFIGURATION SECTION.                       
 SOURCE-COMPUTER.  IBM-370.                   
 OBJECT-COMPUTER.  IBM-370.                   
 SPECIAL-NAMES. CLASS VALID-DATA   '0' THRU '9'
                                   'A' THRU 'Z'.



Here VALID-DATA will work as ALPHANUMERIC CLASS, will check ALPHABETIC & NUMERIC values. If you want to add SPACES or any other symbol, you can add these to your VALID-DATA class.

Here, we are defining our own CLASS VALID-DATA.


We can use VALID-DATA as 'IS VALID-DATA' condition, similar of 'IS NUMERIC' check.

Code:


IF VARIABLE-NAME IS VALID-DATA
NEXT SENTENCE
ELSE
DISPLAY "VARIABLE-NAME is not ALPHANUMERIC".




Correct me If I am wrong.

Yogeshwar
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Thu Jun 05, 2008 11:59 am
Reply with quote

does defining the class as A thru Z,
will this define the value range as: x'C1' thru x'E9'
or as: x'C1' thru x'C9', x'D1' thru x'D9' and x'E1' thru x'E9'?
Back to top
View user's profile Send private message
yogeshwar_ade

Active User


Joined: 31 Aug 2006
Posts: 103
Location: INDIA

PostPosted: Thu Jun 05, 2008 12:28 pm
Reply with quote

Characters A thru Z are not contiguous.There are a few printables in there, like "\" AND "}" To be safe you should code it:

Code:


'A' THRU 'I'   'J' THRU 'R'   'S' THRU 'Z'   




For more help on SPECIAL-NAMES have a look on
This Thread
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19243
Location: Inside the Matrix

PostPosted: Thu Jun 05, 2008 7:02 pm
Reply with quote

Hello,

Quote:
Correct me If I am wrong.
Yes, you are wrong. . . Your example allows characters that should not be allowed.

Quote:
Actually in the field everything EXCEPT special charecters are allowed
What about hex values that are not on the keyboard? I suspect those too should be rejected.

Look at my earliest post - you need to define exactly which characters are "good" and if there are any rules beyond a single-character validation. It is time to actually do the specification, not talk in generalaties. Once the specifics, some generalization is probably possible (i.e. A-I, etc). As has been mentioned A-Z is not correct.
Back to top
View user's profile Send private message
yogeshwar_ade

Active User


Joined: 31 Aug 2006
Posts: 103
Location: INDIA

PostPosted: Fri Jun 06, 2008 7:26 am
Reply with quote

yogeshwar_ade wrote:
Characters A thru Z are not contiguous.There are a few printables in there, like "\" AND "}" To be safe you should code it:

Code:


'A' THRU 'I'   'J' THRU 'R'   'S' THRU 'Z'   






Thanks D for correcting me.
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19243
Location: Inside the Matrix

PostPosted: Fri Jun 06, 2008 7:51 am
Reply with quote

Hello,

Quote:
Thanks D for correcting me.
You're welcome, but i'd not have included that bit if i'd seen your earlier correction when i replied. Seems like a bit of strange magic. . .

Sorry for the overdose icon_redface.gif

Hopefully, TS has what is needed to implement the required code.
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 Help required to reset decimal points... DFSORT/ICETOOL 8
No new posts Sorting Date Field DFSORT/ICETOOL 4
No new posts Replace Multiple Field values to Othe... DFSORT/ICETOOL 12
No new posts Join 2 files according to one key field. JCL & VSAM 3
No new posts How to move the first field of each r... DFSORT/ICETOOL 5
Search our Forums:

Back to Top