Check if the Field Content is Numeric

In some instances you may have to validate if the field content is numeric or not. This step becomes mandatory when designing a program that upload external data to SAP. For example excel, CSV or text file content upload.
This is simple code that check if a string variable contain only numeric values.
Program checks if the value in variable “lv_string” is numeric.

Use keyword “CO” to check variable only include characters 0123456789 and ‘.’
ABAP Code to check if field content is numeric or not
Key word “CO” (Contains Only) checks if the string variable only contain characters in “lc_num”.


Update to Checking Field Content Numeric Logic:

A smart reader noticed that the above logic using keyword “CO” fails when variable contains value ‘10.10.10’. Thank you leaving a comment Saurav Das. Therefore, I have decided to update the logic to capture the scenario where there are repeating decimal points in the string variable.


We can use the string manipulation ABAP keyword “count” to find the number of times a character of sub string repeated in a string variable.


If the count is greater than one, we can conclude that the variable is not a valid numeric value.


Use this logic conjunction with the “CO” logic I have shared above.


Check if variable has no repeating dot characters
Please leave a comment with your suggestions and concerns.

Get the latest tips and tricks on SAP!


Add a Comment

Your email address will not be published. Required fields are marked *

Get the latest tips and tricks on SAP!