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

formating issue

Former Member
0 Likes
522

Hi,

I have an issue in which there is a decimal like suppose 17.34

I get this from a file .. when i have to get it into an internal table it should look like

000000017340000.

Which means it should be divided into 9 and 6

Currently am taking

pamt1(9) TYPE p DECIMALS 6 ,

but this will not fill it up with zeros.

Can some one suggest something

Thanks in advance,

Prince

1 ACCEPTED SOLUTION
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
502

If you need to fill with zeros, then you can not use a type P field. You must use a character field. So you can do something like this.



data: c9(9) type c,
      c6(6) type c,
      c15(15) type c.

data: input type string.

input = '17.34'.

split input at '.' into c9 c6.

shift c9 right deleting trailing space.
translate c9 using ' 0'.

shift c6 left deleting leading space.
translate c6 using ' 0'.

concatenate c9 c6 into c15.

write:/ c15.

Welcome to SDN!.

Regards,

Rich Heilman

4 REPLIES 4
Read only

Former Member
0 Likes
502

Hi Price,

Welcome to SDN................

Move your character values into numeric values. As numeric values will have 0s by default but for characters this will be spaces.

Try as folllows.

DATA p_pamt1(15).

DATA pn_numeric(9) TYPE n.

DATA pn_decimal(6) TYPE n.

DATA pc_numeric(9) TYPE c.

DATA pc_decimal(6) TYPE c.

START-OF-SELECTION.

p_pamt1 = '17.34'.

SPLIT p_pamt1 AT '.' INTO pc_numeric pc_decimal.

pn_numeric = pc_numeric.

pn_decimal = pc_decimal.

CONCATENATE pn_numeric pn_decimal INTO p_pamt1.

Thanks,

Vinay

Read only

Former Member
0 Likes
502

HI,

follow below logic

data v_data(15) type n.

v_data = 17.34 * 100*10000.

Regards

amole

Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
503

If you need to fill with zeros, then you can not use a type P field. You must use a character field. So you can do something like this.



data: c9(9) type c,
      c6(6) type c,
      c15(15) type c.

data: input type string.

input = '17.34'.

split input at '.' into c9 c6.

shift c9 right deleting trailing space.
translate c9 using ' 0'.

shift c6 left deleting leading space.
translate c6 using ' 0'.

concatenate c9 c6 into c15.

write:/ c15.

Welcome to SDN!.

Regards,

Rich Heilman

Read only

0 Likes
502

Thanks Rich... Helped solve it.

Points rewarded.