You may have already done this . . . a command is typically defined by source statements, similar to creating a CL or RPG program. When using the CRTCMD just specify the program that will be launched by the command. It can be any type of program your iSeries supports - CLP, Cobol, RPG, etc.
Last Wiki Answer Submitted: March 13, 2012 3:31 pm by WoodEngineer5,525 pts.
All Answer Wiki Contributors: WoodEngineer5,525 pts.
If you live outside the United States, by submitting your email address you consent to having your personal data transferred to and processed in the United States.
…can i create a command which triggers a small program written by me in background?
Yes.
But the SBMJOB command already does that. What is different about your need that SBMJOB doesn’t handle? If you were to write your own, it would use SBMJOB as one of its instructions.
A bit more of a description of what you actually need to do would probably be helpful to us.
I have 3 commands in CL program..these 3 commands will show screens one by one once i run that CL program ..like… CALL MOM…Instead of CALL MOM,i thinking it to replace with one command..something like MOM/DAD only..
i tried to do that with below…
CRTCMD CMD(MOM) PGM(MOM) ..but getting error like below
“Command DSR not created in library QGPL. ”
Additional Message Information
Message ID . . . . . . : CPF0201 Severity . . . . . . . : 40
Message type . . . . . : Diagnostic
Date sent . . . . . . : 03/14/12 Time sent . . . . . . : 11:45:52
Message . . . . : Command MOM not created in library QGPL.
Cause . . . . . : One or more errors were detected.
Recovery . . . : See the previously listed messages either in the job log
or on the command source listing. Correct the errors and then try the
CRTCMD command again.
The ‘Recovery’ section says to look for earlier messages in the joblog. The CPF0201 diagnostic message is just a summary. There should be one or more messages before that message. If there are multiple errors in how the command is defined, then there will be multiple messages.
Those will be the messages we’ll need to see.
It will probably also be useful to see the source for the command. If you don’t need any parameters for your command, then the source will only need to be a simple CMD statement.
CL program
=========
0001.00 PGM
0002.00 WRKSYSSTS
0003.00 DSPMSG QSYSOPR
0004.00 WRKPRB
0005.00 ENDPGM
===============
Now i made the CL program type is CMD and try again to see the errors..
This is the command
CRTCMD CMD(MOM) PGM(DSR)
..got the below error
Message ID . . . . . . : CPF4102 Severity . . . . . . . : 40
Message type . . . . . : Diagnostic
Date sent . . . . . . : 03/14/12 Time sent . . . . . . : 15:57:54
Message . . . . : File QCLSRC in library *LIBL with member MOM not found.
Cause . . . . . : The file was not opened. The reason code is 05. The
reason codes and their meanings are as follows:
01 – The library does not exist.
02 – The file does not exist. The library does exist.
03 – The file does not exist. The library specified as *LIBL.
04 – The member was saved with storage freed.
05 – The member does not exist. The file does exist.
06 – The file does not have any members.
10 – The member on the remote system is not found.
14 – The member was saved with storage freed on the remote system.
15 – The member on the remote system does not exist. The file does exist.
That seems to be a big part of the problem. You don’t use CL program source to create a command object. You use command source to create a command object.
Your CL program would have type CLLE or CLP, and you compile it as a module or a program.
You need another source for the command definition. You use command definition statements in that member, and that member will have type CMD.
So, you need two separate members — one for the command and one for the program.
The command source is used to define the parameters of the command. And the program source is used to define the program that the command invokes.
The command source for your command will probably only have single statement for the entire source member. That will be a CMD statement.
You can type a CMD statement on a command line and press F4 to prompt it. That will show you what it looks like. See the Defining commands topic in the Information Center for details.
Now, open your source member in QCMDSRC, and put the CMD command into the source member. Close the member.
That’s all you need in that member. You can compile it with CRTCMD. You don’t have to use different names. You can use the same name for your command that you used for your program because they are different object types — one is the *PGM and the other is the *CMD. The command will execute your program when you run the command.
If you want your command to use parameters, you will add PARM statements to the source member after the CMD statement. Each PARM statement will define one parameter. You would also add parameters to your CL program to receive values from the command.
But you don’t need parameters, so your source for the command is just a CMD statement.
That’s all there is to it for a simple command like this.
You can see that I used “DSR” as the name of the command. You can use DSR or you can name it MOM or any name you want, as long as it isn’t the same as a command that already exists in the library that you want to compile it in.
Put this into that member:
FMT ** ...+... 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 ...+... 8
*************** Beginning of data **********************************************
0001.00 CMD PROMPT('My own new command')
****************** End of data *************************************************
That’s the source that defines your command. That’s all. Just a CMD statement (with some prompt text).
You already have the program. All you need is the command to run the program.
That will compile a source member named DSR from a file named mylib/QCMDSRC. The compiled command will be DSR in QGPL, and it will execute a program named DSR that is also in library QGPL. When you execute CRTCMD, it compiles the CMD source and links it to your program.
Once it compiles, you will run the command by typing DSR on a command line and pressing <Enter>. (That assumes you have QGPL in your library list.)
Also, you can then use DSR just like any other command when you write new CL programs. The DSR command will be pretty mucg just like any other command on the system.
Your command is very simple, so that’s all there is to it. When you make more complex commands, you will put more into the QCMDSRC member and you will use other parameters for the CRTCMD command. But nothing else needed for this.
Can you give us more dtails on what you want to accomplish?
It is hard to give advice without understanding more about what you need.
…can i create a command which triggers a small program written by me in background?
Yes.
But the SBMJOB command already does that. What is different about your need that SBMJOB doesn’t handle? If you were to write your own, it would use SBMJOB as one of its instructions.
A bit more of a description of what you actually need to do would probably be helpful to us.
Tom
I have 3 commands in CL program..these 3 commands will show screens one by one once i run that CL program ..like… CALL MOM…Instead of CALL MOM,i thinking it to replace with one command..something like MOM/DAD only..
i tried to do that with below…
CRTCMD CMD(MOM) PGM(MOM) ..but getting error like below
“Command DSR not created in library QGPL. ”
Additional Message Information
Message ID . . . . . . : CPF0201 Severity . . . . . . . : 40
Message type . . . . . : Diagnostic
Date sent . . . . . . : 03/14/12 Time sent . . . . . . : 11:45:52
Message . . . . : Command MOM not created in library QGPL.
Cause . . . . . : One or more errors were detected.
Recovery . . . : See the previously listed messages either in the job log
or on the command source listing. Correct the errors and then try the
CRTCMD command again.
See the previously listed messages…
The ‘Recovery’ section says to look for earlier messages in the joblog. The CPF0201 diagnostic message is just a summary. There should be one or more messages before that message. If there are multiple errors in how the command is defined, then there will be multiple messages.
Those will be the messages we’ll need to see.
It will probably also be useful to see the source for the command. If you don’t need any parameters for your command, then the source will only need to be a simple CMD statement.
Tom
CL program
=========
0001.00 PGM
0002.00 WRKSYSSTS
0003.00 DSPMSG QSYSOPR
0004.00 WRKPRB
0005.00 ENDPGM
===============
Now i made the CL program type is CMD and try again to see the errors..
This is the command
CRTCMD CMD(MOM) PGM(DSR)
..got the below error
Message ID . . . . . . : CPF4102 Severity . . . . . . . : 40
Message type . . . . . : Diagnostic
Date sent . . . . . . : 03/14/12 Time sent . . . . . . : 15:57:54
Message . . . . : File QCLSRC in library *LIBL with member MOM not found.
Cause . . . . . : The file was not opened. The reason code is 05. The
reason codes and their meanings are as follows:
01 – The library does not exist.
02 – The file does not exist. The library does exist.
03 – The file does not exist. The library specified as *LIBL.
04 – The member was saved with storage freed.
05 – The member does not exist. The file does exist.
06 – The file does not have any members.
10 – The member on the remote system is not found.
14 – The member was saved with storage freed on the remote system.
15 – The member on the remote system does not exist. The file does exist.
But the DSR (member exist)
Is the object DSR in the *LIBL?
Where is the source for MON?
By default the CRTCMD command looks in QCMDSRC
Now i made the CL program type is CMD…
That seems to be a big part of the problem. You don’t use CL program source to create a command object. You use command source to create a command object.
Your CL program would have type CLLE or CLP, and you compile it as a module or a program.
You need another source for the command definition. You use command definition statements in that member, and that member will have type CMD.
So, you need two separate members — one for the command and one for the program.
The command source is used to define the parameters of the command. And the program source is used to define the program that the command invokes.
The command source for your command will probably only have single statement for the entire source member. That will be a CMD statement.
You can type a CMD statement on a command line and press F4 to prompt it. That will show you what it looks like. See the Defining commands topic in the Information Center for details.
Tom
@Charlie,Tom..
Yes,Now the DSR is *CLP program in QGPL/QCLSRC
What i was thinking is if i create command MOM using CRTCMD..it should use program DSR to execute…
Now my problem is i need to satisify QCMDSRC part to finish this.. this is where i’m trying all false attempts ..
If understand now correctly..i need to create a command source..Could you pls tell me how to do that..?
As Tom said..i prompted ..CMD..it is not allowing me to create anything from that screen..don’t know whether i’m giving correct values or not….
As Tom said..i prompted ..CMD…
That introduced you to the CMD command.
Now, open your source member in QCMDSRC, and put the CMD command into the source member. Close the member.
That’s all you need in that member. You can compile it with CRTCMD. You don’t have to use different names. You can use the same name for your command that you used for your program because they are different object types — one is the *PGM and the other is the *CMD. The command will execute your program when you run the command.
If you want your command to use parameters, you will add PARM statements to the source member after the CMD statement. Each PARM statement will define one parameter. You would also add parameters to your CL program to receive values from the command.
But you don’t need parameters, so your source for the command is just a CMD statement.
That’s all there is to it for a simple command like this.
Tom
so Tom, you want me to make QCMDSRC member..looks like below
PGM
DSR or CMD DSR….?
ENDPGM
and what it type to be *CLP or *CMD..
and if i compile that with CRTCMD…
will it look like this..
CRTCMD CMD(QGPL/DSR) PGM(QGPL/DSR)
I may get this error again: Command DSR not created in library QGPL.
Following code is from simple command on our system. It may be similar to what you want to do:
/*===================================================================*/ /* DP - Display Spool files for Current Job. */ /* */ /* To compile: */ /* CRTCMD CMD(UTIL/DP) PGM(QSYS/QCMDEXC + */ /* SRCFILE(UTIL/QCMDSRC) */ /* */ /*===================================================================*/ CMD PROMPT('WRKJOB') PARM KWD(CMD) TYPE(*CHAR) LEN(20) + CONSTANT('WRKJOB OPTION(*SPLF)') PARM KWD(LEN) TYPE(*DEC) LEN(15 5) CONSTANT(20) ****************** End of data *******************************************Make a QCMDSRC member..looks like below
You can see that I used “DSR” as the name of the command. You can use DSR or you can name it MOM or any name you want, as long as it isn’t the same as a command that already exists in the library that you want to compile it in.
Put this into that member:
FMT ** ...+... 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 ...+... 8 *************** Beginning of data ********************************************** 0001.00 CMD PROMPT('My own new command') ****************** End of data *************************************************That’s the source that defines your command. That’s all. Just a CMD statement (with some prompt text).
You already have the program. All you need is the command to run the program.
Use CRTCMD to compile the command:
That will compile a source member named DSR from a file named mylib/QCMDSRC. The compiled command will be DSR in QGPL, and it will execute a program named DSR that is also in library QGPL. When you execute CRTCMD, it compiles the CMD source and links it to your program.
Once it compiles, you will run the command by typing DSR on a command line and pressing <Enter>. (That assumes you have QGPL in your library list.)
Also, you can then use DSR just like any other command when you write new CL programs. The DSR command will be pretty mucg just like any other command on the system.
Your command is very simple, so that’s all there is to it. When you make more complex commands, you will put more into the QCMDSRC member and you will use other parameters for the CRTCMD command. But nothing else needed for this.
Tom
@Tom
Finally i was able to execute the DSR program with DSR cmd…Thanks a lot to you folks..
Now i came to know where i’m doing mistake before this happens..It’s all about making command source
i was able to execute the DSR program with DSR cmd…
And somebody in the future might look through this question and recognize mistakes they made and see where it leads.
Trying new things is how to learn. We all made mistakes in the beginning. Glad you now have your own example that you can build on.
Tom