I have an alphanumeric variable with a length of 10. It contains a number at the beginning, the rest of the digits are filled with spaces. Then I need to move the string to the
If you have intrinsics, shuffle a FUNCTION TRIM, with LEADING or TRAILING as fits purpose, through a pic 9. TRAILING in this case, or both in the example below.
identification division.
program-id. rjust.
data division.
working-storage section.
01 str pic x(10) value '123 '.
01 some-n pic 9(10).
procedure division.
move function trim(str) to some-n
move some-n to str
display some-n, " : ", str end-display
goback.
0000000123 : 0000000123
As Bill mentioned above with validation, this assumes all spaces is the equivalent of 0. That may or may not be a sane thing to allow. Non digits being an issue as well.