|
This started as a question to me off list. The person was trying to run
this piece of code partly taken from code I had posted but with changes.
In the original code the commands or program calls are done in the code.
He was trying to learn and he thought by adding the *entry parm cmd he
could test and learn / see what it did. Here was his message and code....
Names removed to protect the innocent :)
/snip
I realize this is a very old subject, but I didn't need it at the time.
Now I've dug through the archives and low and behold...
I'm still cutting my teeth with RPGIV ILE, so bear with me. I need a way
to use QCMDEXC, but am having some difficulty. I was wondering if you
could help me out. I'm trying to compile this with CRTBNDRPG for testing
purposes. Here's what I've got:
*--------------------------------------------------------------------*
* Prototype Definition to Execute Command (QCMDEXC API) *
*--------------------------------------------------------------------*
d ExecuteCommand PR ExtPgm('QCMDEXC')
d cmdstr 3000A Const Options(*VarSize)
d cmdLen 15P 5 Const
d cmdOpts 3A Const Options(*NOPASS)
d cmdstr s 3000A
d cmdLen s 15P 5
d cmdOpts s 3A
d cmd s 3000A
d Len s 15P 5
d Opts s 3A
c *entry plist
c parm cmd
c parm Len
c CallP ExecuteCommand(cmd:%len(cmd))
c eval Len = %len(cmd)
c eval *inlr = *on
c return
And here's the results...
Display All Messages
System:
S10DXXXB
Job . . : User . . : XXXXXX Number . . . : 184912
>> call run ('SBMJOB WRKACTJOB CMD(WRKACTJOB SEQ(*CPUPCT) OUTPUT(*PRINT))
JOB
Q(QSYSNOMAX) OUTQ(QPRINT)' 87)
String ' G ' contains a character that is not valid.
String ')~ 87»' contains a character that is not valid.
Error found on *N command.
Errors occurred in command.
Function check. CPF0006 unmonitored by RUN at statement 0000000020,
instruction X'0000'.
The call to *LIBL/QCMDEXC ended in error (C G D F).
The call to *LIBL/QCMDEXC ended in error (C G D F).
What am I doing wrong?
/end snip
There was other items remove to get to code posted yesterday but ......
That is when the topic of parm larger than 32A has junk(memory that you aren't
supposed to be using) came into play. And the search to change code to allow
him to do it.
Now he has a chance to see the bifs %scan and %replace also :). And yes
I know that it is easier to type WRKACTJOB on command line than to call
this with
CALL PGM(TESTQCMD) PARM(WRKACTJOBENDCMD) :) But then again I've been
know to take the hard way. :)
Hope that shows you how this came about. I just picked it up and ran with
it along with the other 20+ things I had to do yesterday... :)
I did tell him to ask list because there were smarter people here than me
on this and other subjects.... :)
Take care all
Bill Hopkins
"Bob cozzi" <cozzi@xxxxxxxxx>
Sent by: rpg400-l-bounces+bhopkins=libertyhardware.com@xxxxxxxxxxxx
11/07/2003 08:38 AM
Please respond to RPG programming on the AS400 / iSeries
To: "'RPG programming on the AS400 / iSeries'"
<rpg400-l@xxxxxxxxxxxx>
cc:
Subject: RE: Junk Passed 32 on 3000A parm
If you truly want to call this program from command entry (and I don't
understand why since you can run commands directly from command entry)
then
it should be wrapped in a CMD definition. That's what those things were
invented to handle.
Bob Cozzi
Cozzi Consulting
www.rpgiv.com
-----Original Message-----
From: rpg400-l-bounces@xxxxxxxxxxxx [mailto:rpg400-l-bounces@xxxxxxxxxxxx]
On Behalf Of Bill Hopkins
Sent: Friday, November 07, 2003 7:33 AM
To: RPG programming on the AS400 / iSeries
Subject: RE: Junk Passed 32 on 3000A parm
I call with this from command line
CALL PGM(TESTQCMD) PARM('CALL PGM(FORCASTX)ENDCMD')
When looking at code in Debug I see "garbage" in parm after 32A or after
where command ends. "It's actually not garbage, but rather it's memory
that you aren't supposed to
be using" Sorry was trying to explain to someone off list, should have
taken it more technical but hey I'm a "High Tech Red-neck" so sometime you
get "junk and garbage" for replacement terms :). But speaking of
replace.....
I get the start position of "ENDCMD" with %scan returning value of 19
where E of ENDCMD is located in cmd parm which looks like this.... CALL
PGM(FORCASTX)ENDCMD o CALLf PGMØ '
o TESTQCMDf PARMØ E CALL PGM(FORCASTX)ENDC'
MD» '
'
'.
Then comes the %replace
%REPLACE(replacement string: source string{:start position {:source
length to replace}})
1)Replacement string is a blanks ' '
2)Source String is the cmd parm field with "garbage" oops "rather it's
memory that you aren't supposed to be using" past 32A parm length.
3)Start Position for replace is set to 19 in pos from %scan above.
4)LENGTH TO REPLACE (not position of replace) 2999
The fourth parameter represents the number of characters in the source
string to be replaced. If zero is specified, then the replacement string
is inserted before the specified starting position. If the parameter is
not specified, the number of characters replaced is the same as the length
of the replacement string. The value must be greater than or equal to
zero, and less than or equal to the current length of the source string.
I picked 2999 just in case there was a one letter command or program name
being sent.
So after this you get
CALL PGM(FORCASTX) in the cmd parm field used in callp to ExecuteCommand
Now question now comes up because I go from 19 and replace 2999 from there
what happens to the 17 of run over does it effect memory or create more
"garbage" :) ??????
Lord knows I don't know... Any one else out there who does.
PS Good luck on new job you can see from writing skills and limited
knowledge no way in heck I could do it.
Tare Care
Bill Hopkins
d ExecuteCommand PR ExtPgm('QCMDEXC')
d cmdstr Like(cmd) Const Options(*VarSize)
d cmdLen 15P 5 Const
d cmdOpts 3A Const Options(*NOPASS)
D cmd S 3000A
> D pos S 5U 0
>
> c *entry plist
> c parm cmd
> C Eval pos = %scan('ENDCMD':cmd)
> C Eval cmd = %replace(' ':cmd:pos:2999)
> C CallP ExecuteCommand(cmd:%len(%trim
> C (cmd)))
> C eval *inlr = *on
> C return
Scott Klement <klemscot@xxxxxxxxxxxx>
Sent by: rpg400-l-bounces@xxxxxxxxxxxx
11/06/2003 06:12 PM
Please respond to RPG programming on the AS400 / iSeries
To: RPG programming on the AS400 / iSeries
<rpg400-l@xxxxxxxxxxxx>
cc:
Subject: RE: Junk Passed 32 on 3000A parm
Hi Bill,
This code won't actually solve the problem, at least not while you've
still got the %len(%trim(cmd)) in your code. Sure, you now know where
the end of your string is, but you're not using that to set the length
that's passed to QCMDEXC. :)
The data that comes after "ENDCMD" is still going to be garbage, so unless
ENDCMD is always in positions 2995-3000 of the "cmd" string, your call to
%trim() will always face the chance of picking up "garbage." (It's
actually not garbage, but rather it's memory that you aren't supposed to
be using)
A better solution (IMHO) than searching for some string would be creating
a *CMD as a front-end to your program. Something like this should work:
CMD PROMPT('MY COMMAND')
PARM KWD(CMD) TYPE(*CHAR) LEN(3000) +
PROMPT('Command to run')
Now, the operating system knows that it needs to allocate 3000 chars to
use as the parameter, so you won't get the "garbage" that you were getting
before.
At any rate, this question has been asked and answered many times before.
Search the archives or the FAQ, and you'll find lots of ways to work
around the issue.
Good Luck
On Thu, 6 Nov 2003, Bill Hopkins wrote:
> D cmd S 3000A
> D pos S 5U 0
>
> c *entry plist
> c parm cmd
> C Eval pos = %scan('ENDCMD':cmd)
> C Eval cmd = %replace(' ':cmd:pos:2999)
> C CallP ExecuteCommand(cmd:%len(%trim
> C (cmd)))
> C eval *inlr = *on
> C return
_______________________________________________
This is the RPG programming on the AS400 / iSeries (RPG400-L) mailing list
To post a message email: RPG400-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/rpg400-l
or email: RPG400-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at http://archive.midrange.com/rpg400-l.
_______________________________________________
This is the RPG programming on the AS400 / iSeries (RPG400-L) mailing list
To post a message email: RPG400-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/rpg400-l
or email: RPG400-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at http://archive.midrange.com/rpg400-l.
_______________________________________________
This is the RPG programming on the AS400 / iSeries (RPG400-L) mailing list
To post a message email: RPG400-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/rpg400-l
or email: RPG400-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at http://archive.midrange.com/rpg400-l.
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.