I used to fight to get apostrophes just right within RPG --- and then
"quoted" parameters within a quoted command add to the complexity ---
but I don't fight that anymore. Instead, I have written a procedure
(Enquote) that's in my most frequently-used service program to do all
the work for me.
So now, let's say I need to build a "MYEMAIL" command, which takes the
following simple parameters:
TO - the recipient address
FROM - the sender address
SUBJECT - guess
BODY - guess again
And the kicker would be that I need to put it into a variable that's
ready for QCMDEXC (not QCMDEXE, whatever that is ;) ).
Now it is a simple matter:
MY_COMMAND = Enquote('MYEMAIL TO(' + Enquote(recipient) + ') '
+ 'FROM(' + Enquote(sender) + ') '
+ 'SUBJECT(' + Enquote(subject) + ') '
+ 'BODY(' + Enquote(body) + ')'
QCMDEXC(MY_COMMAND: %Len(MY_COMMAND)) ;
Voila! Problem solved! (Of course, you have to ensure that MY_COMMAND
is long enough to hold the result, and all that jazz. . . and to
understand that there's a hard limit of 32K bytes in any result (which
you could easily bump to 64K).
Code is at http://code.midrange.com/aac45831b0.html
I actually favor a later version I have of this - more c-like, with
length checks and the like, but this one reads so much more clearly.
"To cease smoking is the easiest thing I ever did. I ought to know
because I've done it a thousand times."
-- Mark Twain
I have somewhat convoluted series of programs that is used to emailruns
shipping documents and invoices to customers. Our billing process
a CL program that (naturally) calls RPG. In the RPG program I useanother
QCMDEXE to put together a long string of 7 parameters to call
CL program which uses software called BLUESERIES to actually do thedon't
emailing (and occasional fax).
As I struggled to put this together, I had trouble getting RPG to
string the commands together with quotes and parentheses, etc. I
remember all the methods I tried.before
I created a command to call the last CL program. RPG calls the CMD
with parameters, which runs the CL program and the documents get
Customers are happy, billing dept is happy, life is good.
Then one of our customers has an email address with a hyphen in it.
The CMD blows up.
"Message . . . . : Expression operator not allowed for parameter
Cause . . . . . : An expression operator was found immediately
after a character string with no intervening blanks on a parameter
not support expressions. Character string expressions are only
CHGVAR commands, IF commands, or a parameter defined with
Arithmetic, relational, and logical expressions are only allowedon
CHGVAR and IF commands. Recovery . . . : Remove the expression
or insert a blank between the operator and the character string.
information on expression operators can be found in the CL
Is there an easy way to edit the CMD parameters as part of the CMD?
if I edit in RPG and find a hyphen, what can I do to pass it
This whole thing took me a while to get working and for some reason,
could not set up the QCMDEXE call correctly with the 7 parameters ifI
had to "CALL MYCLPGM (parm1 parm2 parm etc). But I could with the CMD.mailing
So to recap in reverse, the final step is a CL program that receives
parameter of email address, customer name, type of document to send.
It creates a path statement and runs BLUESERIES to send/fax the
A CMD is used to fire off the CL program. If the email address has a
hyphen in it, the CMD bombs.
An RPG program calls the CMD
This is the RPG programming on the IBM i / System i (RPG400-L)
list To post a message email: RPG400-L@xxxxxxxxxxxx To subscribe,
unsubscribe, or change list options,
or email: RPG400-L-request@xxxxxxxxxxxx Before posting, please take a
moment to review the archives at http://archive.midrange.com/rpg400-l.