CHKNUM: Checking a String for Numeric Format

How to:

The CHKNUM function checks a character string for numeric format. If the string contains a valid numeric format, CHKNUM returns the value 1. If the string contains characters that are not valid in a number, CHKNUM returns zero (0).

Syntax: How to Check the Format of a Character String

CHKNUM(numchar, source_string, output)

where:

numchar

Integer

Is the number of characters in the string.

string

Alphanumeric

Is the character string to be checked enclosed in single quotation marks, or a field or variable that contains the character string.

output

Numeric

Is the name of the field that contains the result, or the format of the output value enclosed in single quotation marks.

Example: Checking a String for Numeric Format

CHKNUM examines the strings STR1, STR2, and STR3 for numeric format.

DEFINE FILE WF_RETAIL_LITE
STR1/A8 = '12345E01';
STR2/A8 = 'ABCDEFG';
STR3/A8 = '1234.567';
CHK1/I1= CHKNUM(8,STR1,CHK1);
CHK2/I1= CHKNUM(8,STR2,CHK2);
CHK3/I1= CHKNUM(8,STR3,CHK3);
END
TABLE FILE WF_RETAIL_LITE
PRINT STR1 IN 20 CHK1 STR2 CHK2 STR3 CHK3
BY PRODUCT_CATEGORY
WHERE PRODUCT_CATEGORY EQ 'Video Production'
ON  TABLE SET PAGE NOPAGE
ON TABLE PCHOLD FORMAT WP
END

The output is:

  Product                                                                                                                         
  Category           STR1      CHK1  STR2      CHK2  STR3      CHK3                                                               
  --------           ----      ----  ----      ----  ----      ----                                                               
  Video Production   12345E01     1  ABCDEFG      0  1234.567     1
                     12345E01     1  ABCDEFG      0  1234.567     1
                     12345E01     1  ABCDEFG      0  1234.567     1
                     12345E01     1  ABCDEFG      0  1234.567     1
                     12345E01     1  ABCDEFG      0  1234.567     1
                     12345E01     1  ABCDEFG      0  1234.567     1