2008 Nov 10 7:20 PM
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.
2008 Nov 10 7:44 PM
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.
2008 Nov 10 7:33 PM
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.
2008 Nov 10 7:44 PM
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.
2008 Nov 11 3:08 AM
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
2008 Nov 11 4:10 AM
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
| User | Count |
|---|---|
| 4 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |