Friday, 8 February 2013

Easytrieve to fetch data from table


Easytrieve to fetch data from table :

/*ROUTE XEQ DB2D                                       
//*                                                    
//STEP010  EXEC  UCC11RMS,TYPRUN='F'                   
//*                                                    
//STEP020  EXEC  PGM=EZTPA00                           
//EZTVFM   DD    SPACE=(CYL,(3,3)),UNIT=SYSDA          
//SYSPRINT DD    SYSOUT=*                              
//SYSOUT   DD    SYSOUT=*                              
//INFILE    
DD                                        
111111111111                                           
222222222222                                           
//OUTFILE  DD    DSN=XX7384A.TEST.OUT1,DISP=OLD        
//SYSIN      DD    *                                     
*                                                      
    PARM SSID(DB2D)    -                               
    SQLSYNTAX(FULL)                                    
*                                                      
  FILE INFILE                                          
     CM-N1    01  12  A                               
*                                                      
  FILE OUTFILE                                         
     CM-N2    01  12  A                               
     R-PRG    14  06  A                               
     S-CD       22  01  A                               
*                                                      
     WS-CM-N    W   12   A                              
     WS-RB-CD  W   06   A                              
     WS-ST-CD  W   01   A                              
*                                                      
   SQL DECLARE CUR1 CURSOR FOR       +                 
       SELECT CM_N,                                +                 
                  PG_CD,                                   +                 
                  ST_CD                                     +                 
       FROM GRABC.XXXYY_ZZ_ABCD     +                 
       WHERE CM_N = : WS-CM-N           +                 
       WITH UR                                         
*                       
   JOB INPUT INFILE                                   
*                                                     
    WS-CM-N  =  CM-N1                               
*                                                     
   SQL OPEN CUR1                                      
*                                                     
   DO UNTIL SQLCODE NE 0                              
     SQL FETCH CUR1           +                           
     INTO : WS-CM-N,          +                        
               : WS-RB-CD,         +                           
               : WS-ST-CD                                  
*                                                     
     IF SQLCODE = 0                                   
         CM-N2  =  WS-CM-N                          
         R-PRG   =  WS-RB-CD                          
         S-CD     =  WS-ST-CD                          
         PUT OUTFILE                                  
     ELSE                                             
        IF SQLCODE = 100                              
          DISPLAY ' ROW NOT FOUND '                   
        ELSE                                          
          DISPLAY ' OTHER ERROR ' SQLCODE             
        END-IF                                        
     END-IF                                           
   END-DO                                             
*                                                     
   SQL CLOSE CUR1                                     
*

No comments:

Post a Comment