I’m going to run through some of the shortcuts/wizards we can employ with RPG using Rational Developer for i (RDi).
Nowadays, it is all about productivity. Gone are the days when we had a DPM (data processing manager) looking over our shoulders to ensure that we were thrashing out code (we didn’t have fancy job titles back then, either). And, having been a programmer for over 32 years, I am all for anything that saves me coding.
For example, if a database uses auto increments on account numbers, it saves me lines of coding. Fantastic.
So what do we have to help us with programming if we are using Rational Developer? By the way, the coding examples shown here are all of the latest free-format type. Rational Developer is great for introducing us to this latest syntax.
The first wizard I am going to show you is how easy it is to code a sub-procedure.
As we are going to show you free-form code, ensure you tick the Generate free-form D-spec and P-spec code.
Enter all the details you need for the sub-procedure, including any parameters and return values. Once all details have been input, the code is generated and placed in the correct location within our source. Our prototype and procedure is shown in the figure below.
The procedure wizard is a great way to standardise our coding.
With the D-Specification wizard, as you would imagine, we have lots of options for all the various layouts. As with the previous wizard, select Source → New → D-Specification… This will start the wizard.
In the figure below, we can see all the options that are available.
Once again, the source is generated and inserted where required in our source.
Java Method Call
The features to allow us to call Java objects were introduced in V5R1 of RPG. The wizards can help us enormously in creating the entire necessary source. As with the previous two wizards, select Source → New → Java Method Call … This will start the Java wizard.
In the example below, we input the package and class details, then the Java method to call.
All the procedures and definitions, along with the method call are coded for us.
Code Templates and Context Assist
As their names suggest, these are used to place template code in our C specs. The advantage of using free-form coding is that the templates can be used throughout your code.
To see all the code templates already provided for us, navigate to Windows → Preferences then navigate as shown in the figure below.
If you need to create your own templates, use the New… button to create your own.
How do we use these templates? To include a template in your source, key the template name and press the ctrl-Space key combination. As can be seen below, I coded the SELECT keyword and pressed ctrl-Space then selected the SELECT_OTHER_group template and, voila! the select group template has been included for me.
Personally, like many other programmers these days, I do not only code in RPG and the nuances between languages can cause confusion. For example, operational codes for string handling, like substring, that are spelt different in other languages; very annoying. This is where context assist functionality is a very useful.
Context Assist uses the ctrl-Space key combination. In the figure below, it can be seen if I type %SU then the ctrl-Space combination. All the valid operational codes are displayed and you can then drill down to the operational code you need. It will show all the necessary parameters and their order.
One of the great features of context assist is that this functionality also works for any procedures that you have created. In the figure below, we can see context assist popping up the details of our GetCustomerDetails procedure.
Code snippets are very similar to code templates and can be used to insert standard code into our source without having to open, then copy and paste, from other source members.
Firstly, we have to open the snippets view. This is achieved by selecting Windows → Show View → Other…
Then, select General → Snippets
We will now see the Snippets View within our workbench.
Unfortunately, there are no RPG snippets predefined for us but they are straightforward to create, so let us create some of our own.
Right-click anywhere in the Snippets view, then select Customize…
I hope that this article will make your RPG coding more productive and help you use these excellent aids supplied by IBM. And if you need help with RPG and RDi, why not take a look at my company’s training courses which can be found here?
Andy Youens is an IBM i consultant/instructor at Milton Keynes, UK-based FormaServe Systems.