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
The easiest way is to use the WITH CONVERSION clause on the move statement, and if you aren't sure of the input, add the ON EXCEPTION clause.
IDENTIFICATION DIVISION.
PROGRAM-ID. ONCONVERSION.
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 VARIN PIC X(10).
01 VAROUT PIC 9(10).
PROCEDURE DIVISION.
MOVE '123456 ' TO VARIN
MOVE VARIN TO VAROUT WITH CONVERSION
ON EXCEPTION
MOVE ZERO TO VAROUT
END-MOVE
DISPLAY VARIN
STOP RUN.