View previous topic :: View next topic
|
Author |
Message |
dipanshu
New User
Joined: 16 Jan 2006 Posts: 53 Location: pune
|
|
|
|
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 |
|
|
DavidatK
Active Member
Joined: 22 Nov 2005 Posts: 700 Location: Troy, Michigan USA
|
|
|
|
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 |
|
|
dipanshu
New User
Joined: 16 Jan 2006 Posts: 53 Location: pune
|
|
|
|
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 |
|
|
Marso
REXX Moderator
Joined: 13 Mar 2006 Posts: 1353 Location: Israel
|
|
|
|
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 |
|
|
dipanshu
New User
Joined: 16 Jan 2006 Posts: 53 Location: pune
|
|
|
|
many thanks to u. |
|
Back to top |
|
|
Marso
REXX Moderator
Joined: 13 Mar 2006 Posts: 1353 Location: Israel
|
|
|
|
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 |
|
|
ap_mainframes
Active User
Joined: 29 Dec 2005 Posts: 181 Location: Canada
|
|
|
|
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 |
|
|
bhgh Warnings : 1 New User
Joined: 18 Mar 2006 Posts: 21 Location: Hyderabad
|
|
|
|
Hi dave,
explain about Var1(1:1) ,
while executing the program how it will check this condition. |
|
Back to top |
|
|
DavidatK
Active Member
Joined: 22 Nov 2005 Posts: 700 Location: Troy, Michigan USA
|
|
|
|
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 |
|
|
Marso
REXX Moderator
Joined: 13 Mar 2006 Posts: 1353 Location: Israel
|
|
|
|
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 |
|
|
|