Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

AS400 - How to prompt user via CLP program for input. ie Print or Display query?

1,632 views
Skip to first unread message

jjeffre...@gmail.com

unread,
Feb 6, 2017, 3:20:39 PM2/6/17
to
Anyone know how to get input and then with an if statement runqry with print or display within an CLP CLLE program?

jamesa...@gmail.com

unread,
Feb 7, 2017, 8:03:04 AM2/7/17
to
On Monday, February 6, 2017 at 1:20:39 PM UTC-7, jjeffre...@gmail.com wrote:
> Anyone know how to get input and then with an if statement runqry with print or display within an CLP CLLE program?

Look up use of SNDF, IF & SNDDSPF commands (CLP manual).

Buck

unread,
Feb 8, 2017, 7:20:33 AM2/8/17
to
On Monday, February 6, 2017 at 3:20:39 PM UTC-5, jjeffre...@gmail.com wrote:
> Anyone know how to get input and then with an if statement runqry with print or display within an CLP CLLE program?

Convert it to a QMQRY with RTVQMQRY. Edit the source to include parameters. So instead of

...where salesdistrict = '1'

use

...where salesdistrict = &a

Then in your CL program, use STRQMQRY ... SETVAR((A &SALESDIST))... You can specify OUTPUT(*) or (*PRINT).

This is all from memory - I myself wouldn't do this today unless I were working on a machine without an HLL compiler (like RPG or Cobol). If you really want to do this in CL and only in CL, learning QMQRY is probably the easiest answer. Alternatives are Rexx and the DB2 interface in either QShell or PASE, I can't remember which at the moment.
--buck

CRPence

unread,
Feb 12, 2017, 6:04:18 PM2/12/17
to
On 06-Feb-2017 13:20 -0700, jjeffre...@gmail.com wrote:
> Anyone know how to get input and then with an IF statement RUNQRY
> with print or display within an CLP CLLE program?

Send User Message (SNDUSRMSG) can send a stored or impromptu message,
and enable obtaining a reply value into a CL variable [without
compiling/using a display file, as would be required with Send/Receive
File (SNDRCVF)].

PGM
DCL &OUTSPEC *CHAR 8
DCL &OUTTYPE *CHAR 8 '*PRINTER'
SndUsrMsg MSG('Direct Query Output to? (*PRINT or *)') +
DFT(*PRINT) MSGTYPE(*INQ) TOMSGQ(*) +
MSGRPY(&OUTSPEC) VALUES(* *PRINT)
If (&OutSpec *eq '*') Then(ChgVar &OutType '*DISPLAY')
/* '*N' occurs for no reply; defaults to *PRINTER */
RUNQRY TheLib/TheQuery OUTTYPE(&OutType)
ENDPGM

Creating a Command Definition (*CMD) object is an alternative means
to effect the presentation of a[n effectively dynamic] display file; the
Command Processing Program (CPP) would obtain the value specified on the
parameter by the user, and then utilize some means to enable the
invoking program to obtain the value -- a bit query, but the value could
even be returned via another parameter in the command that has been
defined with *YES for the Return Value (RTNVAL). More simply/direct
however, would be to create a command/CPP that would be specific to
running the query with the only parameter being the output
specification; i.e. the RUNQRY is encapsulated in that CPP:

Command source:

CMD RunThatQRY
PARM OUTPUT *CHAR RSTD(*YES) +
SPCVAL((* *) (*PRINT P)) MIN(0) LEN(1) +
CHOICE(*VALUES) PROMPT('Report output') DFT(*)

CPP source:

PGM PARM(&OUTSPEC)
DCL &OUTSPEC *CHAR 1
DCL &OUTTYPE *CHAR 8 '*PRINTER'
/* any value other than '*' runs with printer output */
If (&OutSpec *eq '*') Then(ChgVar &OutType '*DISPLAY')
RUNQRY TheLib/TheQuery OUTTYPE(&OutType)
ENDPGM


I wonder however, if perhaps coding the following [with any desired
adjustments made to selective prompt specifications and/or parameter
specifications], might effect what is required, without ceding too much
control to the user?:

? RUNQRY ?-QRY(THELIB/THEQUERY) ?-QRYFILE((*SAME))
?-RCDSLT(*NO) ?-OUTFORM(*RUNOPT)
?-PRTDFN(*RUNOPT) ?-OUTFILE(*N) ?-AUT(*RUNOPT)
?-FORMSIZE(*RUNOPT) ?-FORMTYPE(*RUNOPT)
?-COPIES(*RUNOPT) ?-LINESPACE(*RUNOPT)
??OUTTYPE(*DISPLAY) /* ?-PRTDEV(*RUNOPT) */
MONMSG CPF6801 EXEC(DO)
/* handler for the user having exited without Enter */
ENDDO

--
Regards, Chuck
0 new messages