|
On Fri, 2004-11-05 at 16:03, Bob Cozzi wrote: > Oh man Joel! This is why people have trouble understanding the APIs and > prototypes. > Your example passes the full 3000 bytes as the command string every time. > That is not necessary. > Working with your code, it would be "better" to have it as follows: > > d sysCommand pr extpgm('QCMDEXC') > >>d commandString 3000 const OPTIONS(*VARSIZE) > d commandLength 15 5 const > >>d QcmdCmd s 3000 VARYING > >>d QcmdLength s 10I 0 > > Defining QcmdLength this way means you never have to do anything other > than use the parameter name (assuming you populate and use QcmdCmd...) > > EX: > c Eval QcmdCmd = 'RMVLIBLE LIB(CVTSPLV4R1)' > >>c CallP(E) sysCommand( QcmdCmd : %len(qcmdcmd) ) > > Summary of changes: > Add OPTIONS(*VARSIZE) to the commandString parameter. > Add VARYING to the CL variable that contains the command to be run. > Change the data type of the QcmdLength variable to 10I0. Since CommandLength > is "const" the compiler will convert the Int4 value into a 15P5 value > automatically (the pleasure of prototyping correctly!). > Changed the 2nd parm value of the CALLP to sysCommand to be the current > length of the no variable length string. > > -Bob Cozzi Thanks Bob, I got this example several years ago and never really re-examined it. And to think at the time I was just happy it worked! :-) Actually, doing it this way, would we even need to define QcmdLength? It isn't used for anything since we are passing %len( QcmdCmd )... d sysCommand pr extpgm('QCMDEXC') d commandString 3000 const OPTIONS(*VARSIZE) d commandLength 15 5 const d QcmdCmd s 3000 VARYING EX: c Eval QcmdCmd = 'RMVLIBLE LIB(CVTSPLV4R1)' c CallP(E) sysCommand( QcmdCmd : %len(qcmdcmd) ) It never occurred to me to use *VARSIZE variables. I am a big fan of varying strings, so I should have done this sooner. As always, thanks for the tips! Joel http://www.rpgnext.com
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2025 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.