Hi Kurup,
Your ques needs a little more detail. For example can the "user" enter "000123" or
" 123" or " 123 ", or "0012.3". How is the field defined, e.g. pic xxx, pic 999, etc? Do you want to know significant digits or all digits, for example if "user" entered " 123" there are 6 digits (or positions; one can argue spaces are not digits, but that should be made clear). Well you get the idea.
To take the simplest case (a mistake when dealing w/what a user my enter):
"User" enters 123 into a 6 byte pic 9 fld.
You can code:
perform
varying fpos from +1 by +1
until pic9-fld(fpos:1) not = zero
if pic9-fld = zero
add +1 to f0-cnt
end-if
end-perform
compute true-len = (length of pic9-fld - fpos) + 1
Remember this is the simplest case. How would you do it if the "user" I/P had to be a decimal amt, e.g. 1.23? Could you use pic9? What if 12300 were entered?, etc.
Some fairly comlicated editing routines have been written to allow maximum flexibility in entering numeric data and at the same time providing strict I/P validity, e.g.:
accepting $1.23, +1.23, 1.23-, 1.23CR, " + 1.23 ", etc.
rejecting 1.2A, "1 .23", $$1.23, etc.
Generally, these edit routines use pic x for numeric flds to allow the flexibility.
After using the edit subrutine, the pgmmer can the add his own "reasonability" edits, dictated by the application requirements, e.g.:
0 not valid
123.00 too large an amt
1.23 negative not a valid amt
etc.
Regards, Jack.
Regards, Jack.