I have a requirement where in a RPGLE pgm will have to dynamically create a CL pgm / MBR , add in source in it may be through PF, compile it and execute it and send intimate the user.
Announcement
Collapse
No announcement yet.
How to dynamically generate a CL mbr add src in it, compile n execute it thru RPGLE
Collapse
This topic is closed.
X
X
-
The how would be pretty much as you describe. Your RPGLE program should write the source to a source file (writing it using embedded SQL would be easier, native IO does not really like writing actual source files), then it would run a compile command (either using QCMDEXC or a companion CL program). It could call it if you define a procedure prototype where the program name is a variable: "Dcl-pr MyNewPgm extpgm(variable_name) end-pr; and set vasriable_name to the name pf the program. Then when you do MyNewPgm(); it would call the new program assuming it was compiled into a library that a. is in the library list, and b. is in a library that is higher in the library list than any other libraries that contain the same program name.
But not sure what you mean by "send intimate the user"
And more important is the why - circumstances that require a custom program to be created on the fly are very rare, and most CL commands (basically any that does not make use of return variables) can be built as strings in an RPGLE program and then executed with QCMDEXC. So can you explain in more detail what this program will actually do, and maybe we can advise you better
- Likes 1
-
Thanks for your reply!
My requirement is like would design a RPGLE pgm which will be a source generator which will create a CL member, and generate code
For generating code, it will have common code that is stored in the template file PF with priority field, so copy the records from that PF till the priority changes in the src member and then read the record from another file which is populated based on the input from the screen. So basically it can be copy file command or delete record or call program with the required parameters. We can have use CL as well if required.
As of now I have to get this requirement clear....
Send intimate the user means sending sending emails to the user that the code has been generated...
-
Ok let me make elaborate it. For each project that goes into the production we create a cl program source which do a cpyf and/or call a pgm to update certain file. This CL source has i/p parameters. So this source has to generate for every instance of the project. So user will enter necessary details in the screen and depending on that we are required to generate this CL source member and add in the required code in it. The common code will be has to be taken from a template file. After that compile the cl member as well.
Comment
-
Is there anything that the CL has to do that can't just be done with QCMDEXC, calls to static CL programs and other RPG based functionality as Vectorspace suggests ?
That way all the data entered for a project could be stored in a table and used to control a single program. Constantly generating and compiling sources, with the resultant need to have clean-up mechanisms for the sources and the PGM objects just seems a very clumsy way to do things.
- Likes 1
Comment
-
JonBoy I agree but the requirement is such that we have to generate the CL pgm and compile it dynamically. This CL source is required to take care of backing out the changes that are done in the project.
I am just not sure how to go for it. Vectorspace can you pls explain your first post reply
Comment
-
What others are suggesting, is that as your template files for instance contain CL instructions, why can't you call a program to execute those commands using QCMDEXC. Here's some pseudo code for a CL to give you an idea:
Code:DCLF <your template file> Loop until end of file RCVF CALL PGM(QCMDEXC) PARM(<source line in template file> <cmd length>) End loop
The same can be done in RPG by calling QCMDEXC from there.
In your case, you'd build the complete set of commands in a file (e.g. in QTEMP or elsewhere if you need it kept) and a program simply reads the file and executes each instruction in it.
- Likes 1
Comment
-
Generate your source file however you think.
Execute a CRTBNDCL command to compile the program from that source file into QTEMP, named, for example, DYNPGM1 (This can be done using QCMDEXC to execute the command, or your RPGLE can call a CL program that specifies the command)
Have your RPGLE program include this definitions:
Code:dcl-pr dyamicProgram extpgm('QTEMP/DYNPGM1'); end-pr;
Code:call dyamicProgram();
But I must reiterate. There should be no technical reason why you need to dynamically generate source and compile it into a one time use program. Any task you can do that way, you can do with static programs and/or QCMDEXC.
You simply say that it's the requirement. Does that mean someone has told you specifically to do it this way?
You say that it's to back out changes. So I assume the commands must be dynamic because they will be different for every project. But if you want to dynamically build and run a set of commands from data in a file, then the way to do that is to build each command as a string and execute each in turn with QCMDEXC. It will be far faster and far more reliable than dynamically generating a program.
Comment
-
Could you take the template and add parameters to accept whatever is entered on the screen?
Or maybe use STRDBRDR
Originally posted by DipShell10 View PostOk let me make elaborate it. For each project that goes into the production we create a cl program source which do a cpyf and/or call a pgm to update certain file. This CL source has i/p parameters. So this source has to generate for every instance of the project. So user will enter necessary details in the screen and depending on that we are required to generate this CL source member and add in the required code in it. The common code will be has to be taken from a template file. After that compile the cl member as well.
- Likes 1
Comment
Comment