Skip to main content

Problem:

How do you right-justify a numeric value?

Resolution:

If a numeric value is accepted in an alphanumeric field, (which is left- justified) and it needs to be right-justified, try the following code:

01 alpha-item pic x(10).

01 move-item redefines alpha-item pic z(10).

01 num-item pic 9(10).

...

    accept alpha-item.

    move move-item to num-item.

    display num-item.

This should cause num-item to be right-justified. A direct move won't work because we pad alphanumeric fields with trailing spaces, and these spaces don't get stripped.

    

Old KB# 6114