Today we’ll discuss another of RDz’s code reuse options: Templates – which provide another approach to reuse/workflow – and at least in some respects simpler code reuse.
What are code Templates?
The name Templates implies some sort of scaffolding … or a program framework – or portions of code to be completed by users. And you can use Templates as such. But most RDz shops use them as containers for custom, shop-specific, complete/finished code … and/or standardized statement examples.
Although it’s important to point out that RDz comes equipped with a robust set of default language Templates as part of the client software. The default language Templates are used in a similar fashion to custom/shop-specific Templates. They can be edited, removed and extended … something we’ll cover in this article.
Template language support
Figure 1 shows both Template and Snippet availability across the various z/OS programming languages. In looking through the Support columns of Figure 1 you might be tempted to think that Templates are inferior to Snippets. Actually Templates provide a superior workflow feature (they are utilized through standard RDz Content Assist (Ctrl+Spacebar).
The aforementioned default Templates have become a standard code development asset in RDz shops. And because Templates are intrinsically different from Snippets, many shops use both the RDz-default Templates and Snippets – as well as rolling their own custom Templates and Snippets.
Template Preferences for COBOL
You create Templates from within the RDz Preferences dialog. Figure 2 shows the default (un-customized) Templates panel for the COBOL language. The Templates functionality for all of the other z/OS languages (Figure 1) are the same as COBOL’s.
You can see from where the slider bar is in Figure 2 that there are a large number of COBOL Templates delivered with RDz – each being a variation on some statement. For example, from Figure 2 you can see different types of COBOL ADD statements that include SIZE ERROR clauses, CALLs with exception handling, etc.
You can also see from Figure 2 that the Template creation options include:
- Create New…
- Edit and Remove existing (and un-remove… if this is confusing think Facebook: Friend … Un-friend)
- Revert to the defaults (undo all of your Workspace Templates)
- Import Templates to your Workspace
- Export Workspace Templates in order to share (think Instagram for z/OS code example)
An important point – Templates are tied to your Workspace. They are stored inside of your Workspace folders in a compressed, non-shareable format. There are two ways of sharing Templates:
- Creating custom RDz Workspace(s)
The custom RDz Workspace option would make more sense to use as the delivery mechanism for an initial default set of Templates – which will include the RDz-provided defaults but could include shop-specific/custom code.
Using a Template
Let’s start with using a COBOL Template (other languages follow the same pattern). Do the following:
1.Open a file that has been z/OS File Mapped to COBOL (the workstation file extension should be: *.cbl)
2.Set your mouse focal point to where you want the Template to be inserted (for instance, a COBOL ADD statement should be inserted within the COBOL PROCEDURE DIVISION, in the “B Margin”)
4.Then press Ctrl+Spacebar a second time – this will bring up the list of Templates that you saw in Figure 2.
5.Double-click to select a Template and insert it in your source code at the point of your mouse cursor focus – or Single-click a Template from the list to show the template’s Description. This is shown in Figure 3:
Figures 4 and 5 show the default Templates for SQL and JCL. Again, see Figure 1 for a list of Template support in the z/OS software languages……..
Creating a custom Template
To create a new/custom JCL Template…
- From: Preferences > COBOL > Templates, click: New…
- Type in a Template Name. Optionally add a Description – which will show up as hover help inside of the Templates popup
- Enter (type in) your Template code. Optionally add a variable – which will insert a default value from your editing environment.
This is shown in Figure 6. But what is not shown in Figure 6 is that, for C/C++, PL/I, Assembler, COBOL, Java, etc. when you define a custom Template you get to select the “Context” under which the user can insert the Template. Context simplifies Workflow and lowers code-reuse errors, by making the Template usage language-specific (i.e. PL/I Templates do not even appear as options if you’re editing a JCL or COBOL file).
From Figure 6 you may notice that the there are only eight variables and all eight are hard-wired to specific values: the current date, your PC name (user name), etc. So unlike Snippets, which provide complete control over the creation and use of free-form variables within code fragments, Templates (for all practical purposes) don’t offer much – if anything in the way of variable extensions to the defined code fragments.
This is why:
Although, as Figure 6 shows, rules can be broken (I’ve created a Template that deletes a VSAM dataset through IDCAMS/JCL)
Figure 7 shows the use of the custom IDCAMS/JCL template – and also the use of a default/RDz-provided JCL JOB Statement Template to create a JCL file for a job. I used Ctrl+Spacebar to add both sets of code. Very little effort – lots of time saved.
Choosing between Snippets and Templates
Both Templates and Snippets are supported by Push-to-Client (RDz version 9.5 offers support for Snippet P2C) and both the LPEX and language-specific editors offer the same access to/use of Templates and Snippets.
Net: Code reuse can save time & money – both during development and during program maintenance. RDz Snippets and Templates provide “economy of scale” … where a few individuals build out/provide a base of reusable code patterns – and many developers benefit from the shared work.
With its tooling that; Simplifies workflow, Implements Export/Import and Manages with Push-to-Client support, RDz equips you with an effective blueprint for building out reusable language/program patterns.
After finishing this section in an RDz class one of my students stated: “Do you know what’s better than coding…? Not coding.”
Thank you for your time (this was a lot of detail to wade through) ð Jon Sayles/IBM – email@example.com