Easytrieve – check if value IS NUMERIC in an alpha variable

Similar to how we have the ‘IS NUMERIC’ verb in COBOL, we can validate if a Alphanumeric variable contains Numeric value or not in Easytrieve.

Sample program:

----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
 DEFINE WS-ALPHA W 6 A
 JOB INPUT NULL
* ----- NOT NUMERIC --------
 WS-ALPHA = 'AB1234'
 IF WS-ALPHA NUMERIC
    DISPLAY WS-ALPHA ' IS NUMERIC'
 ELSE
    DISPLAY WS-ALPHA ' IS NOT NUMERIC'
 END-IF
* ----- NUMERIC --------
 WS-ALPHA = '123456'
 IF WS-ALPHA NUMERIC
    DISPLAY WS-ALPHA ' IS NUMERIC'
 ELSE
    DISPLAY WS-ALPHA ' IS NOT NUMERIC'
 END-IF
* ----- NOT NUMERIC --------
 WS-ALPHA = '123.45'
 IF WS-ALPHA NUMERIC
    DISPLAY WS-ALPHA ' IS NUMERIC'
 ELSE
    DISPLAY WS-ALPHA ' IS NOT NUMERIC'
 END-IF
* ----- NOT NUMERIC --------
 WS-ALPHA = '  1234'
 IF WS-ALPHA NUMERIC
    DISPLAY WS-ALPHA ' IS NUMERIC'
 ELSE
    DISPLAY WS-ALPHA ' IS NOT NUMERIC'
 END-IF
 STOP

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.