‎2009 Nov 11 6:12 AM
Hi Experts,
i have a question on data type conversion. My requirement is:
i have fields of type packed decimal in my internal table itab. I need to convert the values of packed decimal fields in itab to numeric type.
Example:
Data: begin of itab occurs 0,
ebeln like ekko-ebeln,
ebelp like ekpo-ebelp,
menge(15) type p decimals 2,
netpr(15) type p decimals 2,
end of itab.
if itab-menge has a value of 2.00, i need to convert that value to ' 200'. Right justified.
if itab-netpr has a value of 1,234.56, i need to convert that to ' 123456'.
The above internal table itab is passed to the Function module GUI_DOWNLOAD and the itab data is downloaded to a text file.
Please let me know how to acheive this objective.
‎2009 Nov 11 6:22 AM
HI,
Create one data : var(15) with type C.
1. Use Write To statment to dis.
WRITE variable TO VAR NO-GAP.
CONDENSE VAR.2.
REPLACE ',' WITH SPACE INTO variable.
CONDENSE variable NO-GAPS
‎2009 Nov 11 6:22 AM
HI,
Create one data : var(15) with type C.
1. Use Write To statment to dis.
WRITE variable TO VAR NO-GAP.
CONDENSE VAR.2.
REPLACE ',' WITH SPACE INTO variable.
CONDENSE variable NO-GAPS
‎2009 Nov 11 6:40 AM
Hello,
i tried your suggestion.
i created 2 variables.
data: v_char(14) type c,
v_pack(14) type p decimals 2 value '21223.86'.
The first option is not applicable in ths scenario. i tried the second option too and this is working fine for removing the comma(,) from inbetween the value.
But i need to convert the value 21223.86 to 2122386. without any decimals. Can you help me on this?
‎2009 Nov 11 6:50 AM
Hello,
Check this sample
data: var1 type p decimals 2,
var2 type string.
var1 = '1234.56'.
write: var1.
var2 = var1.
replace '.' with space into var2.
replace ',' with space into var2.
condense var2 no-gaps.
write:/ var2.
Vikranth
‎2009 Nov 11 7:03 AM
Vikranth,
thanks for your reply. i was able to perform the desired function with your help. The process of removing '.' is similar to ','. i should have got the idea, but somehow i didnt.
Thanks anyway.
‎2009 Nov 11 6:59 AM
Hi ,
You can use
SPLIT at '.' into v1 v2
concatenate v1 v2 into vv1.
REPORT ZDN_TEST_001 .
data: lv_var1(15) type p decimals 2 value '123.00'.
data: lv_var2(15) type p decimals 5 value '123.12121'.
data: lv_varc1(15) type c.
data: lv_varc2(15) type c.
data: lv_varc1d(2) type c.
data: lv_varc2d(5) type c.
data: lv_varc11(15) type c.
data: lv_varc21(15) type c.
write:/ lv_var1.
write:/ lv_var2.
*1)write & REPLACE.
write lv_var1 to lv_varc1.
write lv_var2 to lv_varc2.
REPLACE '.' WITH SPACE INTO lv_varc1.
CONDENSE lv_varc1 NO-GAPS.
REPLACE '.' WITH SPACE INTO lv_varc2.
CONDENSE lv_varc2 NO-GAPS.
write:/ lv_varc1.
write:/ lv_varc2.
*2)split & concatinate
write lv_var1 to lv_varc1.
write lv_var2 to lv_varc2.
split lv_varc1 at '.' into lv_varc1 lv_varc1d.
concatenate lv_varc1 lv_varc1d into lv_varc11.
split lv_varc2 at '.' into lv_varc2 lv_varc2d.
concatenate lv_varc2 lv_varc2d into lv_varc21.
write:/ lv_varc11.
write:/ lv_varc21.