Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
252 views
in Technique[技术] by (71.8m points)

mainframe - How to run dymanic SQL through IKJEFT01 Utility?

How can we pass parameters in SQL query while executing IKJEFT01? Example:

//UNLOAD    EXEC PGM=IKJEFT01
//SYSTSPRT  DD SYSOUT=*
//SYSTSIN   DD *  DSN SYSTEM(DB2X) RETRY(120)
RUN PROGRAM(DSNTIAUL)
PLAN(DSNTIAUL) -
PARM('SQL')
END
//SYSPRINT  DD SYSOUT=*
//SYSUDUMP  DD SYSOUT=D
//SYSREC00  DD DSN=FCSTN.AK.XXXXXX,
//          DISP=(NEW,CATLG,DELETE),
//SYSPUNCH  DD SYSOUT=*                                           
//SYSIN     DD *
SELECT * FROM ABC.DEF WHERE XYZ='999'   
/*

Instead of giving value in sql query as '999' i want to pass the value through a variable. How this can be done? Plz help...!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Have a separate step, prior to your UNLOAD step, that writes the variable line(s) of SQL to a temporary file. Then concatenate that temporary file with the unchanging lines of SQL.

Freehand...

//SETVAR   EXEC PGM=PRM2FILE,PARM='WHERE XYZ=''&VAL'''
//SYSPRINT DD  SYSOUT=*
//OUTPUT01 DD  DISP=(NEW,PASS,DELETE),
//             LRECL=80,
//             AVGREC=U,
//             RECFM=FB,
//             SPACE=(80,(1,1),RLSE)
//*
//UNLOAD    EXEC PGM=IKJEFT01
//SYSTSPRT  DD SYSOUT=*
//SYSTSIN   DD *  DSN SYSTEM(DB2X) RETRY(120)
RUN PROGRAM(DSNTIAUL)
PLAN(DSNTIAUL) -
PARM('SQL')
END
//SYSPRINT  DD SYSOUT=*
//SYSUDUMP  DD SYSOUT=D
//SYSREC00  DD DSN=FCSTN.AK.XXXXXX,
//          DISP=(NEW,CATLG,DELETE),
//SYSPUNCH  DD SYSOUT=*                                           
//SYSIN     DD *
SELECT * FROM ABC.DEF
//          DD  DISP=(OLD,PASS),DSN=*.SETVAR.OUTPUT01
//*

...where PRM2FILE is a program you write to take whatever is in the parm field and write it to the OUTPUT01 DD.

We do this a lot to accomplish the same goal you are trying to achieve.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...