|
View previous topic :: View next topic
|
| Author |
Message |
vnktrrd
New User
Joined: 12 Jan 2010 Posts: 34 Location: New York
|
|
|
|
Hi,
I need help in achieving my requirement.
Thanks in advance.
I receive parms to JCL and based on that I have to prepare a SQL query which is to be run in the next step.
Input parms :
Input1
Input2
Input3
Select * from table1
Where table_field = Input1
and table_field = Input2
and table_field = Input3 ;
depending on what I receive in the Inputs the SQL query should be generated.
If there is no value in Input2 then the query should be like this
Select * from table1
Where table_field = Input1
and table_field = Input3 ;
Thanks,
Ramana. |
|
| Back to top |
|
 |
Arun Raj
Moderator
Joined: 17 Oct 2006 Posts: 2482 Location: @my desk
|
|
|
|
| Quote: |
Select * from table1
Where table_field = Input1
and table_field = Input2
and table_field = Input3 ; |
Are you sure it is 'and' and not 'or'? |
|
| Back to top |
|
 |
vnktrrd
New User
Joined: 12 Jan 2010 Posts: 34 Location: New York
|
|
|
|
It can be anything. I just gave an example with 'AND'. Does it make any difference ? All I want is to generate a query using the JCL parms.
Thanks,
Ramana. |
|
| Back to top |
|
 |
Nic Clouston
Global Moderator
Joined: 10 May 2007 Posts: 2454 Location: Hampshire, UK
|
|
|
|
| Write your program then! |
|
| Back to top |
|
 |
Arun Raj
Moderator
Joined: 17 Oct 2006 Posts: 2482 Location: @my desk
|
|
|
|
| Quote: |
| It can be anything. I just gave an example with 'AND'. Does it make any difference ? |
Yes it might make a difference in your results. 'AND' does not make much sense in the context you showed. As far as building your sql dynamically, as Nic pointed out, you could choose any programming language of convenience, I'm sure there would be working examples in this forum. Post here if you come across any issues and someone would be around to help you. Good luck. |
|
| Back to top |
|
 |
RahulG31
Active User
Joined: 20 Dec 2014 Posts: 446 Location: USA
|
|
|
|
If you are looking for any kind of SORT solution then you can probably make a use of PARM JPn. You can write something similar to:
| Code: |
//STEPSORT EXEC PGM=SORT,PARM='JP1"IN1",JP2"IN2",JP3" "'
//SYSOUT DD SYSOUT=*
//SYSPRINT DD SYSOUT=*
//SORTIN DD *
/*
//SORTOUT DD SYSOUT=*
//SYSIN DD *
OUTFIL IFTHEN=(WHEN=(1,3,CH,EQ,JP1),
BUILD=(C'SELECT * FROM TABLE',/,C'WHERE TABLE_FIELD=',JP2,/,
C' AND TABLE_FIELD=',JP3)),
IFTHEN=(WHEN=(1,3,CH,EQ,JP2),
BUILD=(C'SELECT * FROM TABLE',/,C'WHERE TABLE_FIELD=',JP1,/,
C' AND TABLE_FIELD=',JP3)),
IFTHEN=(WHEN=(1,3,CH,EQ,JP3),
BUILD=(C'SELECT * FROM TABLE',/,C'WHERE TABLE_FIELD=',JP1,/,
C' AND TABLE_FIELD=',JP2))
OPTION COPY
/* |
SORTIN is having a blank line so that we can compare it with JPn values. I assumed all input fields have 3 byte length.
You can manipulate this logic according to your requirement.
. |
|
| Back to top |
|
 |
Rohit Umarjikar
Global Moderator

Joined: 21 Sep 2010 Posts: 3109 Location: NYC,USA
|
|
|
|
| Instead of convoluted logic simply unload the table to a data set and use DFSORT include to play around The filter based on the input values |
|
| Back to top |
|
 |
Arun Raj
Moderator
Joined: 17 Oct 2006 Posts: 2482 Location: @my desk
|
|
|
|
Here is another way of using the sort product (if you are at z/OS 2.1 or higher). Please note, I have included a dummy value at the end.
| Code: |
// EXPORT SYMLIST=(IN1,IN2,IN3)
// SET IN1='AAA',IN2='BBB',IN3='CCC'
//STEP01 EXEC PGM=SORT
//SORTIN DD *,SYMBOLS=JCLONLY
&IN1
&IN2
&IN3
//SYSIN DD *
INCLUDE COND=(1,3,CH,NE,C' ')
SORT FIELDS=COPY
OUTFIL REMOVECC,HEADER1=('SELECT * FROM TABLE',/,
'WHERE TABLE_FIELD IN ( '),
BUILD=(C'''',1,3,C''',',80:X),
TRAILER1=('''---'')')
//SYSOUT DD SYSOUT=*
//SORTOUT DD SYSOUT=* |
|
|
| Back to top |
|
 |
|
|
 |
All times are GMT + 6 Hours |
|