03-15-2007 8:18 AM
Hello!
How can I get the following outputs
"output var1 = 56.7
"output var2 = 789
instead of
"output var1 = 56.700
"output var2 = 789.000
"zs_vmeng = has the type QUAN length is 15 and decimal
" places are 3.
data var1 type zs_vmeng.
data var2 type zs_vmeng.
var1 = '56.7'.
var2 = 789.
write:/ var1.
write:/ var2.
"output var1 = 56.700
"output var2 = 789.000
Regards
Ilhan Ertas
03-15-2007 8:20 AM
Hello,
U could make use of the
data: wa_input type i,
wa_output type i.
wa_input = '1.000'.
CALL FUNCTION 'ROUND'
EXPORTING
INPUT = wa_input
IMPORTING
OUTPUT = wa_output
EXCEPTIONS
INPUT_INVALID = 1
OVERFLOW = 2
TYPE_INVALID = 3
OTHERS = 4.
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
write:/ wa_output.
Regards,
Vasanth
03-15-2007 8:20 AM
Hello,
U could make use of the
data: wa_input type i,
wa_output type i.
wa_input = '1.000'.
CALL FUNCTION 'ROUND'
EXPORTING
INPUT = wa_input
IMPORTING
OUTPUT = wa_output
EXCEPTIONS
INPUT_INVALID = 1
OVERFLOW = 2
TYPE_INVALID = 3
OTHERS = 4.
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
write:/ wa_output.
Regards,
Vasanth
03-15-2007 8:21 AM
03-15-2007 8:22 AM
03-15-2007 8:28 AM
hi ,
try this.
DATA:
L_MENGE_P5(16) TYPE P DECIMALS 5,
L_MENGE_P3(16) TYPE P DECIMALS 3,
L_ANDEC like T006-ANDEC value 2.
L_MENGE_P5 = '56.000'.
CALL FUNCTION 'ROUND'
EXPORTING
DECIMALS = L_ANDEC
input = L_MENGE_P5 "over here u need to pass other than char
SIGN = '+'
IMPORTING
OUTPUT = L_MENGE_P3
EXCEPTIONS
INPUT_INVALID = 1
OVERFLOW = 2
TYPE_INVALID = 3
OTHERS = 4
.
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
WRITE:/ L_MENGE_P3.
Regards
Anver
03-15-2007 8:32 AM
Hello!
but the problem has not been solved yet.
I can not take an integer field or any other field in order to show
that code example above is working. It must cover every scenario.
The problem is solved when I get by the output of
var3 -> 56.7
instead of -> 56.700
data var1 type zs_vmeng.
data var2 type zs_vmeng.
data var3 type p decimals 3.
var1 = '56.7'.
var2 = 789.
var3 = var1.
write:/ var1.
write:/ var2.
write:/ var3.
03-15-2007 8:33 AM
Hi,
you can use round key word as follows in your report to get the required output.
DATA pack TYPE p VALUE '123.456'
DECIMALS 3.
WRITE pack DECIMALS 2.
WRITE: / pack ROUND -2, " 12,345.600
/ pack ROUND -1, " 1234.560
/ pack ROUND 1, " 12.346
/ pack ROUND 2. " 1.235
03-15-2007 8:34 AM
try this
data : menge like mseg-menge value '745',
menge1 like mseg-menge value 745.
data : cmenge(15),
dec(3),
cmenge1(12),
dec1(3).
cmenge = menge.
cmenge1 = menge1.
if cmenge cp '*.000'.
split cmenge at '.' into cmenge dec.
else.
split cmenge at '.' into cmenge1 dec.
* shift cmenge left deleting
if dec cp '*00'.
dec = dec(1).
elseif dec cp '*0'.
dec = dec(2).
endif.
concatenate cmenge1 dec into cmenge separated by '.'.
endif.
*split cmenge1 at '0' into cmenge1.
write : cmenge.
regards
shiba dutta
03-15-2007 8:46 AM
ponada your example is not true
The correct result is 123.456 instead of 12,345.600
WRITE: / pack ROUND -2. " 12,345.600 is not 12,345.600
it is 123.456
Reagrds
Ilhan
03-15-2007 8:58 AM
hi ,
I am getting it as 12,345.600.Please check your answer .
regards,
veeresh
03-15-2007 9:35 AM
Hello! These results didnt still solve the problem.
@SHIBA DUTTA the uotput field will stay in a excel column later
therefore I can not handle with char
@veereshbabu ponnada its correct it is has been rounded but only in the
write instruction but the variable pack.
Regards
Ilhan
03-15-2007 9:36 AM
eXECUTE THE CODE
REPORT zex13 .
data: var1 type ekpo-menge,
var2(13) type c,
VAR3(4) TYPE C.
var1 = '56.7'.
var2 = trunc( var1 ).
CONDENSE VAR2.
VAR3 = FRAC( VAR1 ).
CONCATENATE VAR2 VAR3+1(3) INTO VAR2.
WRITE 😕 VAR1.
WRITE:/ VAR2.
03-15-2007 9:47 AM
hello sniper !
Result of VAR2 is OK but it has the type char.
I need a way to solve the problem exactly as you have solved
but not as char it has to have the same type
like VAR1 and the rersult like VAR2
VAR1 56.700
VAR2 56.7
03-15-2007 10:18 AM
No you cannot operate on the packed data type .Thats the mistake you are making .
In my opinion we cannot control the zero decimals in packed datatype to eliminate from display.
All you have to do is convert this into the character datatype and proceed .
Thats the solution left .
See the problem is you might be using this query in the display options and best way is to operate it effectively converting to another form of data type .
Already i have given the option of this in one of ur previous post .
madhumitas option works when u want to round that value .
DATA: var1 TYPE p DECIMALS 1.
but if u have 56.780
you are looking for 56.78 and not 56.7 so i dont suppose u will take this option .
Regards,
Vijay
03-15-2007 10:23 AM
just add the code below of my previous coding
data : length type i.
length = strlen( dec ).
if length = 1.
data : value1 type p decimals 1.
value1 = cmenge.
elseif length = 2.
data : value2 type p decimals 2.
value2 = cmenge.
elseif length = 3.
data : value3 type p decimals 3.
value3 = cmenge.
endif.
if not value1 is initial.
" pass value1
elseif not value2 is initial.
" pass value2
elseif not value3 is initial.
endif.
regards
shiba dutta
03-15-2007 11:40 AM
Ertas just check this code and see if this can be applied .
REPORT zex13 .
data: var1 type ekpo-menge,
var2(3) type c,
VAR3(5) TYPE C.
var1 = '56.7'.
VAR3 = FRAC( VAR1 ).
var2 = var3 * 1000.
condense var2. "use this
if var2+0(1) eq '0'.
write:/ var1 decimals 0.
elseif var2+1(1) eq '0'.
write:/ var1 decimals 1.
elseif var2+2(1) eq '0'.
write:/ var1 decimals 2.
ELSE.
WRITE:/ var1.
endif.
Regards,
Vijay
03-15-2007 1:28 PM