localsxonly
localsxonly

Reputation: 31

How to validate a negative value being passed in as a alphanumeric literal?

Basically, I've been given an input file that gets passed in too a mix of fields that are alphanumeric and numeric. My goal is to test each field for valid data. The first field is an alphanumeric with a Pic X(3) description that should represent a number. However, because i'm testing for data validity there will be instances where the value could have a letter in there such as 0R1 or a negative value -001.

When testing for data, using the "Is Numeric" test works perfectly for finding values that aren't numeric. However, it fails the test when there is a negative sign being passed in. I assume this is happening because it recognizes that a dash or negative symbol (-) is not a numeric character. My overall goal is to test if the number is both numeric and positive, but given the circumstances above, i'm having trouble achieving a proper test.

Any recommendations on how to get past this?

Thanks

Upvotes: 3

Views: 1323

Answers (1)

Simon Sobisch
Simon Sobisch

Reputation: 7287

I suggest to use FUNCTION TEST-NUMVAL(some-data) if you need a good check of anything that is defined as alphanumeric/alphabetic; if this passes you can then use FUNCTION NUMVAL(some-data) to get the actual value.

For more details you could check on those in the current draft of the COBOL standard.

Upvotes: 6

Related Questions