× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Hello Nelson,

You wrote:
>I've probably missed this in previous threads, but what is the value or
>benefit of using the C 'system' over using QCAPCMD in the first place?

Because it is simple and it allows literal strings to be used in an easier
manner.  For example, the following definitions:

D int_t           S             10I 0
D pointer_t       S               *
D rc              S                   LIKE(int_t)

D system          PR                  LIKE(int_t) EXTPROC('system')
 *
 * Required parameter group:
 *                             OS/400 command
D   command                           LIKE(pointer_t) VALUE
D                                     OPTIONS(*STRING)

allow me to code:

C               callp           system("DSPMSG")

or

C               eval            rc = system("DSPMSG")

whereas using QCMDEXC with the following prototype:

 /if defined(LONG_PROC_NAMES)
D QcaRunClCmd     PR
 /else
D QCMDEXC         PR
 /endif
D                                     EXTPGM('QCMDEXC')
 *
 * Required parameter group:
 *                              A Control Language command string
D  clCmd                     32702    CONST OPTIONS(*VARSIZE)
 *                              Length of command string
D  clCmdLen                     15  5 CONST
 *
 * Optional parameter group:
 *                              A DBCS data flag
D  dbcsFlag                      3    CONST OPTIONS(*NOPASS)

requires:

C               callp           QCMDEXC("DSPMSG" : 6)

or

D $CMD          C                       CONST('DSPMSG')

C               callp           QCMDEXC($CMD : %SIZE($CMD))

both of which are slightly uglier than system().

Using QCAPCMD is uglier still but much more powerful since its prototype
looks like:

 /if defined(LONG_PROC_NAMES)
D QcaProcessClCmd...
D                 PR
 /else
D QCAPCMD         PR
 /endif
D                                     EXTPGM('QCAPCMD')
 *
 * Required parameter group:
 *                              Command string to process
D  clCmd                     32702    CONST OPTIONS(*VARSIZE)
 *                              Length of command string
D  cmdLen                       10I 0 CONST
 *                              Options control block
D  optCtlBlk                          LIKE(Qca_PCMD_CPOP0100)
D                                     CONST OPTIONS(*VARSIZE)
 *                              Length of options control block
D  optCtlBlkLen                 10I 0 CONST
 *                              Format of options control block
D  format                        8    CONST
 *                              Changed command string
D  chgClCmd                  32767    OPTIONS(*VARSIZE:*OMIT)
 *                              Length provided for changed command string
D  chgClCmdLenProv...
D                               10I 0 CONST
 *                              Length available for changed command
string
D  chgClCmdLenAvail...
D                               10I 0
 *                              Error code
D  errorCode                  1024    OPTIONS(*VARSIZE)

In all the "ugly" cases the solution is to create a wrapper procedure that
masks the ugliness behind a nice interface.  For example:

C               eval            errCode = runCLcmd("DSPMSG")

where runCLcmd is a nice wrapper procedure that may in turn use either
QCMDEXC or QCAPCMD or even system.

I use system where I expect the command to succeed (e.g., DSPMSG is
unlikely to fail) but I use the other methods when there is a reasonable
chance of the command failing.  However, if you take the effort to create
a decent runCLcmd procedure you get the best of both worlds.

Regards,
Simon Coulter.
--------------------------------------------------------------------
   FlyByNight Software         AS/400 Technical Specialists
   http://www.flybynight.com.au/

   Phone: +61 3 9419 0175   Mobile: +61 0411 091 400        /"\
   Fax:   +61 3 9419 0175   mailto: shc@flybynight.com.au   \ /
                                                             X
                 ASCII Ribbon campaign against HTML E-Mail  / \
--------------------------------------------------------------------



As an Amazon Associate we earn from qualifying purchases.

This thread ...


Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.