‎2007 Aug 03 2:00 PM
If I have a character field that contains only numbers how do I convert this so it moves into a numeric field. I thought it would accept it automatically if it had only numbers but we get a mismatch.
Can I just create another datatype like this
a type char.
b type numeric.
b= a
‎2007 Aug 03 2:02 PM
If it does not work try the instruction MOVE :
MOVE a TO b.
Mathieu
‎2007 Aug 03 2:02 PM
If it does not work try the instruction MOVE :
MOVE a TO b.
Mathieu
‎2007 Aug 03 2:03 PM
Hi,
try this
data: a(10) type c,
b(10) type n.
a = '123'.
b = a.
write:/ b.
b = 0000000123.
reward points if helpful,
thanks & regards,
venkatesh
‎2007 Aug 03 2:06 PM
what if I wnat it to have 3 decimals. how would that work? It is 17 places
‎2007 Aug 03 2:56 PM
hi,
while converting one data type into another data type you must maintain the same length.....
data: par1(10) type c value '1234',
par2 type n.
MOVE para1 TO para2.if the source field para1 contains any decimal values in that case you declare target variable of type Integer or Packed type.
The source field must contain the representation of a decimal number, that is, a sequence of digits with an optional sign and no more than one decimal point. The source field can contain blanks. If the target field is too short, an overflow may occur. This may cause the system to terminate the program.
DATA: par1(10) type c value '1234',
par2 type i. "
MOVE para1 TO para2.<b>or</b>
DATA: par1(10) TYPE C,
par2 TYPE P DECIMALS 2. " specifies the decemal positions
MOVE par1 TO par2.
regards,
Ashok Reddy
‎2007 Aug 03 3:02 PM
u r going right..
just make sure.. to have same size for both variable..
DATA: v_char(10) type c,
v_numc(10) type c.
v_char = '1234'.
v_numc = v_char.
write:/ v_numc.
Result will be :
0000001234
Reward useful answers
Regards
Pradeep
‎2007 Aug 03 3:06 PM
Hi,
Use the standard function module MOVE_CHAR_TO_NUM
Regards
Sudheer
‎2007 Aug 03 3:28 PM
‎2007 Aug 03 3:34 PM
Hi,
Please try FM HRCM_STRING_TO_AMOUNT_CONVERT.
Regards,
Ferry Lianto
‎2007 Aug 03 3:36 PM
try this program.
(invert . and , if you are using period as decimal point)
DATA: zchar(15) VALUE '123.456.789,12'.
DATA: znum(8) TYPE p DECIMALS 3.
CALL FUNCTION 'MOVE_CHAR_TO_NUM'
EXPORTING
chr = zchar
IMPORTING
num = znum
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.
WRITE: / 'error', sy-subrc.
ENDIF.
WRITE: / 'znum =', znum.