Application Development 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: 

add 0's

Former Member
0 Kudos

How to fill a char variable with 0's to the right?

For example:

v = 'abc'.

And if the length of data element is 8 i would like :

v = 'abc00000'

Thanks

1 ACCEPTED SOLUTION

valter_oliveira
Active Contributor
0 Kudos

DATA: lenght TYPE i.
DATA: diff TYPE i.

lenght = strlen( v ).
diff = 8 - lenght.

DO diff TIMES.
  CONCATENATE v '0' INTO v.
ENDDO.

Regards,

Valter Oliveira.

8 REPLIES 8

Former Member
0 Kudos

Hi,

Try to use the SHIFT LEFT and add the zeroes.

Check the ABAPDOCU on the same.

Regards

Lekha

0 Kudos

Try this code:

data: V_CHAR(8) type C,

IN_VAR type I.

constants:C_LEN type N value '8',

C_ZERO type N value '0'.

**

V_CHAR = 'abc'.

IN_VAR = strlen( V_CHAR ).

while IN_VAR <> C_LEN.

V_CHAR+IN_VAR(1) = C_ZERO.

IN_VAR = IN_VAR + 1.

endwhile.

Award points if this helps.

Former Member
0 Kudos

use the following statement


concatenate v '00000000' into v.

Cheers

KD

0 Kudos

Hi

The length is not fix.

0 Kudos

For example if the length of data element is 8 then concatenate V with 8 zeros.

if the lengh is not constant then build the zero string and concatenate with V .

Cheers,

KD

Former Member
0 Kudos

Hi,

Try

Translate v using ' 0'.

Darren

Former Member
0 Kudos

data v(8) type c.

v = 'abc'.

Translate v using ' 0'.

write v.

valter_oliveira
Active Contributor
0 Kudos

DATA: lenght TYPE i.
DATA: diff TYPE i.

lenght = strlen( v ).
diff = 8 - lenght.

DO diff TIMES.
  CONCATENATE v '0' INTO v.
ENDDO.

Regards,

Valter Oliveira.