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

confusion with alphanumeric characters


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

New User


Joined: 16 Jan 2006
Posts: 53
Location: pune

PostPosted: Mon Apr 10, 2006 8:28 pm
Reply with quote

Hi all,

If var1 start with a numeric and rest contains any non numeric characters then display 'warning'

If var1(1:1) is numeric and ?

If var1 start with other than alphanumeric character then display 'invalid'.

var1 pic x(9)

Pls help to code above two conditions.

Thanks,
Dipanshu G.
Back to top
View user's profile Send private message
DavidatK

Active Member


Joined: 22 Nov 2005
Posts: 700
Location: Troy, Michigan USA

PostPosted: Tue Apr 11, 2006 12:48 am
Reply with quote

dipanshu,

Quote:

If var1 start with other than alphanumeric character then display 'invalid'.


The assumption is that you meant numeric, not alphanumeric above.

Code:


    05  VAR1             PIC X(9).


    IF VAR1(1:1) NOT NUMERIC
    THEN
        DISPLAY 'INVALID'
    ELSE
        IF VAR1(2:8) NOT NUMERIC
        THEN
            DISPLAY 'WARNING'
        END-IF
    END-IF
       


Dave
Back to top
View user's profile Send private message
dipanshu

New User


Joined: 16 Jan 2006
Posts: 53
Location: pune

PostPosted: Tue Apr 11, 2006 9:09 am
Reply with quote

Hi,

Thanks dave, But I am seeking for the condition to test alphanumeric character.

As per my perception alphanumeric character set includes :-
numeric + alphabet + national characters.

Is there any shortcut and what are the characters included in national character?

Thanks,
Dipanshu G.
Back to top
View user's profile Send private message
Marso

REXX Moderator


Joined: 13 Mar 2006
Posts: 1353
Location: Israel

PostPosted: Tue Apr 11, 2006 7:10 pm
Reply with quote

Try the following:

In the ENVIRONMENT DIVISION add

Code:
CONFIGURATION SECTION.
SPECIAL-NAMES.
    CLASS NATCHARSET IS 'A' THROUGH 'I' 'J' THROUGH 'R'
                        'S' THROUGH 'Z' '0' THROUGH '9'
                        '$%&()<>/?=+-_'.

(place as many national characters as you want, add also lowercase if you wish and don't forget to add QUOTE if you need to).

Then you can just ask:

Code:
IF VAR1(1:1) IS NUMERIC THEN
    DISPLAY 'WARNING'
ELSE
    IF VAR1(1:1) NOT NATCHARSET THEN
        DISPLAY 'INVALID'
    ELSE
        DISPLAY 'OK'
    END-IF
END-IF
Back to top
View user's profile Send private message
dipanshu

New User


Joined: 16 Jan 2006
Posts: 53
Location: pune

PostPosted: Tue Apr 11, 2006 8:10 pm
Reply with quote

many thanks to u.
Back to top
View user's profile Send private message
Marso

REXX Moderator


Joined: 13 Mar 2006
Posts: 1353
Location: Israel

PostPosted: Wed Apr 12, 2006 11:57 am
Reply with quote

The only drawback with this method is that the defined CLASS(es) can be used only with IF statements, not with EVALUATE.
Back to top
View user's profile Send private message
ap_mainframes

Active User


Joined: 29 Dec 2005
Posts: 181
Location: Canada

PostPosted: Mon Apr 17, 2006 3:10 pm
Reply with quote

Hey marso,

What are these classes and where and when are they used ( apart from the example given).
Can you throw some light on this??
If you can provide some document on this then it would be best.

Thanks for all the information you can provide.

Ap_mainframes.
Back to top
View user's profile Send private message
bhgh
Warnings : 1

New User


Joined: 18 Mar 2006
Posts: 21
Location: Hyderabad

PostPosted: Mon Apr 17, 2006 4:52 pm
Reply with quote

Hi dave,
explain about Var1(1:1) ,
while executing the program how it will check this condition.
Back to top
View user's profile Send private message
DavidatK

Active Member


Joined: 22 Nov 2005
Posts: 700
Location: Troy, Michigan USA

PostPosted: Mon Apr 17, 2006 11:16 pm
Reply with quote

bhgh,,

I think the link below to reference modification will answer your question.

REFERENCE MODIFICATION

Var1(1:1) is the alphanumeric substring of Var1 starting at char position 1 with a length of 1.

If you do not understand, Please come back and I will try to explain differently,

Dave
Back to top
View user's profile Send private message
Marso

REXX Moderator


Joined: 13 Mar 2006
Posts: 1353
Location: Israel

PostPosted: Tue Apr 25, 2006 12:10 pm
Reply with quote

A CLASS is a set of specific characters. Here are more samples:

Code:
CONFIGURATION SECTION.
SPECIAL-NAMES.
    CLASS HEXADECIMAL IS '0123456789ABCDEF'
    CLASS BINARY IS '01'.

Note: if you define more than one class, put only one dot after the last, not between.

Classes defined in this way can be used only in a "class condition", which means the only thing you can do is ask:

Code:
01  MY-FIELD1   PIC X(8)    VALUE '003AC968'.
01  MY-FIELD2   PIC X(8)    VALUE '01101011'.

IF MY-FIELD1 IS HEXADECIMAL THEN
    ...
IF MY-FIELD2 IS NOT BINARY THEN
    ...
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 Substring number between 2 characters... DFSORT/ICETOOL 2
No new posts Reading dataset in Python - New Line ... All Other Mainframe Topics 22
No new posts Count the number of characters in a f... CA Products 1
No new posts convert alphanumeric PIC X(02) to hex... COBOL Programming 3
No new posts Tilde Characters Changing to COLONs i... CLIST & REXX 22
Search our Forums:

Back to Top