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

Formatting

Former Member
0 Likes
883

Hi,

I want to write a code in ABAP in such a way that I should get the output in the right side format.

Ex:

1200 - > 1,200

12000 - > 12,000

120000 -> 120,000

1200000 -> 1,200,000

12000000 -> 12,000,000

120000000 - > 120,000,000

.

.

In more generic way if the value is 'abcdefg' it should be a,bcd,efg . So it counts from behind and puts comma after three places and does this moving foward if there are other digits in the number.

Please help.

Thanks.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
854

hI Tushar

data: val(10) type c,val1(10) type c.

data: len type i,cnt type i value 0.

val = '12000000'.

len = strlen (val).

while len ne 0.

if cnt eq 3.

concatenate ',' val+len(3) val1 into val1.

cnt = 0.

endif.

cnt = cnt + 1.

len = len - 1

endwhile.

if cnt ne 0.

concatenate val+0(cnt) val1 into val1.

endif.

write val1.

regards

kishore

there is small change

Message was edited by: Harikishore Sreenivasulu

6 REPLIES 6
Read only

Former Member
0 Likes
854

Hi Tushar,

If your value is Currency then you can use :

Write Field Currency <Currency key Ex: 'USD'>. This will set all the comma formats base on coutry specific.

Lanka

Read only

0 Likes
854

You should just be able to do this by writing from a type P field to a character field.

<b>This way it will not show the decimal places.</b>



report  zrich_0003.


data: value1(15) type c value '12000000000'.
data: value2(15) type c.
data: p(15) type p decimals 0.


p = value1.

write p to value2.

write:/ value1, value2..

Regards,

Rich Heilman

Read only

Former Member
0 Likes
854

Hi Tushar,

If you define the variable or the internal table field refering to any standard currency field,you will get the way you want.

DATA: V_CURR LIKE VBAP-NETPR.

V_CURR = '1200000'.

WRITE:/ V_CURR CURRENCY 'USD'.

Read only

0 Likes
854

Also, for Phani's solution, if you don't want the decimals places. Add the extension.



report  zrich_0003.

DATA: V_CURR LIKE VBAP-NETPR.
V_CURR = '1200000'.

WRITE:/ V_CURR CURRENCY 'USD' <b>decimals 0.</b>

Regards,

Rich Heilman

Read only

Former Member
0 Likes
855

hI Tushar

data: val(10) type c,val1(10) type c.

data: len type i,cnt type i value 0.

val = '12000000'.

len = strlen (val).

while len ne 0.

if cnt eq 3.

concatenate ',' val+len(3) val1 into val1.

cnt = 0.

endif.

cnt = cnt + 1.

len = len - 1

endwhile.

if cnt ne 0.

concatenate val+0(cnt) val1 into val1.

endif.

write val1.

regards

kishore

there is small change

Message was edited by: Harikishore Sreenivasulu

Read only

0 Likes
854

Thanks Hari,

I was looking for this one...