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

fixed field length by adding zeros

Former Member
0 Likes
557

Hi all,

I am wondering how to fix the field length by putting zeros if field length is not as required.

eg. required field length is 4.

& data in filed is 2 then should be - 2000.

if 12 then should be - 1200.

Thanks.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
516

Hi Rita

Her is the code


DATA: txt(4).

txt = ' 12'.
SHIFT txt LEFT DELETING LEADING space.
TRANSLATE txt USING ' 0'.
WRITE:/ txt.

txt = '  2'.
SHIFT txt LEFT DELETING LEADING space.
TRANSLATE txt USING ' 0'.
WRITE:/ txt.

Regards

Dean Q.

3 REPLIES 3
Read only

Former Member
0 Likes
517

Hi Rita

Her is the code


DATA: txt(4).

txt = ' 12'.
SHIFT txt LEFT DELETING LEADING space.
TRANSLATE txt USING ' 0'.
WRITE:/ txt.

txt = '  2'.
SHIFT txt LEFT DELETING LEADING space.
TRANSLATE txt USING ' 0'.
WRITE:/ txt.

Regards

Dean Q.

Read only

0 Likes
516

Thank you so much. solved it.

Read only

Former Member
0 Likes
516

below is example for you.

data: t1(4) type c value '1'.

data: len type i,

len2 type i,

diff type i.

describe field t1 length len.

len2 = strlen( t1 ).

diff = len - len2.

case diff.

when '1'.

t1 = t1 * 10.

when '2'.

t1 = t1 * 100.

when '3'.

t1 = t1 * 1000

endcase.

Note: This kind of logic is a basic one. you can resolve urself if you think. Asking basic questions is against forum rules.