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

add 0's

Former Member
0 Likes
1,156

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
Read only

valter_oliveira
Active Contributor
0 Likes
1,114

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.

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

8 REPLIES 8
Read only

Former Member
0 Likes
1,114

Hi,

Try to use the SHIFT LEFT and add the zeroes.

Check the ABAPDOCU on the same.

Regards

Lekha

Read only

0 Likes
1,114

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.

Read only

Former Member
0 Likes
1,114

use the following statement


concatenate v '00000000' into v.

Cheers

KD

Read only

0 Likes
1,114

Hi

The length is not fix.

Read only

0 Likes
1,114

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

Read only

Former Member
0 Likes
1,114

Hi,

Try

Translate v using ' 0'.

Darren

Read only

Former Member
0 Likes
1,114

data v(8) type c.

v = 'abc'.

Translate v using ' 0'.

write v.

Read only

valter_oliveira
Active Contributor
0 Likes
1,115

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.