on 12-10-2007 10:27 AM
hi,
i want to convert a character to number in abap which function can i use? and how to use this function?
Sample code below:
DATA: lv_chr(4) type c,
lv_num type p.
CALL FUNCTION 'MOVE_CHAR_TO_NUM'
EXPORTING
CHR = lv_chr
IMPORTING
NUM = lv_num
EXCEPTIONS
CONVT_NO_NUMBER = 1
CONVT_OVERFLOW = 2
OTHERS = 3.
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
* https://help.sap.com/doc/abapdocu_752_index_htm/7.52/en-us/abenconversion_type_p.htm
data: c_field type c LENGTH 40 value '8.1499999999999995E-01'.
data: p_field type p DECIMALS 5.
p_field = CONV f( c ).
write: / c_field.
write: / p_field.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
CALL FUNCTION 'MOVE_CHAR_TO_NUM'
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
try this...
data : n type I.
data : C(20).
C = '356'.
move C to n.
n = n + 1.
write n.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Use Fms
MOVE_CHAR_TO_NUM
C14W_CHAR_NUMBER_CONVERSION
CHAR_NUMC_CONVERSION
Regards,
PRashant
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Use the following Code :
DATA NO1(10) TYPE C VALUE '1234567890'.
DATA NO2 TYPE I.
NO2 = NO1.
WRITE NO2.
the foll code will convert the string to interger.
DATA NO1 TYPE STRING.
DATA NO2 TYPE I.
NO1 = '1234567890'.
NO2 = NO1.
WRITE NO2.
Also you can use the FM <b>CONVERT_STRING_TO_INTEGER,</b>.
Hope this would be helpful.
Regards,
Lalit
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi
I am working in one PO enhancement.
Here in field i.e. charactertype fileld and storing as v_charvalue = '1,950 US GAL' ( v_Charvalue is type C).
Now I want to fetch only numeric value i.e 1950 into v_num ( this is type N ).
From the v_charvalu how will fetch only 1950 ....here it should exclude comma (,) and US GAL.
finally I need v_num = 1950
Pls guide me how to fetch only the numeric value.
Dear all, thank you very much for your participation and help, which led me to your solutions.
Kind Regards
Torbjörn Saretz
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I think you didn't required any FM to do it.
Just assign c type variable to variable type P. It will work fine.
Like:
DATA : lv_ch(4) type c,
lv_num type p length 4.
lv_num = lv_ch.
write:/ lv_num.
It's just simply work in case of your problem.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
108 | |
12 | |
11 | |
6 | |
5 | |
4 | |
3 | |
3 | |
3 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.