‎2010 Jan 28 12:05 PM
Hi all,
i have field of length 9 as declared below.
ID(9) TYPE N,
this i need to check if it consists more than 8 digits it has to throw an error. this field should contain only 8 digits it should not contain 9 digits,
this is one condition for validation and we are not suppose to change the declaration as ID(8) TYPE N.
please help with code sample.
regards,
reddy
‎2010 Jan 28 12:16 PM
Hi,
You can pass the value into another variable of type string and then find length. and accordingly throw error if it is more than 8.
use strlen()
Thanks
Ankit
‎2010 Jan 28 12:33 PM
Hi Reddy,
as far as I know, if variable is declared as ID(9) TYPE N, it always contains 9 digits.
E.g. after
ID = 123 is value of ID 000000123, because value is always shifted to right and other places are filled with zeroes. In such case, probably following test is sufficient for You:
IF ID(1) EQ '0'.
* First digit is zero, it means that whole number is shorter than 9 digits
ELSE.
* First digit is not zero, it means the number's length is 9 digits
ENDIF.Regards,
Adrian
‎2010 Jan 28 12:35 PM
data:ID(9) TYPE n,
l type i.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'
EXPORTING
input = id
IMPORTING
OUTPUT = id.
l = strlen( id ).
if l <= 8.
-
-
-
else.
-
-
-
endif.
‎2010 Jan 28 12:39 PM
This is a numeric field, so the solution is simple.
DATA id(9) TYPE n.
id = 123456789.
IF id > 99999999.
WRITE 'incorrect'.
ENDIF.
‎2010 Jan 28 12:52 PM
data:len(9) type c.
len = d.
length = strlen( len ).
if length > 8.
error.
endif.
‎2010 Mar 02 2:18 PM