title: Adding preceding zeros for a particular field based on value in that field in JCL
body: <p>I have tried adding preceding zeros to a field in JCL
  but all idea which I tried are not matching with my requirements.
  my requirement is to add preceding zeros only if the field is numeric and
  only if field is having preceding spaces.</p>
  
  <p><strong>Input</strong>
  <a href="https://i.stack.imgur.com/ctSXd.jpg" rel="nofollow noreferrer">Sample Input</a>  </p>
  
  <blockquote>
  <pre><code>123457 0 |  
  34567R   |  
  997654D3 |  
      45833|  
  23       |  
     112456|  
    56  64 |  
  </code></pre>
  </blockquote>
  
  <p><strong>Expected Output:</strong>
  <a href="https://i.stack.imgur.com/YTdHX.jpg" rel="nofollow noreferrer">Sample output</a></p>
  
  <blockquote>
  <pre><code>123457 0 |  
  34567R   |  
  997654D3 |  
  000045833|  
  23       |  
  000112456|  
    56  64 |  
  </code></pre>
  </blockquote>
  
  <p>I have already tried a few methods, but didn't meet my requirements.<br>
  I have viewed the query <a href="https://stackoverflow.com/questions/32858763/add-zero-padding-to-string-in-jcl">Add zero padding to string in JCL</a> but it's not applicable in my case.  </p>
  
  <p>Below are what I have tried   </p>
  
  <p><strong>Method 1</strong></p>
  
  <pre><code>//STEP0001 EXEC PGM=SORT                                       
  //SYSOUT   DD SYSOUT=*                                         
  //SYMNAMES DD *                                                
  ALPHA,C'A, ,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z' 
  //SORTIN   DD *                                                
  123457 0                                                       
  34567R                                                         
  997654D3                                                       
      45833                                                      
  23                                                             
  //SORTOUT  DD SYSOUT=*                                         
  //SYSIN    DD *                                                    
    SORT FIELDS=COPY                                                 
    INREC IFTHEN=(WHEN=(01,01,SS,EQ,ALPHA,OR,02,01,SS,EQ,ALPHA,OR,   
                        03,01,SS,EQ,ALPHA,OR,04,01,SS,EQ,ALPHA,OR,   
                        05,01,SS,EQ,ALPHA,OR,06,01,SS,EQ,ALPHA,OR,   
                        07,01,SS,EQ,ALPHA,OR,08,01,SS,EQ,ALPHA,OR,   
                        09,01,SS,EQ,ALPHA,OR,10,01,SS,EQ,ALPHA),     
    BUILD=(1,10)),                                                   
    IFTHEN=(WHEN=NONE,BUILD=(1,10,UFF,M11,LENGTH=10))                
  //           
  </code></pre>
  
  <p><strong>Method 2</strong>  </p>
  
  <pre><code>//STEP0001 EXEC PGM=SORT                                               
  //SYSOUT   DD SYSOUT=*                                                 
  //SORTIN   DD *                                                        
  123457   0                                                             
  34567                                                                  
  997654                                                                 
  4568 F ABC                                                             
  23 1     1                                                             
  //SORTOUT  DD SYSOUT=*                                                 
  //SYSIN    DD *                                                        
    SORT FIELDS=COPY                                                     
    INREC IFOUTLEN=50,IFTHEN=(WHEN=INIT,OVERLAY=(51:1,10,TRAN=ALTSEQ)),  
    IFTHEN=(WHEN=(51,10,FS,EQ,NUM),OVERLAY=(1:1,10,UFF,M11,LENGTH=10))   
    ALTSEQ CODE=(40F0)                                                   
  /*    
  </code></pre>
  
  <p><strong>Method 3</strong>    </p>
  
  <pre><code>//STEP001  EXEC PGM=SORT                      
  //SORTIN DD *                                 
  764536 27                                     
  0097865432                                    
  00065499234                                   
  00012342345                                   
  12301231233                                   
  //SORTOUT DD SYSOUT=*                         
  //SYSIN DD *                                  
    OPTION COPY                                 
    INREC BUILD=(1,11,UFF,M11,LENGTH=11)        
  //
  </code></pre>
  
  <p><strong>Note:</strong><br>
  - It will be better if we can do it in ICETOOL<br>
  - Other sort methords are also fine.</p>