185 pts.
 Calling query/400 through CL
Hi,

Is it possible to call query/400 through a CL program?

Please suggest some idea..

Thanks,

Jayashree V.

 

 

 



Software/Hardware used:
AS/400
ASKED: January 11, 2012  4:45 AM
UPDATED: March 17, 2012  5:47 AM

Answer Wiki:
Hi, We can use RunQry command. But i want to call a query file from a Control Language Program. Jayashree V. Doesn't the runqry command have the query file and library as the first parameter? Alternatively if you wan to query a file without creating a query then you can use runqry *n flielib/file rcdslt(*yes) Alternativelty if yuo want to satrt getting really sophisticated then have a look at Query Manager as that will allow you to dynamically build a query programmatically.
Last Wiki Answer Submitted:  January 11, 2012  2:46 pm  by  VJayashree   185 pts.
All Answer Wiki Contributors:  VJayashree   185 pts.
To see all answers submitted to the Answer Wiki: View Answer History.


Discuss This Question:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _


 

That would be the RUNQUERY command in CL

 44,070 pts.

 

I am having a hard time understanding what you are asking.
In a CL, you run a query that has allready been created by using RUNQRY (yourquery)
or dynamically to just do a singel file by RUNQRY *N (yourfile)

If this does not help you, please give us more information.

 32,785 pts.

 

RUNQRY is the command to use. Try RUNQRY + F4-key to study parameters. Especially note your options to ‘overwrite’ definitions inside your query, by adding parameters to command.

DanF

 2,540 pts.

 

Hi All,

Thanks for your update.

My requirement is I want to call the created query/400 program through a control language program so that the query ll run and the output file will be stored in a location mentioned in the control language program

Jayashree V

 185 pts.

 

Sounds like you want to build something on-the-fle.
I’d suggest you use SQL.
You can build a source member and then do a RUNSQLSTM to execute it.

 32,785 pts.

 

Hi
Depending on your requirements you can run a query using vairaibles or without.. you can also run this via batch mode. The options are plenty…

 365 pts.

 

So .. you want to run myqry in mylib and put the results in the cl variables
&MYLIB and &MYOUTF .. that would be something like this ..

RUNQRY QRY(MYLIB/MYQRY) OUTTYPE(*OUTFILE) OUTFILE(&MYLIB/&MYOUTF)

Phil

 44,070 pts.

 


and the output file will be stored in a location mentioned in the control language program

I am guessing you are talking about a spool file. If so, you can try something like this:

/*********************************************************************/ 
/*  override the outq                                                */ 
/*********************************************************************/ 
             OVRPRTF    FILE(QPQUPRFIL) OUTQ(My_Outq)       
                                                         
/*********************************************************************/ 
/*  run the qry                                                                                          */ 
/*********************************************************************/ 
                                                                        
             RUNQRY     QRY(My_Qry_Lib/My_Qry)

 5,830 pts.

 

This sketch program may help:

PGM
DCL        VAR(&QRYLIB)    TYPE(*CHAR) LEN(10) VALUE('myqrylib') 
DCL        VAR(&QRY400OBJ) TYPE(*CHAR) LEN(10) VALUE('myqryobj') 

DCL        VAR(&RESULTFILE) TYPE(*CHAR) LEN(10) VALUE('myfile') 
DCL        VAR(&MYLIB)      TYPE(*CHAR) LEN(10) VALUE('mylib')

RUNQRY     QRY(&myqrylib/&myqryobj) OUTTYPE(*OUTFILE)    /* note 1 */

RNMOBJ     OBJ(QTEMP/QPQUPRFIL) OBJTYPE(*FILE) +
                      NEWOBJ(&resultfile)                         /* note 2 */

MOVOBJ     OBJ(QTEMP/&newname) OBJTYPE(*FILE) +  
                      TOLIB(&mylib)                               /* note 3 */
ENDPGM

Note 1: Since you cannot pass variable filename and library for the query outputfile, then leave the default (QTEMP/QQRYOUT) in your Query400 object. If you do that this RUNQRY will run and output the file QTEMP/QPQUPRFIL.

Note 2: Renames the QTEMP/QPQUPRFIL into your chosen filename, still located in QTEMP.

Note3: Now move the file to the library of your choice.

Remember this code is just a sketch; – you should add some MONMSG a.o. before putting into production.

If you create a command you may pass all the parameters to the CL.

Happy coding.

DanF

 2,540 pts.

 

You’re looking for something like this:

OVRPRTF FILE(QPQUPRFIL) OUTQ(XEROX_2)
RUNQRY QRY(QRYLIB/DLYTRANS01)
DLTOVR FILE(QPQUPRFIL)

 145 pts.

 

Sorry, I had some mis-naming in my prev CL coe. Hee it is corrected:

PGM
DCL        VAR(&QRYLIB)    TYPE(*CHAR) LEN(10) VALUE('qrplobj ')
DCL        VAR(&QRY400OBJ) TYPE(*CHAR) LEN(10) VALUE('q       ')

DCL        VAR(&RESULTFILE) TYPE(*CHAR) LEN(10) VALUE('myfile')
DCL        VAR(&MYLIB)      TYPE(*CHAR) LEN(10) VALUE('mylib')

RUNQRY     QRY(&QRYLIB/&QRY400OBJ) OUTTYPE(*OUTFILE)     /* note 1 */

RNMOBJ     OBJ(QTEMP/QPQUPRFIL) OBJTYPE(*FILE) +                     
             NEWOBJ(&resultfile)                         /* note 2 */

MOVOBJ     OBJ(QTEMP/&resultfile) OBJTYPE(*FILE) +                   
             TOLIB(&mylib)                               /* note 3 */
ENDPGM

I can confirm that Teandys tip on printing the output works.

DanF

 2,540 pts.

 

Since you cannot pass variable filename and library for the query outputfile ???
— why??? not because a restrition of CL or Query/400

RUNQRY QRY(MYLIB/MYQRY) OUTTYPE(*OUTFILE) OUTFILE(&MYLIB/&MYOUTF)
works just fine.

Phil

 44,070 pts.