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

Leading Zeros

Former Member
0 Likes
3,586

Hi All,

I need to insert leading zeros for a currency and quantity field.

Eg: v_dig =7.00

v_dig = 00007.00

I searched in SDN but I could get only for char. I even converted to char and tried but the value is changing to 0000700. the decimal is not coming.

Please help me with this.

Regards,

Srik

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
2,584

HI,

Try this FM: HRPBSNO_FORMAT_ZERO

With input values:

Left = 4

Right = 2

In_separator = blank

Out_separator = dot( .)

Str value = 70.00

You will get output as 0070.00

Regards,

Bhaskar

13 REPLIES 13
Read only

JozsefSzikszai
Active Contributor
0 Likes
2,582

how did you move the decimal value to char field? you have to do like this:

WRITE decimal TO char_field.

after that you can fill up with leading zeros.

Read only

Former Member
0 Likes
2,582

hi,

it is not posible to add leading zeroes to currency. u have to take the output field also as char.

Regards,

Ajay

Read only

Former Member
0 Likes
2,582

lv_val = v_dig(1).

lv_len = strlen ( lv_val).

while (lv_len LT 4).

concatenate '0' lv_val into v_dig.

lv_len = strlen( lv_val).

endwhile.

Hope this helps.

regards

Edited by: BrightSide on Dec 2, 2008 10:40 AM

Read only

Former Member
0 Likes
2,582

Use FM

BKK_AMOUNT_CONV_TO_EXTERNAL or

CURRENCY_AMOUNT_SAP_TO_IDOC

to properly convert you amount from internal to external format

you may define AMOUNT_EXTERNAL as character field.

This will properly convert your amount.

After that you can concatenate 0000 to your amount.

Regards,

Mohaiyuddin

Read only

Former Member
0 Likes
2,582

hi,

you could try using TRANSLATE statement :



DATA : v_dig LIKE reguh-rwbtr
          , v_dig_with_zero(8) .

v_dig = 7 .

MOVE v_dig TO v_dig_with_zero .

* move value to the right side of the final variable : v_dig_with_zero contains '    7.00'
SHIFT v_dig_with_zero RIGHT DELETING TRAILING space .


* replace space in front of value with zeros :  v_dig_with_zero contains '00007.00'
TRANSLATE v_dig_with_zero USING ' 0' .

peter.

Read only

Former Member
0 Likes
2,582

do you want to show the content with leading zeroes in a script or smartform then use the fill character F

for example &V_DIG(F0)&.

when you want to show the content with leading zeroes in a write statement then use this:

WRITE v_dig TO v_dig_type_char.

OVERLAY v_dig_type_char with '000000000000000000'.

WRITE v_dig_type_char.

Regards,

Guido

Read only

Former Member
0 Likes
2,585

HI,

Try this FM: HRPBSNO_FORMAT_ZERO

With input values:

Left = 4

Right = 2

In_separator = blank

Out_separator = dot( .)

Str value = 70.00

You will get output as 0070.00

Regards,

Bhaskar

Read only

Former Member
0 Likes
2,582

Hi All,

I implemented all the above but still I am getting spaces but not zeros.

DATA: unhrs(8) type c.

DATA: amount(11) type c.

WRITE wa_tm-unhrs TO unhrs.

SHIFT amount RIGHT DELETING TRAILING space .

translate amount using '0'.

wa_items-unit = unhrs.

please help me with this.

Regards,

Srik

Read only

0 Likes
2,582

> translate amount using '0'.

Your partern is not correct. It should be : translate amount using ' 0' (there is a space before the zero).

When using translate, the first char of partern is replaced by the second (use F1 key on word TRANSLATE in your abap editor).

peter.

Read only

Former Member
0 Likes
2,582

Hey,

You cannot get leading 0's in a quantity/currency field.

for displaying purpose, after all calculation are over

you can convert it into a character field

and then apply the MATN conversion exit.

Hope this helps,

Regards,

Raj

Read only

Former Member
0 Likes
2,582

Hi Bhaskar,

How to give the dot(.) its not accepting. Throwing error.

Regards,

Srik

Read only

Former Member
0 Likes
2,582

Hi

As eric said Move the data to character fields then to NUMC field u wil get leading zeros

Read only

Former Member
0 Likes
2,582

Hi,

You can use the below code as well:

DATA: v_menge TYPE bstmg,

v_char(8) TYPE c,

v_char1(8) TYPE c.

v_menge = '7.00'.

v_char = v_menge.

UNPACK v_char TO v_char.

CONCATENATE v_char0(5) '.' v_char5(2) INTO v_char1.

WRITE: v_char1.

Regards,

Nitin.