Convert String to Number and Quantity in ABAP

Different Methods to Convert String to Integer, Quantity, Currency in SAP ABAP

Convert String to Number and String in ABAP : Discover the different methods to convert String variable into Number, Quantity or Amount in SAP ABAP with sample code or SAP standard function template making easing to convert string. 

Convert String to Number in ABAP

In this part, I will try to explain different methods how to sap ABAP convert char to number:

Method 0: Check if string variable is a number

First at all, let’s check if a string variable ( or a char variable ) contains really only number before trying to convert it.
Fortunately, SAP provides in Standard an useful function NUMERIC_CHECK

Here the signature of NUMBERIC_CHECK :

The HTYPE export variable can have:

  • CHAR: if the variable doesn’t contain only numerical characters.
  • NUMC: if the variable contains exclusively Number (integer).

TipsCHECK lv_variable NA SY-ABCD : check if an ABAP variable doesn’t contains letters and none-numerical caracters 😉 


IF you are looking to convert string to integer in ABAP code, you should start by testing this function CONVERT_STRING_TO_INTEGER.
Here the signature of this function:

Unfortunately, it is not available on each system. It is shipped with ECC.


In order to convert in SAP ABAP String variable to Number or Integer, you can also use the standard Function CATS_ITS_MAKE_STRING_NUMERICAL.

Here a sample ABAP Code how to use it ( source ):


An other method to convert string variable to numerical format is the function WOSI_CONVERT_STRING_TO_NUM.

Here the signature of this signature.

Method 4: Convert String to Integer the ABAP OO way

If you prefer using the ABAP OO way, you can use the method read_container_co of the ABAP utility class (CL_ABAP_CONTAINER_UTILITIES).
Personally, I have never used before this method ( but I used a lot the ABAP utilities classes to read the meta data of ABAP variables and do some generic programming in ABAP ).

Here a sample ABAP code using this method (>source)

Method 5: Do it directly in ABAP

Instead of using function modules or method’s classes, you can do convert string / char to Integer or numerical using sample ABAP Statement.
The MOVE Statement and WRITE Statement can do the job for you or even the affectation statement ( = ) will do the casting  .

A very example ABAP Code snippet can be:

You may check also

SAP ABAP Convert string to decimal in ABAP

Method 1: With ABAP coding (the “+” statement)

The easiest way to convert a char variable to decimal is to use the + statement in order to sum a decimal variable and a string.
The ABAP engine will cast the string variable into a decimal and the result will be a decimal.

Here a sample ABAP program illustrating this method:


Once again, SAP provides this function WSAF_CONV_STRING_TO_DECIMAL to convert a string to decimal.
The signature of this function module is:


MOVE_CHAR_TO_NUM can do the job and make the conversion from Char to Decimal.

Look at the following sample (source)

Convert String to Quantity in ABAP

Let’s jump to the Quantity part. I want to make a confidence: the MENGE data makes my life much harder because of all the dumb of illegal data type occurred to Quantity data type. So let’s remove this pain and list some of method how to convert String to Quantity or Amount variable.
PS: I will be called it try and not method because the functions are not available on every version of SAP.


The first method can be the function module CHECK_AND_CONVERT_NUMERICS to Checks whether a value is numeric and converts to a packed number


Here we are talking about ABAP OO again. Actually it is the standard nowadays.
The Class CONVERT_STRING_TO_QUANTITY have an interesting method to convert String to Quantity (source)

Try n°3: Convert String to Quantity with RS_CONV_EX_2_IN

Here a sample ABAP code to figure out the use of the function RS_CONV_EX_2_IN (source):

Try n°4: ABAP Write Statement (Specific Output)

Check more about the Special Output Formats  on and make a focus on the Unit-specific Output Formats’s section.

The statement to be use is: WRITE <f> UNIT <u>.

Just try this abap snippet code


This function /CWM/CONVERT_CHAR_TO_PACK will convert a char to pack ABAP type.

ABAP Convert String to Amount (Currency)



You may also like :

Leave a Reply

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