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

Padded by spaces

Former Member
0 Likes
846

Hello Experts ,

I have to pad a character field by spaces.

Eg : var1(5) type c.

Var1 can have value 'ab' or 'abc' etc...

Now if value is 'ab' , i should pad it with 3 spaces as ' ab'

and if value is 'abc' i should pad with 2 spaces as ' abc'.

So depending on value of var1 , it should be padded with spaces .

Conversion Exit is useful only Numeric fields.Please suggest a solution for char field.

Thanks.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
815

this works...


data: testf(5) type c value 'ABC'.

start-of-selection.
  write: / '12345'.
  write: / testf.
* this works
  write testf to testf right-justified.
  write: / testf.

Hello Experts ,

I have to pad a character field by spaces.

Eg : var1(5) type c.

Var1 can have value 'ab' or 'abc' etc...

Now if value is 'ab' , i should pad it with 3 spaces as ' ab'

and if value is 'abc' i should pad with 2 spaces as ' abc'.

So depending on value of var1 , it should be padded with spaces .

Conversion Exit is useful only Numeric fields.Please suggest a solution for char field.

Thanks.

4 REPLIES 4
Read only

former_member156446
Active Contributor
0 Likes
815

Hi hope this helps:

DATA: var1(5) TYPE c VALUE 'AB'.
DATA:lv_len TYPE i, count TYPE i, lv_temp TYPE i.

DESCRIBE FIELD var1 LENGTH lv_len IN CHARACTER MODE.
count = STRLEN( var1 ).
lv_temp = lv_len - count.
DO lv_temp TIMES.
  CONCATENATE space var1 INTO var1.
ENDDO.

Read only

Former Member
0 Likes
816

this works...


data: testf(5) type c value 'ABC'.

start-of-selection.
  write: / '12345'.
  write: / testf.
* this works
  write testf to testf right-justified.
  write: / testf.

Read only

Former Member
0 Likes
815

Hi,

calculate the length of the value and then according to the length to decide how many spaces you should add.

Thanks.

Regards,

Chris Gu

Edited by: Gu Chris on Nov 11, 2008 4:09 AM

Read only

Former Member
0 Likes
815

Hi,

All character type variables/fields are left justified by default, so if you want to add padding to the beginning of a variable, just use the write statement in addition with the right-justified.

example-

data var1(5) type c value 'ab'.

write var.

this would give you and output

ab (left justified without and padding) but instead use the following

write var right-justified.

this would give you an output

ab.

that 3 spaces before writing value of the variable amounting to the total of 5 spaces.

Hope this will help you in solving your query.

Thanka and Regards,

Sachin Dargan