Monday, September 26, 2011

COBOL: Checking if alphanumeric

The below sample program demonstrates how to check if a field is alphanumeric.

ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
SPECIAL-NAMES.
CLASS VALID-NAME 'A' THRU 'I'
'J' THRU 'R'
'S' THRU 'Z'
'0' THRU '9'.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 Var1 Pic x(4) value 'AB12'.
01 Var2 Pic x(4) value 'A C3'.

PROCEDURE DIVISION.
If Var1 VALID-NAME
Display 'Var1 is valid'
else
Display 'Var1 is invalid'
end-if.

If Var2 VALID-NAME
Display 'Var2 is valid'
else
Display 'Var2 is invalid'
end-if.

GOBACK.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.