cancel
Showing results for 
Search instead for 
Did you mean: 

How to check the number of digits entered into a itab-field.

Former Member
0 Kudos

Howdy,

I've got a program where i retrieve some data from the database and then I need to check if field BKPF-XBLNR has exactly 15 digits in it.

I've got no idea on how I would do this...

Can anyone help?

Thanking you kindly!

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

XBLNR is a character field. If you want to make sure all 15 positions have a digit and not some other character then use:

IF BKPF-XBLNR CO '0123456789'.
* OKAY, all 15 positions have digits
ELSE.
* NOT OKAY, at least one of the 15 is not a digit
ENDIF.

If you do not care what the characters are, then Rich has given you the solution but be aware that you could have embedded blanks, for example:

'ABCDEF    GHIJK'

is length 15.

Message was edited by: Charles Folwell

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

Use the following code.



    data: len type i.

    len = strlen( BKPF-XBLNR ).

Regards,

Rich Heilman

Former Member
0 Kudos

Sorry, could you elaborate on that please?

Are you saying that

I should do this:

<b>data: len type i.

len = strlen( BKPF-XBLNR ).

if len NE '15'.

message E129(Z4).

endif.</b>

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

Looks ok to me, but if you want to be thorough, as Charles said, make sure that the field only contains numeric numbers, then get the length, then check it against '15' as you are doing.

Regards,

Rich Heilman