Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Zeroes after Decimal

Former Member
0 Likes
1,127

Hi,

I am having a value as '6009.12300 ML' belongs to type C.

Now i don't want the zeroes after decimal such as 6009.123 ML .

how cud i do this?

i tried search ,split,shift,trailing zeroes but could nt get it?

Thanks,

Ponraj.s.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,105

Hello,


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

11 REPLIES 11
Read only

Former Member
0 Likes
1,106

Hello,


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

Read only

0 Likes
1,105

HI vasanth.. In your program You have taken <b>wa_input as type i</b>.

and u are giving value '1.000'.

the value will be converted there it self as 1 only ,integer doesn't tale decimals ,before going to call the function module it will be converted as 1..

I think you should change the data type of wa_input

Regards Rk

Read only

anversha_s
Active Contributor
0 Likes
1,105

hi,

just execute this. u will get the idea.

data: a(16) type p decimals 4 .
 
data: b(16) type p decimals 2 .
 
data: c(30) .
 
 
a = '56.4400'.
write:/ a .
 
move: a to b .
 
write:/ b .
 
write a to c decimals 2 .
 
write:/ c .
 
the results will be
 
a = 56.4400
b = 56.44
c = 56.44

Regards

Anver

Read only

0 Likes
1,105

Hi Vasanth,

I've tried the function module directly in se37, am not getting output. only exception ,what we have to pass in the field decimal?

Hi Aversha,

My value contains like this '5134.4500 ML' also 3215.642000 GM' .no.of zeroes is not constant so i need like this

'5143.45 ML' and '3215.624 GM'.I hope ur logic wont work with this.

any other idea?

Thanks,

Ponraj.s.

Read only

Former Member
0 Likes
1,105

data : text1(6),

text2(6),

text(13) type c value '325.2300'.

split text at '.' into text1 text2.

shift text2 right deleting trailing '0'.

shift text2 left deleting leading space.<may be spaces>

clear text.

concatanate text1 text2 into text separated by '.'.

regards

shiba dutta

Read only

Former Member
0 Likes
1,105

Execute teh code

data : val(20) type c value '6009.12300 ML',
       v1(15) type c,
       v2(6) type c.


data : in(10) type c,
       dec(6) type c,   "increase this for ur need 
       final(20) type c.
*write:/ val .

split val at ' ' into v1 v2.

*write:/ v1 .
*write:/ v2.
*
in = trunc( v1 ).

*write:/ in.
dec = FRAC( V1 ).  "this will eliminate zeros if any

*write:/ dec.


concatenate in dec+1(5) into v1.
concatenate v1 v2 into final separated by space.

write:/ final.

"ur final o/p

see if this is working for you .

regards,

vijay

Read only

0 Likes
1,105

Raj,

Is Ur query resolved ?

Regards,

Vijay

Read only

0 Likes
1,105

yes, my query is resolved...

sorry for poiting late.please regret...

Read only

Former Member
0 Likes
1,105

Hi Ponraj Sundarraj,

You can go through the following code.

DATA: lv_string(20) VALUE '6009.12300 ML'.

DATA: lv_length TYPE i.

DATA: lv_len TYPE i.

DATA: lv_char.

lv_length = strlen( lv_string ).

lv_length = lv_length - 4.

WHILE lv_length > 0.

lv_char = lv_string+lv_length(1).

IF lv_char EQ '0'.

lv_len = lv_length + 1.

lv_stringlv_length = lv_stringlv_len.

ELSE.

EXIT.

ENDIF.

lv_length = lv_length - 1.

ENDWHILE.

WRITE: lv_string.

Regards,

Balakrishna.N

Read only

Former Member
0 Likes
1,105

Hi,

I tested the following code segment, it works well to suit your requirement.

Just look at the code.

DATA C(20) VALUE '6009.12300 ML'.

DATA: LEN TYPE I,

FLAG TYPE I.

LEN = STRLEN( C ).

DO LEN TIMES.

LEN = LEN - 1 .

IF ( C+LEN(1) EQ '0' ) .

C+LEN(1) = ' ' .

FLAG = 1 .

ELSE.

IF FLAG = 1 .

EXIT .

ENDIF .

ENDIF .

ENDDO.

CONDENSE C NO-GAPS.

WRITE C.

Reward if helpful.

Regards,

Sandhya

Read only

Former Member
0 Likes
1,105

Answered