|
|||||||
|
|
![]() |
|
|
|
|
||
|
Retrieve Command Source Hey, Ted: I know how to retrieve the source code of a CL program (an OPM CL program, anyway). Is there a way to retrieve the source for a command? --Bill There's no RTVCMDSRC in OS/400, Bill, but if you don't mind getting your hands dirty, you might try the QCDRCMDD (retrieve command definition) API. It doesn't retrieve command source code; rather, it writes XML code to a stream file. This is not an easy API to get working. The error messages give you generic information. For instance, error CPE3021 says, "The value specified for the argument is not correct." But it doesn't tell you which argument has the incorrect value. I stumbled along, however, and eventually was able to generate XML for the GENDDL command, which I published in the June 5, 2002, edition of this newsletter. Here's my CL code:
pgm
dcl &cmd *char 20
dcl &destinfo *char 64
dcl &destfmt *char 8 value('DEST0200')
dcl &rcvvar *char 1
dcl &rcvfmt *char 8 value('CMDD0100')
dcl &error *char 16 value(x'00000000')
dcl &null2 *char 2 value(x'0000')
dcl &null3 *char 3 value(x'000000')
dcl &null10 *char 10 value(x'00000000000000000000')
chgvar &cmd value('GENDDL *LIBL')
chgvar %bin(&destinfo 1 4) value(0) /* CCSID */
chgvar %sst(&destinfo 5 2) value(&null2) /* country */
chgvar %sst(&destinfo 7 3) value(&null3) /* language */
chgvar %sst(&destinfo 10 3) value(&null3) /* reserved */
chgvar %bin(&destinfo 13 4) value(0) /* path type */
chgvar %bin(&destinfo 17 4) value(22) /* path name len */
chgvar %sst(&destinfo 21 2) value('/') /* delimiter */
chgvar %sst(&destinfo 23 10) value(&null10) /* reserved */
chgvar %sst(&destinfo 33 32) value('/home/tholt/genddl.xml')
call qcdrcmdd (&cmd &destinfo &destfmt +
&rcvvar &rcvfmt &error)
endpgm
After running my program, I FTP'd the generated stream file to my PC and opened the stream file in a Web browser. Here's what I saw:
- <QcdCLCmd DTDVersion="1.0">
- <Cmd CmdName="GENDDL" CmdLib="__LIBL" CCSID="37"
Prompt="Generate SQL DDL" MaxPos="99" MsgF="QCPFMSG"
MsgFLib="__LIBL" ExecBatch="YES" ChgCmdExit="NO"
RtvCmdExit="NO">
<Parm Kwd="OBJECT" PosNbr="1" KeyParm="NO" Type="CHAR"
Min="1" Max="1" Prompt="Object name" Len="258" Rstd="NO"
AlwUnprt="YES" AlwVar="YES" Expr="YES" Full="NO"
DspInput="YES" Choice="Character value" />
<Parm Kwd="OBJECTLIB" PosNbr="2" KeyParm="NO" Type="CHAR"
Min="1" Max="1" Prompt="Object library" Len="258" Rstd="NO"
AlwUnprt="YES" AlwVar="YES" Expr="YES" Full="NO"
DspInput="YES" Choice="Character value" />
- <Parm Kwd="OBJECTTYPE" PosNbr="3" KeyParm="NO" Type="CHAR"
Min="1" Max="1" Prompt="Object type" Len="10" Rstd="YES"
AlwUnprt="YES" AlwVar="YES" Expr="YES" Full="NO"
DspInput="YES" Choice="TABLE, VIEW, ALIAS..." >
- <Values>
<Value Val="TABLE" />
<Value Val="VIEW" />
<Value Val="ALIAS" />
<Value Val="CONSTRAINT" />
<Value Val="FUNCTION" />
<Value Val="INDEX" />
<Value Val="SCHEMA" />
<Value Val="TRIGGER" />
<Value Val="TYPE" />
</Values>
</Parm>
<Parm Kwd="SRCFILE" PosNbr="4" KeyParm="NO" Type="NAME"
Min="1" Max="1" Prompt="Source physical file" Len="10"
Rstd="NO" AlwUnprt="YES" AlwVar="YES" Expr="YES"
Full="NO" DspInput="YES" Choice="Name" />
- <Parm Kwd="SRCLIB" PosNbr="5" KeyParm="NO" Type="NAME"
Min="1" Max="1" Prompt="Source library" Len="10" Rstd="NO"
AlwUnprt="YES" AlwVar="YES" Expr="YES" Full="NO"
DspInput="YES" Choice="Name, *CURLIB, *LIBL">
- <SpcVal>
<Value Val="*CURLIB" MapTo="*CURLIB" />
<Value Val="*LIBL" MapTo="*LIBL" />
</SpcVal>
</Parm>
- <Parm Kwd="SRCMBR" PosNbr="6" KeyParm="NO" Type="NAME"
Min="1" Max="1" Prompt="Source member" Len="10" Rstd="NO"
AlwUnprt="YES" AlwVar="YES" Expr="YES" Full="NO"
DspInput="YES" Choice="Name, *FIRST, *LAST">
- <SpcVal>
<Value Val="*FIRST" MapTo="*FIRST" />
<Value Val="*LAST" MapTo="*LAST" />
</SpcVal>
</Parm>
- <Parm Kwd="CRTSRC" PosNbr="7" KeyParm="NO" Type="CHAR"
Min="0" Max="1" Prompt="Create file and/or member?" Len="4"
Rstd="YES" Dft="*NO" AlwUnprt="YES" AlwVar="YES"
Expr="YES" Full="NO" DspInput="YES" Choice="*YES, *NO">
- <SpcVal>
<Value Val="*YES" MapTo="1" />
<Value Val="*NO" MapTo="0" />
</SpcVal>
- <Values>
<Value Val="*YES" />
<Value Val="*NO" />
</Values>
</Parm>
- <Parm Kwd="REPLACE" PosNbr="8" KeyParm="NO" Type="CHAR" Min="0"
Max="1" Prompt="Replace or append to source?" Len="8" Rstd="YES"
Dft="*APPEND" AlwUnprt="YES" AlwVar="YES" Expr="YES" Full="NO"
DspInput="YES" Choice="*REPLACE, *APPEND">
- <SpcVal>
<Value Val="*REPLACE" MapTo="1" />
<Value Val="*APPEND" MapTo="0" />
</SpcVal>
- <Values>
<Value Val="*REPLACE" />
<Value Val="*APPEND" />
</Values>
</Parm>
</Cmd>
</QcdCLCmd>
It's not pretty, but the information is there. As far as I know, there is no way to convert the XML to command source, but I hope somebody writes in and proves me wrong. --Ted
|
Editors
Contact the Editors |
| Copyright © 1996-2008 Guild Companies, Inc. All Rights Reserved. |