Oftentimes it’s necessary to alter the 2E generated source before your function is compiled. In this case what I really wanted to do is add my own H Specs in before the program is compiled. This article will outline how I was able to do this with some user source and the YSCNRPLSRC command provided by 2E.
Note! In order for this to work you will need to have the 2E preprocessor setup. If you don’t have this setup there is a manual provided by 2E to do so.
OK so first thing we need to do is establish a user source that will hold all of the H specs that I want to include in my function. I’m going to setup this source in my QRPGLESRC source member in my generation library.
So now I have a member in my QRPGLESRC source file called OPS00CB00 which will hold my custom H* Specs.
Next what I need to do is go into my *Template 2E provided file and create a Execute User Source. I’m going to call this new function Add Custom H Specs.
When I Zoom into this new function I’ve renamed the program OPS99R01 to hold the code that I want to insert into my Function. The Code is going to look like the following.
As you can see this is going to insert into my Function’s generated code a Y* CALL OPS99C01 statement. This new program OPS99C01 is going to hold the code for the YSCNRPLSRC. Now let’s code up OPS99C01. It will look like this.
This simple program will figure out the name of the program being generated and compiled using the job name. As you are probably aware the batch compiles are always the same name as the generated program name. Then the program uses the YSCNRPLSRC command to look for the statement,
H DATFMT(*YMD) DATEDIT(*YMD) DEBUG(*YES)
And replace it with a insert of a copybook as,
This is the OPS00CB00 which holds my custom H* Specs.
OK now that we have all the setup completed. Let’s insert a call to our Add Custom H* Specs function in a simple Display File function. We will be putting this call in the user point of USER: Initialize program.
Now we just generate/compile our function as normal.
Once that is complete you should see the following in the generated source member.
You’ll see from the above screen shot that my Y* CALL OPS99C01 has been inserted in the source code. Now let’s look at the compile listing.
As you can see my copybook was used and now my custom H* specs are now included in the generated code.
I find this most useful when putting a program into debug when the function is using SQL for record access instead of the default RPG record level access. The statements that are included to run the SQL statements are removed in debug so that you can just see the executed SQL statements. Makes running 2E programs in Debug MUCH easier.
This same technique can also be used to do other things if you wish to replace what the generated RPG code looks like, but you may need to run a combination of programs if you wish to scan and replace multiple lines of code.
One reason I like this technique so much is that I don’t need to mess with the generated code at all. Each time this function is going to be generated these H* Specs will always be included. And, if you combine the use of a template with this technique, you will never forget to put the line of code in the Initialize user point.
If you have any questions or comments please feel free to let me know! Thanks! Jason