Passing a variable into a member with sql

JES, JES2, JCL utilities, IDCAMS, Compile & Run JCLs, PROCs etc...
verabb
Posts: 5
Joined: Thu Dec 04, 2025 4:25 pm
Skillset: COBOL
Referer: From searched

Passing a variable into a member with sql

Postby verabb » Fri Dec 05, 2025 7:47 pm

Hello,
Is there a way to pass a variable in a jcl into a member containing an sql statememt.
//UNLOAD EXEC PGM=DSNTIAUL
//SYSPUNCH DD DUMMY
//SYSREC00. DD DSN=MY.UNLOAD.TMP, DISP=(,CATLG),
// SPACE=(CYL,(10,10),RLSE)
//SYSIN DD DSN=MY.SQL.LIB(MYSQL1),DISP=SHR

MY.SQL.LIB(MYSQL1)
SELECT KDNR FROM TABKND WHERE TIMESTAMP= <--- here I would like to have the content of the variable that I would like to pass from my jcl.

I would really apreciate any help :)

willy jensen
Posts: 481
Joined: Thu Mar 10, 2016 5:03 pm
Skillset: assembler rexx zOS ispf racf smf
Referer: saw it in the experts foprum thought I could help here

Re: Passing a variable into a member with sql

Postby willy jensen » Sun Dec 07, 2025 4:07 pm

Unfortunately I think that system symbols are restricted to sysin type data.
One solution is to add a step to pull the parm and generate the TIMESTAMP statement, then concatenate datasets to get the complete statement.
So, LIB.DATA(SQL) contains 'SELECT KDNR FROM TABKND WHERE - '
Running the job

Code: Select all

 //*                                                                   
 // EXPORT SYMLIST=*  allow use of all symbols hereafter               
 // SET TS='2025-12-07:12:48'                                         
 //*                                                                   
 //MKI      EXEC PGM=IEBGENER                                         
 //SYSIN    DD DUMMY                                                   
 //SYSPRINT DD DUMMY                                                   
 //SYSUT2   DD DISP=(,PASS),DSN=&&TSTMP,LRECL=80,RECFM=FB,SPACE=(TRK,1)
 //SYSUT1   DD *,SYMBOLS=EXECSYS                                       
  TIMESTAMP=&TS                                                       
 //*                                                                   
 //PRT      EXEC PGM=IEBGENER                                         
 //SYSIN    DD DUMMY                                                   
 //SYSPRINT DD SYSOUT=*                                               
 //SYSUT2   DD SYSOUT=*                                               
 //SYSUT1   DD DISP=SHR,DSN=LIB.DATA(SQL)                         
 //         DD DISP=OLD,DSN=&&TSTMP

Generates

Code: Select all

 SELECT KDNR FROM TABKND WHERE -
 TIMESTAMP=2025-12-07:12:48           

I don't know the rules for SQL statement continuation, I leave that up to the OP.

willy jensen
Posts: 481
Joined: Thu Mar 10, 2016 5:03 pm
Skillset: assembler rexx zOS ispf racf smf
Referer: saw it in the experts foprum thought I could help here

Re: Passing a variable into a member with sql

Postby willy jensen » Sun Dec 07, 2025 4:11 pm

Of course it will be much simpler to have the entire statement as sysin and then use the SYMBOLS JCL feature for that. One caveat for uising SYMBOLS, the jobclass must have SYSSYM=ALLOW defined.

willy jensen
Posts: 481
Joined: Thu Mar 10, 2016 5:03 pm
Skillset: assembler rexx zOS ispf racf smf
Referer: saw it in the experts foprum thought I could help here

Re: Passing a variable into a member with sql

Postby willy jensen » Mon Dec 08, 2025 12:22 am

Perhaps slightly simpler:

Code: Select all

// EXPORT SYMLIST=*  allow use of all symbols hereafter 
// SET TS='2025-12-07:12:48'                             
//*                                                     
//GENSQL   EXEC PGM=SORT                                 
//SYSOUT   DD SYSOUT=*                                   
//SORTIN   DD DISP=SHR,DSN=MY.SQL.LIB(MYSQL1)           
//SORTOUT  DD SYSOUT=*,RECFM=FB,LRECL=80                 
//SYSIN    DD *,SYMBOLS=EXECSYS                         
 SORT FIELDS=COPY                                       
 OUTFIL BUILD=(1,40,C'&TS',24X)     24=80-(16+40)       

verabb
Posts: 5
Joined: Thu Dec 04, 2025 4:25 pm
Skillset: COBOL
Referer: From searched

Re: Passing a variable into a member with sql

Postby verabb » Mon Dec 08, 2025 2:51 pm

Thank You very, very much, the second option worked! :)

User avatar
sergeyken
Posts: 473
Joined: Wed Jul 24, 2019 10:12 pm
Skillset: Assembler, JCL, Utilities, PL/I, C/C++, DB2, SQL, REXX, COBOL, etc. etc. etc.
Referer: Internet search

Re: Passing a variable into a member with sql

Postby sergeyken » Tue Jan 06, 2026 2:35 am

A more universal approach.
You may need to mark your SQL variables with any special characters, like <....>, or :.....: or whatever you like.

Code: Select all

 SELECT KDNR
   FROM TABKND
  WHERE TIMESTAMP=<TS>


Code: Select all

// EXPORT SYMLIST=*  allow use of all symbols hereafter 
// SET TS='2025-12-07:12:48'   
// SET PARM1='value1'
// . . . . . .
// SET PARM10='value10'                         
//*                                                     
//GENSQL   EXEC PGM=SORT                                 
//SYSOUT   DD  SYSOUT=*                                   
//SORTIN   DD  DISP=SHR,DSN=MY.SQL.LIB(MYSQL1)           
//SORTOUT  DD  DISP=(NEW,PASS),SPACE=(TRK,(5,5)),
//             RECFM=FB,LRECL=80,
//             DSN=&&NEWSQL                 
//SYSIN    DD  *,SYMBOLS=EXECSYS                         
 SORT FIELDS=COPY                                       
 OUTREC FINDREP=(INOUT=(C'<TS>',C'&TS',
                        C'<PARM1>',C'&PARM1',
                         . . . . . . . .
                        C'<PARM10>',C'&PARM10'))
  END                                               
Javas and Pythons come and go, but JCL and SORT stay forever.

  • Similar Topics
    Replies
    Views
    Last post