Validating numeric fields in cobol


Example: "December 25, 2001"Or else there is the Julian date format, which is formatted as CCYYDDD i.e. "1999364" which would be the year 1999 and the 364th day in that year -- which would be Dec. This format is frequently used for elapsed time applications, as the dates can be directly subtracted from each other. You can FUNCTION REVERSE your 30-byte field, so your trailing spaces become leading spaces. If you want to use that number, remember to FUNCTION REVERSE it again. Now calculating the length of string and then will use Reference modification for numeric check like ws-new-var(len-of-str:9) is NUMERIC then do my work, else do nothing.. If you use the length of WS-VAR1, you'll get back 30 every time, you know. You can change the characters you want with INSPECT. perform varying source-index from 1 by 1 until source-index space add 1 to target-index move source-field(source-index:1) to target-field(target-index:1) end-if end-perform.3. How do you plan to calculate the length of the "string" (since COBOL does not have strings)? PERFORM VARYING CNT-SRC FROM 1 by 1 UNTIL CNT-SRC You need to look at byte 1, for 9, byte 2 for 9, byte 3 for 9 up to byte 22 for 9. Whether to start from the back, the front, or somewhere in the middle, is down to you.

Or it could be MONTH (spelled out) and then your date, then your year (either 2 digits or 4 digits). IF YEAR-IN-QUESTION NUMERIC PERFORM CHECK-LEAP-YEAR ELSE DISPLAY "NON NUMERIC YEAR WAS INPUT".

This program not only validated dates but would convert dates from one format to another.

After you decide on the format of the date to be validated, then each program must make sure that each date to be validated is in the proper format.

Each lesson builds on the previous one providing a solid foundation in COBOL programming concepts and techniques.

Coupled with the source code and the compiler available from Fujitsu, this hands-on guide is the easiest, fastest way to begin creating standard COBOL compliant code.

It might be possible to build a program that can be called to test dates or use DB2 to test dates if you can use that. Probably the only reason COBOL doesnt have one built in, is that mission critical data is usually in a database that has that capability.

You must have an account to comment. Please register or login here!