title: How to replace spaces at the right into zeros at the left in COBOL?
body: <p>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 left and put the number of spaces with '0' at the begining. This examples speaks for themselves:</p>
  
  <pre><code>INPUT            OUTPUT
  ==============================
  '123456    ' -&gt;  '0000123456'
  '12345678  ' -&gt;  '0012345678'
  '123456789 ' -&gt;  '0123456789'
  '1234567890' -&gt;  '1234567890'
  </code></pre>
  
  <p>Then I tought in something like this:</p>
  
  <p>Check this COBOL fiddle where you can try: <strong><a href="http://ideone.com/mgbKZ3" rel="nofollow">http://ideone.com/mgbKZ3</a></strong> (just click on <em>edit</em>)</p>
  
  <pre><code>   IDENTIFICATION DIVISION.
     PROGRAM-ID. VARSWAP.
     ENVIRONMENT DIVISION.
     DATA DIVISION.
     WORKING-STORAGE SECTION. 
  
         01 VARIN   PIC X(10).
         01 VARSWAP PIC X(10) JUSTIFIED RIGHT.
  
     PROCEDURE DIVISION.
  
         MOVE '123456    ' TO VARIN
  
         UNSTRING VARIN DELIMITED BY ' ' INTO VARSWAP
  
         INSPECT VARSWAP REPLACING LEADING SPACE BY '0'
  
         MOVE VARSWAP TO VARIN
  
         DISPLAY VARIN
  
         STOP RUN.
  </code></pre>
  
  <p>Returns:</p>
  
  <pre><code>0000123456
  </code></pre>
  
  <p>It seems work ok, but I wonder if you have a better, simpler, or clearer way to do it.</p>