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 

form an sql query using SORT
Goto page Previous  1, 2
 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Utilities
View previous topic :: View next topic  
Author Message
yadav2005
Intermediate


Joined: 10 Jan 2005
Posts: 348
Topics: 144

PostPosted: Mon Nov 12, 2007 4:08 pm    Post subject: Reply with quote

Frank,

Thanks a lot for the needful help. Your code works perfect .Really great.
But i have a small question i just want to add some text at the below of the query something like this:
Code:

SELECT EMPNO,EMPNAME,SALARY       
  FROM EMPLOYEE                   
 WHERE JOINDATE IN (               
    '2007-01-01'                   
   ,'2007-02-01'                   
   ,'2007-03-01'                   
  )                               
   AND DEPT IN (                   
    'ABC'                         
   ,'DEF'                         
   ,'GHI'                         
   ,'XXX'                         
   ,'YYY'                         
  );   
**** THIS IS AN SQL QUERY ****

Please let me know what needs to be done , do i have to change the Trailer1. Thank You.
Back to top
View user's profile Send private message
yadav2005
Intermediate


Joined: 10 Jan 2005
Posts: 348
Topics: 144

PostPosted: Mon Nov 12, 2007 4:28 pm    Post subject: Reply with quote

Frank,

I got the solution. Thanks.
Back to top
View user's profile Send private message
Frank Yaeger
Sort Forum Moderator
Sort Forum Moderator


Joined: 02 Dec 2002
Posts: 1618
Topics: 31
Location: San Jose

PostPosted: Mon Nov 12, 2007 5:09 pm    Post subject: Reply with quote

Just change the TRAILER1 operand to:

Code:

    TRAILER1=('  );',/,                 
      '**** THIS IS AN SQL QUERY ****')   

_________________
Frank Yaeger - DFSORT Development Team (IBM)
Specialties: JOINKEYS, FINDREP, WHEN=GROUP, ICETOOL, Symbols, Migration
DFSORT is on the Web at:
www.ibm.com/storage/dfsort
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Nic Clouston
Advanced


Joined: 01 Feb 2007
Posts: 1075
Topics: 7
Location: At Home

PostPosted: Tue Nov 13, 2007 1:01 pm    Post subject: Reply with quote

Here is a Rexx solution

Code:

/*- Rexx ------------------------------------------------------------*/
/*                                                                   */
/* Rexx exec to:                                                     */
/*   1 - read joindates - 1 record multiple dates                    */
/*   2 - read department codes - 1 record multiple codes             */
/*   3 - generate SQL statement using the above values in the WHERE  */
/*       condition                                                   */
/* (Includes extra comments on one or two things for a newbie to     */
/*  Rexx in batch)                                                   */
/*------------------------------------------------------------ Rexx -*/
cobol_data. = ''
/* Read file of dates and departments. Running in batch so allocation*/
/* is handled via JCL statements (//FILEIN DD DSN=....               */
'EXECIO * DISKR FILEIN(STEM cobol_data. FINIS'
If rc <> 0
Then Do
   /* In batch SAY puts its output to SYSTSPRT */
   Say 'Unexpected rc from EXECIO: Expected: 0 Got: 'rc
   Return 12

End
/*-------------------------------------------------------------------*/
/* Check that we have:                                               */
/*   2 records                                                       */
/*   data on the date record - first record                          */
/*   data on the dept record - second record                         */
/*                                                                   */
/* Note: number of records read has been placed in cobol_data.0      */
/*-------------------------------------------------------------------*/
If cobol_data.0 <> 2
Then Do

   Say 'Expected 2 records to be read. Read 'cobol_data.0
   Return 12

End
If cobol_data.1 = ' '
Then Do

   Say 'No dates on date record'
   Return 12

End
If cobol_data.2 = ' '
Then Do

   Say 'No depts on dept record'
   Return 12

End
/*----------------------------------------------*/
/* OK so far.....                               */
/* Now extract dates to stem variable 'dates.'. */
/*----------------------------------------------*/
dates. = ''         /* We will store the dates in this stem variable */
ix = 0
Do While cobol_data.1 <> ' '

   ix = ix + 1
   /* PARSE will take the first date (delimited by comma) and assign */
   /*       to dates.ix                                              */
   /*       The remaining data will be rewritten to cobol_data.1     */
   /*       and the process repeated until cobol_data.1 is empty     */
   Parse Var cobol_data.1 1 dates.ix ',' cobol_data.1

End
dates.0 = ix   /* Assign number of dates read into dates.0 */
/*----------------------------------------------*/
/* Now extract depts to stem variable 'depts.'. */
/* Same logic as for dates.                     */
/*----------------------------------------------*/
depts. = ''
ix = 0
Do While cobol_data.2 <> ' '

   ix = ix + 1
   Parse Var cobol_data.2 1 depts.ix ',' cobol_data.2

End
depts.0 = ix
/*---------------------------------*/
/* Now construct the SQL statement */
/*---------------------------------*/
sql_stmt.1 = " SELECT EMPNO,EMPNAME,SALARY"
sql_stmt.2 = " FROM   EMPLOYEE "
sql_stmt.3 = " WHERE  JOINDATE IN ("dates.1
ix1 = 3
Do ix = 2 to dates.0  /* Do the remaining dates */

   ix1 = ix1 + 1
   sql_stmt.ix1 = "                    ,"dates.ix

End
sql_stmt.ix1 = sql_stmt.ix1")"
ix1 = ix1 + 1
sql_stmt.ix1 = "   AND  DEPT IN ("depts.1
Do ix = 2 to depts.0 /* Do the remaining depts */

   ix1 = ix1 + 1
   sql_stmt.ix1 = "              ,"depts.ix

End
sql_stmt.ix1 = sql_stmt.ix1");"
sql_stmt.0 = ix1
/*--------------------------------------------------------------*/
/* All done - now display the construction and write to FILEOUT */
/*--------------------------------------------------------------*/
Do i = 1 To sql_stmt.0

   Say sql_stmt.i

End
"EXECIO * DISKW FILEOUT(STEM sql_stmt. FINIS)"
If rc <> 0
Then Do

   Say 'Unexpected rc from EXECIO: Expected: 0 Got: 'rc
   Return 12

End

Return 0 /* All done OK */


The JCL:
Code:

//xxxNCTSO JOB (3E99,B2),'BATCH TSO',
//         CLASS=0,
//         NOTIFY=&SYSUID,
//         MSGCLASS=R
//*-------------------------------------------------------------------
//* Run a Rexx Exec in batch
//*-------------------------------------------------------------------
//RUNREXX EXEC PGM=IKJEFT01'
//FILEIN   DD *
'2007-01-31','2007-02-28','2007-03-31'
'ABCD','XYZ1','34AD','C1B2'
//*FILEOUT DD DSN=SOME.FILE,DISP=...
//SYSTSIN  DD *
 EXEC 'xxx.yyyyyy.EXEC(FORUM)'
/*
//SYSTSPRT DD SYSOUT=*
//SYSPRINT DD SYSOUT=*


And the output
Code:

ACF0C038 ACF2 LOGONID ATTRIBUTES HAV
READY
 EXEC 'xyz.myuid.EXEC(FORUM)'
 SELECT EMPNO,EMPNAME,SALARY
 FROM   EMPLOYEE
 WHERE  JOINDATE IN ('2007-01-31'
                    ,'2007-02-28'
                    ,'2007-03-31')
   AND  DEPT IN ('ABCD'
              ,'XYZ1'
              ,'34AD'
              ,'C1B2');
READY
END
******************************** BOT

_________________
Utility and Program control cards are NOT, repeat NOT, JCL.
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 -> Utilities All times are GMT - 5 Hours
Goto page Previous  1, 2
Page 2 of 2

 
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