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: 

Filling the needed characters

Former Member
0 Kudos

Hi,

i need to fill a variable with some char like 'A' or 'B' but it is flexible.

i mean, i will do it as required, for example i need to put 10 'A' if the variable needs 10,

15 if it needs 15.

And need is like that, variable lenght is 40 and assume 25 of it is full and 15 is blank.

i want to fill this 15 char with 'A'. How can i put a number of char to the variable?

thanks.

1 ACCEPTED SOLUTION

SuhaSaha
Advisor
Advisor
0 Kudos

The best way is to use TRANSLATE:

DATA: v_ip(40) TYPE c.

v_ip = '12345678901234567890123456789012345'. "35 characters

TRANSLATE v_ip USING ' A'. " ' A' --> Replace the space with A, output will have 5 A's

WRITE / v_ip.

Edited by: Suhas Saha on Aug 9, 2010 3:04 PM

3 REPLIES 3

Former Member
0 Kudos

Hi,

You can achieve ur requirement like this,

Eg.

DATA: v_value(10) TYPE C.

v_value = 'ABCDEF'.

CONCATENATE v_value 'AAAAAAAAAA' INTO v_value.

Check the value of v_value variable. If your variable has 10 char then concatenate 10 'A's, it is 15 char length concatenate 15 'A's

There will be an overflow when it calls in runtime but it gives solution to ur requirement.

Regards,

Selva

Edited by: Selva M on Aug 9, 2010 2:50 PM

kesavadas_thekkillath
Active Contributor
0 Kudos

data:char_var(40) type c.

data:value type char25.

value = '1234567891234567891234567'.

do 40 times.

concatenate char_var 'A' into char_var.

enddo.

len = strlen ( value ).

len = len - 1.

char_var+0(len) = value.

write char_var.

SuhaSaha
Advisor
Advisor
0 Kudos

The best way is to use TRANSLATE:

DATA: v_ip(40) TYPE c.

v_ip = '12345678901234567890123456789012345'. "35 characters

TRANSLATE v_ip USING ' A'. " ' A' --> Replace the space with A, output will have 5 A's

WRITE / v_ip.

Edited by: Suhas Saha on Aug 9, 2010 3:04 PM