How to replace spaces at the right into zeros at the left in COBOL?

后端 未结 5 744
孤街浪徒
孤街浪徒 2021-01-22 09:39

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

5条回答
  •  我在风中等你
    2021-01-22 10:27

    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.
    

提交回复
热议问题