Page 1 of 1

Executing SQL query from JCL to handel SQL 100

PostPosted: Thu Jan 12, 2017 4:44 pm
by Surabhi
Hello,

I am executing a SQL query through JCL.

    //STEP010  EXEC PGM=IKJEFT01,DYNAMNBR=20,COND=(4,LT)
    //STEPLIB   DD  DSN=DB2.DSNLOAD,DISP=SHR            
    //SYSTSPRT DD SYSOUT=*                              
    //SYSTSIN  DD *                                    
     DSN SYSTEM(*)                                  
     RUN  PROGRAM(*) PLAN(*) PARM('SQL') -
          LIB('*')                  
    //SYSPRINT DD SYSOUT=*                              
    //SYSUDUMP DD SYSOUT=*                              
    //SYSREC00 DD DSN=TEST.PGM.FILE1,  
    //            DCB=(RECFM=FB,LRECL=80),              
    //            UNIT=SYSDA,DISP=(NEW,CATLG,DELETE)    
    //SYSPUNCH DD DSN=TEST.RESULTS.FILE,
    //            UNIT=SYSDA,SPACE=(8000,(1500,1500)),  
    //            DISP=(NEW,DELETE)                    
    //SYSIN    DD *                                    
      SELECT DISTINCT                                  
             SUBSTR(EMP,1,10),                        
      FROM  EBET_PND_BILL_NTR                          
      WHERE ENV_IT  = '003'                        
         ;                                              
    /*                                                  
   


CODE' d
Even if row is not found for the condition, i.e. SQL 100 i want the row to get written in SYSREC00 with a note NO DATA.
Is this possible within JCL itself?

Re: Executing SQL query from JCL to handle SQL 100

PostPosted: Thu Jan 12, 2017 7:17 pm
by prino
Four word answer: No!

Re: Executing SQL query from JCL to handel SQL 100

PostPosted: Sat Jan 14, 2017 8:33 pm
by NicC
No! JCL ony tells the computer what programs to run and the resources required. Can SQL do what you want? I am not sure - have you tried the COALESCE (??) keyword?

The alterantive is to check the return code of the step excecuting the SQL code and if not zero run another step that would write the value to your data set.