Easytrieve Plus and Db2 - Read a file as input to matching against Db2 table

316 views Asked by At

I am running a batch job that reads in a file in with a list of templates. I am trying to find an example since the one I was provided will not work. I have tried to find any example of reading in a file via EZTPA00. The JCL is correct, but I keep getting an error. Here's the basic code followed by the error I'm getting:

  LIST ON                          
  PARM SSID('DB2G')                
                                   
  FILE INFILE1 VB (133 6233)       
  IP-REC                 01  133 A 
  TEMPLATE               01  015 A 
                                   
  FILE OUFILE1 FB (100 1000)       
  OP-REC                 01  100 A 
  COMMUN_TRANS_ID        01  040 A 
  COMMUN_TEMPLATE_NO     42  015 A 
                                   
  DEFINE H-CNT            W   13 N 

  SQL DECLARE C1 CURSOR FOR                           +
    SELECT TRANSACTION, TEMPLATE        +
      FROM DB2.TEMPLATE_TABLE WHERE                   +
      TEMPLATE = INFILE1:TEMPLATE            
  FETCH FROM INFILE1                                   
  IF EOF INFILE1                                       
      DISPLAY 'TEMPLATE ' TEMPLATE ' NOT RETURNED'     
      STOP                                             
  END-IF                                               
  CLOSE INFILE1                                        
                                                       
* INPUT SETUP                                          
  JOB INPUT(INFILE1)  +                                
    START  010-INIT   +                                
    FINISH 999-END                                     
                                                       
* START THE SQL                                  
  SQL OPEN C1                                    
  DO WHILE SQLCODE NE +100                       
     SQL FETCH C1 +                              
         INTO :WS-TMPLT, :WS-COMMID              
     IF SQLCODE NE 0                             
        DISPLAY 'PF : ERROR : SQLCODE : ' SQLCODE
        STOP                                     
     END-IF                                      

13   SQL DECLARE C1 CURSOR FOR                           +                 
       SELECT COMMUN_TRANS_ID, COMMUN_TEMPLATE_NO        +                 
         FROM VMUSIU.E_COMM_DLVY WHERE                   +                 
         COMMUN_TEMPLATE_NO = INFILE1:TEMPLATE                             
13 *******B204 SQL - SQL ERROR, SQLCODE IS -104                            
13 *******B204 SQL - DSNT408I SQLCODE = -104, ERROR:  ILLEGAL SYMBOL "?". SOME SYMBOLS THAT MIGHT BE LEGAL
13 *******B204 SQL -          ARE: AND * AT OR SELECTIVITY YEAR YEARS MONTH MONTHS DAY DAYS HOUR          
13 *******B204 SQL - DSNT418I SQLSTATE   = 42601 SQLSTATE RETURN CODE      

I have no idea what the "?" is. I tried using a fetch for infile1 but it said it was invalid. Everything I try gives me the same answer. I even tried using ws variables, but it still failed. Does someone have something that allows you to match db2 table info against a file?

1

There are 1 answers

0
Patricia Flickner On

Got it:

  SQL DECLARE C1 CURSOR FOR                           +
    SELECT COMMUN_TRANS_ID, COMMUN_TEMPLATE_NO        +
      FROM DB2.TEMPLATE_TABLE WHERE                   +
      COMMUN_TEMPLATE_NO = :TEMPLATE                  +
      FETCH FIRST 2 ROWS ONLY                          

There are a few things I still need to do, but this got me thru to get the data. The FETCH FIRST 2 ROWS ONLY came after so I could finally pull just 2 per record. Now I need to find out if I can keep the table open during the entire time since opening and closing the table eats up time.