Problem solve Get help with specific problems with your technologies, process and projects.

Formatting numbers contained in char variables for use in database searches

Here's how to format numbers for successful database searches.

If you try to retrieve a record from a database file with a SELECT statement, using a number contained in a character type field as a search argument, the search will fail. (For example, you try to retrieve material number '15' in materials master file).

The reason for this is that the search argument is treated as a "char". Therefore, it is not automatically justified as a number, that is, it is not filled with zeroes to the left to its full length as the field in the database. ('15' will not match '00000000000000015' in the database.)

In order to achieve this transformation in string data, you can use the function CONVERSION_EXIT_ALPHA_INPUT. This function, when applied to the 'char' variable containing only digits, will return another string value but masked as a number, adding the necessary number of zeroes to the left to complete the length of the field. If you don't know this function, you would be bothering with some fussy string manipulation.

The inverse function, CONVERSION_EXIT_ALPHA_OUTPUT is also very useful to achieve the opposite result, for example, when you need to print a number contained in a character field, supressing zeroes to the left.

Dig Deeper on SAP Basis

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.