I have been asked a couple of times about some utilities I wrote so I thought I would post them out here for anyone who wanted to use them. There are a couple of steps you need to set these up, but once you do, it will make some functions MUCH easier to use and read in your ILERPG. This one contains tools for running AS400 commands inside RPG.
1. Create a source file called QCPYSRC in some library that will be in your library list anytime you are going to compile a program.
2. Create a source member in the source file called CMDTOOLS and place the following code in the member. This member does NOT get compiled.
3. In one of your RPG source files, create a member called CMDTOOLS and copy the following source into it.
3. Ok, save the source and use option 15 to compile it somewhere.
4. Now we need to create a binding directory. In a library that will be in your library list when you compile stuff use the command
CRTBNDDIR to create a binding directory called CMDTOOLS.
5. Now you need to add your module to this binder. Use the command ADDBNDDIRE BNDDIR(CMDTOOLS)
OBJ((CMDTOOLS *MODULE)) to create an entry for your module in the binder.
Now your ready to use these procedures in your program.
To use these procedures in an RPG program, you just need to reference the binder in an H spec, and include the copy book in your source. For example:
There is also a procedure to display a command line or check the validity of a command.
1. Create a source file called QCPYSRC in some library that will be in your library list anytime you are going to compile a program.
2. Create a source member in the source file called CMDTOOLS and place the following code in the member. This member does NOT get compiled.
Code:
***************************************************************** * * * Copy Book for procedures defined in the service program * * CMDTOOLS * * * ***************************************************************** D RunCommand PR 272A D Parm1 32767A CONST D CheckCommand PR 272A D Parm1 32767A CONST D CommandLine PR
Code:
H OPTION(*NODEBUGIO:*SRCSTMT) DEBUG(*YES) NOMAIN ***************************************************************** * * * Service Program Name: CmdTools * * Description ........: This service program contains * * routines to make the handling of * * commands easier. * * * ***************************************************************** * API error data structure. D @@ErrorDS DS Qualified D ByteProv 9B 0 INZ(%SIZE(@@ErrorDS.msgdata)) D BytesAval 9B 0 INZ(%SIZE(@@ErrorDS.msgdata)) D Msgid 7A INZ(*BLANKS) D Filler 1A INZ(*BLANKS) D MsgData 256A INZ(*BLANKS) * Procedure definitions. /COPY QCPYSRC,CmdTools * Program Status Data Structure. D PSDS SDS QUALIFIED D MsgId 40 46 D MsgData 91 170 D QCMDEXC PR EXTPGM('QCMDEXC') D Parm1 32767A CONST D Parm2 15P 5 CONST D QCMDCHK PR EXTPGM('QCMDCHK') D Parm1 32767A CONST D Parm2 15P 5 CONST ***************************************************************** * * * Run Command Procedure * * * ***************************************************************** P RunCommand B EXPORT D RunCommand PI LIKE(@@ErrorDS) D P_CmdString 32767A CONST D Length S 5S 0 C RESET @@ErrorDS C EVAL LENGTH = %LEN(%TRIM(P_CmdString)) C MONITOR C Callp QCMDEXC(%trim(P_CmdString): C %LEN(%TRIM(P_CmdString))) C ON-ERROR C EVAL @@ErrorDS.MsgId = PSDS.MsgId C EVAL @@ErrorDS.MsgData = PSDS.MsgData C ENDMON C RETURN @@ErrorDS P E ***************************************************************** * * * Check Command Procedure * * * ***************************************************************** P CheckCommand B EXPORT D CheckCommand PI LIKE(@@ErrorDS) D P_CmdString 32767A CONST C RESET @@ErrorDS C MONITOR C Callp QCMDCHK(%trim(P_CmdString): C %LEN(%TRIM(P_CmdString))) C ON-ERROR C EVAL @@ErrorDS.MsgId = PSDS.MsgId C EVAL @@ErrorDS.MsgData = PSDS.MsgData C ENDMON C RETURN @@ErrorDS P E ***************************************************************** * * * Display a command line * * * ***************************************************************** P CommandLine B EXPORT D CommandLine PI C MONITOR C Call 'QUSCMDLN' C ON-ERROR C ENDMON C RETURN P E
4. Now we need to create a binding directory. In a library that will be in your library list when you compile stuff use the command
CRTBNDDIR to create a binding directory called CMDTOOLS.
5. Now you need to add your module to this binder. Use the command ADDBNDDIRE BNDDIR(CMDTOOLS)
OBJ((CMDTOOLS *MODULE)) to create an entry for your module in the binder.
Now your ready to use these procedures in your program.
To use these procedures in an RPG program, you just need to reference the binder in an H spec, and include the copy book in your source. For example:
Code:
H DFTACTGRP(*NO) OPTION(*NODEBUGIO:*SRCSTMT) H BNDDIR('CMDTOOLS') /COPY QCPYSRC,CmdTools /free runCommand('DSPMSG'); *inlr = *on; return; /end-free
Comment