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

Decimal Validation

Former Member
0 Likes
1,407

Hi All,

During Processing of internal table remove one decimal digit from left hand side

For Example

Input data : itab-amt = 9,059500

Output data : itab-amt = 9,05950

Plz send the Reply

Award points Compulsory for correct solution

Thanks & Regards

SEK

5 REPLIES 5
Read only

Former Member
0 Likes
847

If , stands for Decimal, then do like this:

data: v_temp(20)

write v_amount to v_temp decimals 5.

condense v_temp.

Regards,

Ravi

Read only

Former Member
0 Likes
847
program test.
write: / ' CAST'.  
perform cast  using :  '1.011',  '2.036'.
write: / 'TRUNC'.
 perform trunc using :  '1.011',  '2.036'.

form cast using value type p.  
data:    3decs type p length 9 decimals 3, 
   2decs type p length 9 decimals 2.  
3decs = value. 
 write : 3decs.  3decs = 2decs = 3decs.  
write : 3decs.
endform.
form trunc using value type p. 
 data:    3decs type p length 9 decimals 3. 
 3decs = value. 
 write : 3decs. 
 3decs = ( trunc( 100 * 3decs ) / 100 ).
  write : 3decs.endform.

Data: x type p decimals 3 value '1.234'.
Data: y type p decimals 2.
y = x.
Write:/ x.
Write:/ y.
Read only

Former Member
0 Likes
847

HEllo,

Make use of the FM.

<b>

HR_NZ_ROUNDING_DECIMALS</b>

Vasanth

Read only

Former Member
0 Likes
847

AS FAR AS I HAVE UNDERSTOOD.

DATA : VALUE(7) TYPE C.

VALUE = ITAB-AMT(7).

SINCE YOUR ITAB-AMT IS EIGHT IN LENGTH MOVE THE CONTENT TO A 7 DIGIT DATA OBJECT OVER HERE IT IS VALUE

Read only

Former Member
0 Likes
847

Hi Raja,

If the number of decimal places is variable you could do:

DATA:

zlv_nr_of_decimals TYP I,

zlv_6_dec(10) TYPE p DECIMALS 6,

zlv_5_dec(10) TYPE p DECIMALS 5,

zlv_4_dec(10) TYPE p DECIMALS 4,

..

DESCRIBE FIELD itab-amt DECIMALS zlv_nr_of_decimals.

CASE zlv_nr_of_decimals.

WHEN 6.

zlv_5_dec = itab-amt.

itab-amt = zlv_5_dec.

WHEN 5.

zlv_4_dec = itab-amt.

itab-amt = zlv_4_dec.

.

.

.

.

ENDCASE.

Regards,

John.