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

variable length

Former Member
0 Likes
855

Hi

I have a Quantity field with 3 decimals. Now in the o/p I have to shoe that in special way..i.e.

4.000 = 4

4.120 = 4.12

4.100 = 4.1

So how to do that? Is there any FM 4 dat?

Regards,

Kaushik

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
826

... ROUND r

Effect

Scaled output of a field of type P.

The decimal point is first moved r places to the left (r > 0) or to the right (r < 0); this is the same as dividing with the appropriate exponent 10**r. The value determined in this way is output with the valid number of digits before and after the decimal point. If the decimal point is moved to the left, the number is rounded.

For further information about the interaction between the formatting options CURRENCY and DECIMALS, see the notes below.

Example

Effect of different ROUND specifications:

DATA: X TYPE P DECIMALS 2 VALUE '12493.97'.

WRITE: /X ROUND -2, "output: 1,249,397.00

/X ROUND 0, "output: 12,493.97

/X ROUND 2, "output: 124.94

/X ROUND 5, "output: 0.12

Option

... UNIT u

Effect

Formats a value according to the unit specified in the field u.

The contents of f are treated as a quantity. The unit specified in u determines how many decimal places should be output.

If f has more places after the decimal point than determined in u, the output value will only have the number of decimal places determined by u, unless the operation truncates digits other than zero.

If f has fewer places after the decimal point than determined by u, the option has no effect.

The contents of u are used as a unit in the table T006, but if there is no entry, the formatting option has no effect.

The field f which is to be output must have the type P. This option is used for table fields which have the Dictionary type QUAN, or for fields defined with reference to such fields ( DATA ... LIKE ...).

This formatting option excludes the options DECIMALS and ROUND.

Example

Suppose the unit 'STD' has 3 decimals

DATA HOUR TYPE P DECIMALS 3 VALUE '1.200'.

WRITE (6) HOUR UNIT 'STD'. "output: 1,2

HOUR = '1.230'.

WRITE (6) HOUR UNIT 'STD'. "output: 1,230

6 REPLIES 6
Read only

Former Member
0 Likes
826

Hi,copy these fields to a character field, then use remove zeros

SHIFT w_quantity RIGHT DELETING TRAILING '0'. 

After that u can use simple string operations(w_quatity+1(0)) to get the required output.

Hope it will solve u r problem,

Thanks & Regards,

Rock.

Read only

Former Member
0 Likes
827

... ROUND r

Effect

Scaled output of a field of type P.

The decimal point is first moved r places to the left (r > 0) or to the right (r < 0); this is the same as dividing with the appropriate exponent 10**r. The value determined in this way is output with the valid number of digits before and after the decimal point. If the decimal point is moved to the left, the number is rounded.

For further information about the interaction between the formatting options CURRENCY and DECIMALS, see the notes below.

Example

Effect of different ROUND specifications:

DATA: X TYPE P DECIMALS 2 VALUE '12493.97'.

WRITE: /X ROUND -2, "output: 1,249,397.00

/X ROUND 0, "output: 12,493.97

/X ROUND 2, "output: 124.94

/X ROUND 5, "output: 0.12

Option

... UNIT u

Effect

Formats a value according to the unit specified in the field u.

The contents of f are treated as a quantity. The unit specified in u determines how many decimal places should be output.

If f has more places after the decimal point than determined in u, the output value will only have the number of decimal places determined by u, unless the operation truncates digits other than zero.

If f has fewer places after the decimal point than determined by u, the option has no effect.

The contents of u are used as a unit in the table T006, but if there is no entry, the formatting option has no effect.

The field f which is to be output must have the type P. This option is used for table fields which have the Dictionary type QUAN, or for fields defined with reference to such fields ( DATA ... LIKE ...).

This formatting option excludes the options DECIMALS and ROUND.

Example

Suppose the unit 'STD' has 3 decimals

DATA HOUR TYPE P DECIMALS 3 VALUE '1.200'.

WRITE (6) HOUR UNIT 'STD'. "output: 1,2

HOUR = '1.230'.

WRITE (6) HOUR UNIT 'STD'. "output: 1,230

Read only

raviprakash
Product and Topic Expert
Product and Topic Expert
0 Likes
826

> Hi

> I have a Quantity field with 3 decimals. Now in the o/p I have to shoe that in special way..i.e.

> 4.000 = 4

> 4.120 = 4.12

> 4.100 = 4.1

> So how to do that? Is there any FM 4 dat?

> Regards,

> Kaushik

Hi Kaushik,

Here is the code to do the above:-

NOTE:-

INPUT is the IMPORTING parameter which will be your decimal variable and

OUTPUT is the EXPORTING parameter which will be a string.


DATA: lv_input TYPE string,      
        lv_numerator TYPE string,     
        lv_denumerator TYPE string,  
        lv_sign TYPE c,            
        lv_decimals TYPE i,           
        lv_output_c TYPE c LENGTH 31, 
        lv_output TYPE string.        

  lv_input = input. "Conversion of DEC to string
* Get sign

* Get position of last zero in denumerator
  SPLIT lv_input AT '.' INTO lv_numerator lv_denumerator.
  CONDENSE lv_denumerator. "Remove spaces
  lv_decimals = STRLEN( lv_denumerator ) - 1. "Need to substract 1 for position
  "Check for sign at end of string
  IF lv_decimals >= 0 AND lv_denumerator+lv_decimals(1) EQ '-'. "Sign found ?
    lv_sign = '-'.
    lv_decimals = lv_decimals - 1.
  ENDIF.
  WHILE lv_decimals >= 0 AND lv_denumerator+lv_decimals(1) EQ '0'.
    lv_decimals = lv_decimals - 1.
  ENDWHILE.
  lv_decimals = lv_decimals + 1. "Need to add one for length

* Create formatted output string
  WRITE input TO lv_output_c DECIMALS lv_decimals NO-GROUPING NO-SIGN USING NO EDIT MASK. "Convert to characters
  lv_output = lv_output_c. "Convert to string.
  CONDENSE lv_output.
  "Prepend sign
  IF lv_sign IS NOT INITIAL.
    CONCATENATE lv_sign lv_output INTO lv_output.
  ENDIF.

  output = lv_output.

Many Regards,

Ravi.

Read only

raja_narayanan2
Active Participant
0 Likes
826

Hi....

It very simple.....

Declare that output variable as CHAR.... Your problem will be solved...

Regards

Raja

Read only

0 Likes
826

Hi...

sorry...

Declare it as packeddecimal with decimal values 2 so that your output will come like this....

4.000 = 4

4.1200 = 4.12

regards

Raja...

Read only

Former Member
0 Likes
826

Thnaks All