check the type of value in a field

I have a probelm. In a field in an Adabas file which is defined as aplha numeric I have both numerical data and alphanumeric one for different records. I need to get those records having only alphanumeric data in this field Can anyone help me out? IS there any predefined function to check this like ISNUMERIC() in COBOL

No.

KNOW THY DATA.

Ask those who put’ in mixed content for the rule they applied, I assume this didn’t happen randomly.

But, in COBOL terms, if you are talking about DISPLAY type data, and not COMP or COMP-3,
then Natural has

IF ... IS (format)
1 Like

Depending on what you are trying to do (eliminate numerics, identify records with numeric, identify which characters are wrong, etc) you might also have a look at IF field = MASK (…)

MASK possibilities include A (for upper and lower case alpha) N (for numeric digits) and I believe L (lower alpha) and U (upper alpha) (check on the last two, I am working from memory)

Hi Wolfgang ,

01.IF … IS (N3)

Is this used to check whether a variable has a value of type ‘N3’ ? or whether the variable is defined in the type ‘N3’

IS can be used to check if data in an A field can be converted to the target type.

As always … It’s in the documentation

Thanks Wolfgang Winter for the help

If there is more to it than a simple numeric / not numeric decision then you’ll have
to look at MASK as pointed out by Steve Robinson.

could you tell me the difference between IS (N9) ans MASK (99999)

regards

The difference is quite simple.

First, I presume you meant to compare IS (N9) and = MASK (999999999)

Let’s start with IS (N9). This checks to see if the contents of the alpha field can be “converted” by the VAL function into an N9 variable.

By contrast, = MASK (999999999) checks to see if the alpha field contains a string of digits between 000000000 and 999999999.

Here is a program that shows the main scenarios you might need to understand

DEFINE DATA LOCAL
1 #A (A9)
1 #N (N9)
END-DEFINE
*
INCLUDE AATITLER
INCLUDE AASETC
*
MOVE ‘123456789’ TO #A
WRITE 10T ‘***** TESTS FOR MOVE ‘‘123456789’’ TO #A
IF #A = MASK (999999999)
WRITE 10T ‘#A = MASK (999999999) IS TRUE’
ELSE
WRITE 10T ‘#A = MASK (999999999) IS FALSE’
END-IF
IF #A IS (N9)
WRITE 10T ‘#A IS (N9) IS TRUE’
ELSE
WRITE 10T ‘#A IS (N9) IS FALSE’
END-IF
COMPUTE #N = VAL (#A)
WRITE 10T ‘VAL (#A) IS’ #N
*
SKIP 1
MOVE ‘123’ TO #A
WRITE 10T '
TESTS FOR MOVE ‘‘123’’ TO #A
IF #A = MASK (999999999)
WRITE 10T ‘#A = MASK (999999999) IS TRUE’
ELSE
WRITE 10T ‘#A = MASK (999999999) IS FALSE’
END-IF
IF #A IS (N9)
WRITE 10T ‘#A IS (N9) IS TRUE’
ELSE
WRITE 10T ‘#A IS (N9) IS FALSE’
END-IF
COMPUTE #N = VAL (#A)
WRITE 10T ‘VAL (#A) IS’ #N
*
SKIP 1
MOVE ’ 123’ TO #A
WRITE 10T '
TESTS FOR MOVE ‘’ 123’’ TO #A
IF #A = MASK (999999999)
WRITE 10T ‘#A = MASK (999999999) IS TRUE’
ELSE
WRITE 10T ‘#A = MASK (999999999) IS FALSE’
END-IF
IF #A IS (N9)
WRITE 10T ‘#A IS (N9) IS TRUE’
ELSE
WRITE 10T ‘#A IS (N9) IS FALSE’
END-IF
COMPUTE #N = VAL (#A)
WRITE 10T ‘VAL (#A) IS’ #N
*
SKIP 1
MOVE ‘-123’ TO #A
WRITE 10T '
TESTS FOR MOVE ‘’-123’’ TO #A
IF #A = MASK (999999999)
WRITE 10T ‘#A = MASK (999999999) IS TRUE’
ELSE
WRITE 10T ‘#A = MASK (999999999) IS FALSE’
END-IF
IF #A IS (N9)
WRITE 10T ‘#A IS (N9) IS TRUE’
ELSE
WRITE 10T ‘#A IS (N9) IS FALSE’
END-IF
COMPUTE #N = VAL (#A)
WRITE 10T ‘VAL (#A) IS’ #N
*
SKIP 4
MOVE ‘12.3’ TO #A
WRITE 10T '
TESTS FOR MOVE ‘‘12.3’’ TO #A *****’
IF #A = MASK (999999999)
WRITE 10T ‘#A = MASK (999999999) IS TRUE’
ELSE
WRITE 10T ‘#A = MASK (999999999) IS FALSE’
END-IF
IF #A IS (N9)
WRITE 10T ‘#A IS (N9) IS TRUE’
ELSE
WRITE 10T ‘#A IS (N9) IS FALSE’
END-IF
COMPUTE #N = VAL (#A)
WRITE 10T ‘VAL (#A) IS’ #N
END

PAGE #   1                    DATE:    14-11-01
PROGRAM: MASKIS01             LIBRARY: INSIDE

     ***** TESTS FOR MOVE '123456789' TO #A *****
     #A = MASK (999999999) IS TRUE
     #A IS (N9) IS TRUE
     VAL (#A) IS  123456789

     ***** TESTS FOR MOVE '123' TO #A *****
     #A = MASK (999999999) IS FALSE
     #A IS (N9) IS TRUE
     VAL (#A) IS        123

     ***** TESTS FOR MOVE '      123' TO #A *****
     #A = MASK (999999999) IS FALSE
     #A IS (N9) IS TRUE
     VAL (#A) IS        123

     ***** TESTS FOR MOVE '-123' TO #A *****
     #A = MASK (999999999) IS FALSE
     #A IS (N9) IS TRUE
     VAL (#A) IS       -123

PAGE #   2                    DATE:    14-11-01
PROGRAM: MASKIS01             LIBRARY: INSIDE

     ***** TESTS FOR MOVE '12.3' TO #A *****
     #A = MASK (999999999) IS FALSE
     #A IS (N9) IS TRUE
     VAL (#A) IS         12

Note that blanks (leading and trailing) , decimal points, and minus (also plus) signs make the MASK test FALSE. By contrast all the IS tests above are TRUE.

ALL of the aspects of IS and MASK are well documented in Natural’s online help. If you do not have access to this documentation you should demand same from the company you work for.

1 Like

Thanks Steve,