MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

DSNTIAUL - How do you code a varible?

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database
View previous topic :: View next topic  
Author Message
NASCAR9
Intermediate


Joined: 08 Oct 2004
Posts: 274
Topics: 52
Location: California

PostPosted: Mon Jun 19, 2006 6:17 pm    Post subject: DSNTIAUL - How do you code a varible? Reply with quote

I have the following query in a batch job. How can a make the dates in this statement variables?

BETWEEN '4/1/2006' AND '4/30/2006'

Code:


//STEP0160 EXEC PGM=IKJEFT01                                 
//SYSTSPRT DD  SYSOUT=*,DCB=BLKSIZE=121                       
//SYSPRINT DD  SYSOUT=*                                       
//SYSTSIN  DD  *                                             
 DSN SYSTEM(DB2P)                                             
 RUN  PROGRAM(DSNTIAUL) -                                     
      PLAN(DSNTIB81)    -                                     
      PARMS('SQL')      -                                     
      LIB('DB2P.DSN.RUNLIB.LOAD')                             
//SYSPUNCH DD SYSOUT=*                                       
//SYSIN    DD *                                               
    INSERT INTO HOURS.PART_DEPS_WORK                         
          SELECT HOURS.PARTDEPS.SSNO,                         
                 HOURS.FTBELIG2.MEMTYPE,                     
                 HOURS.MEMPLAN.PLANNAME,                     
                 HOURS.MEMPLAN.MEMDESC,                       
             SUM(HOURS.PARTDEPS.CHECK_AMT)                   
          FROM (HOURS.PARTDEPS INNER JOIN HOURS.FTBELIG2     
                               ON HOURS.PARTDEPS.SSNO =       
                                  HOURS.FTBELIG2.SSNO)       
                              INNER JOIN HOURS.MEMPLAN       
                               ON HOURS.FTBELIG2.MEMTYPE =   
                                  HOURS.MEMPLAN.MEMTYPE       
          WHERE (((HOURS.PARTDEPS.MEMSTAT)='ACTIVE')         
            AND ((HOURS.PARTDEPS.RECVD_DATE)                 
             BETWEEN '4/1/2006' AND '4/30/2006')             
            AND ((HOURS.MEMPLAN.EFF_TO_DATE)='12/31/9999'))   
          GROUP BY HOURS.PARTDEPS.SSNO,                       
            HOURS.FTBELIG2.MEMTYPE,                           
            HOURS.MEMPLAN.PLANNAME,                           
            HOURS.MEMPLAN.MEMDESC                             
  ;                                                           

_________________
Thanks,
NASCAR9
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12375
Topics: 75
Location: San Jose

PostPosted: Mon Jun 19, 2006 8:13 pm    Post subject: Reply with quote

NASCAR9,

What exactly do you mean by variable? Do you want to change it everytime you run your job? If so you can split the sql into 3 parts

Everything before the BETWEEN statement as part1 and BETWEEN stmt as part2 and everything after the BETWEEN stmt as part3.

So your sysin would be as follows
Code:

//SYSIN    DD DSN=80 BYTE FILE WITH SQL BEFORE BETWEEN STMT1,
//            DISP=SHR
//         DD DSN=YOUR DYNAMIC BETWEEN STMT,
//            DISP=SHR
//         DD DSN=80 BYTE FILE WITH SQL AFTER BETWEEN STMT2,
//            DISP=SHR


Another option is to generate the DATES in the between statement dynamically. So if you let me the conditions for the dates then may be I can suggest a way to get the dates.

Hope this helps....

Cheers

Kolusu
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
NASCAR9
Intermediate


Joined: 08 Oct 2004
Posts: 274
Topics: 52
Location: California

PostPosted: Tue Jun 20, 2006 9:38 am    Post subject: Reply with quote

Kolusu, Thanks for your reply. My requirement is to pull all deposits in a given calendar month, along with some plan information. The job will run sometime the following month. The Between range needs to include the From and TO date from the previous month.
_________________
Thanks,
NASCAR9
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12375
Topics: 75
Location: San Jose

PostPosted: Tue Jun 20, 2006 9:56 am    Post subject: Reply with quote

Quote:

The Between range needs to include the From and TO date from the previous month.


That is quite simple. The following sql will give you the first and last day of the previous month.

Code:

SELECT DATE(LAST_DAY(CURRENT DATE - 2 MONTHS) + 1 DAY)
      ,DATE(LAST_DAY(CURRENT DATE - 1 MONTHS))         
  FROM SYSIBM.SYSDUMMY1                               
  ;                                                   


So now you change your insert statement to the following
Code:

   INSERT INTO HOURS.PART_DEPS_WORK                         
          SELECT HOURS.PARTDEPS.SSNO,                         
                 HOURS.FTBELIG2.MEMTYPE,                     
                 HOURS.MEMPLAN.PLANNAME,                     
                 HOURS.MEMPLAN.MEMDESC,                       
             SUM(HOURS.PARTDEPS.CHECK_AMT)                   
          FROM (HOURS.PARTDEPS INNER JOIN HOURS.FTBELIG2     
                               ON HOURS.PARTDEPS.SSNO =       
                                  HOURS.FTBELIG2.SSNO)       
                              INNER JOIN HOURS.MEMPLAN       
                               ON HOURS.FTBELIG2.MEMTYPE =   
                                  HOURS.MEMPLAN.MEMTYPE       
          WHERE (((HOURS.PARTDEPS.MEMSTAT)='ACTIVE')         
            AND ((HOURS.PARTDEPS.RECVD_DATE)                 
             BETWEEN DATE(LAST_DAY(CURRENT DATE - 2 MONTHS) + 1 DAY)
                 AND DATE(LAST_DAY(CURRENT DATE - 1 MONTHS))
            AND ((HOURS.MEMPLAN.EFF_TO_DATE)='12/31/9999'))   
          GROUP BY HOURS.PARTDEPS.SSNO,                       
            HOURS.FTBELIG2.MEMTYPE,                           
            HOURS.MEMPLAN.PLANNAME,                           
            HOURS.MEMPLAN.MEMDESC                             
  ;                                   


The last_day scalar function is explained in detail here

http://publibz.boulder.ibm.com/cgi-bin/bookmgr_OS390/BOOKS/DSNSQH11/3.2.40?SHELF=&DT=20010718164132&CASE=

Hope this helps...

Cheers

Kolusu
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
NASCAR9
Intermediate


Joined: 08 Oct 2004
Posts: 274
Topics: 52
Location: California

PostPosted: Tue Jun 20, 2006 10:00 am    Post subject: Reply with quote

Kolusu Thanks! I was just looking at this function and was not sure how to code it in my query. This would have been for the last day of the month. My query for the first day was much more complicated than it need to be. Your solution is awesome!
_________________
Thanks,
NASCAR9
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group