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.

Jon_30Nov_Figure1
Figure 1 – Language Options for Snippets and Templates


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:

  1. Export/Import
  2. 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.

Jon_30Nov_Figure2
Figure 2 – COBOL Code Templates – defaults from IBM


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”)

    3.Press Ctrl+Spacebar

    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……..

Jon_30Nov_Figure3
Figure 3 – Pressing Ctrl+Spacebar twice brings up the Templates for a giving language – Double click to insert the Template into your code

Jon_30Nov_Figure4
Figure 4 – SQL Code Templates – activate by; Editing an SQL statement pressing Ctrl+Spacebar one time

Jon_30Nov_Figure5
Figure 5 – JCL Code Templates – activate by; Editing a file mapped to *.jcl and pressing Ctrl+Spacebar one time


Creating a custom Template
To create a new/custom JCL Template…

  1. From: Preferences > COBOL > Templates, click: New…
  2. Type in a Template Name. Optionally add a Description – which will show up as hover help inside of the Templates popup
  3. 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).

Jon_30Nov_Figure6
Figure 6 – Create a custom JCL Template to delete a KSDS Dataset

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:

  • Snippets are often used for larger coding constructs: Paragraphs/Sections/Procedures/JCL Job Steps, even entire program shells
  • Templates are better suited to more granular coding patterns: Statements … even partial statements or fragments of code, etc.
  • 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.

    Jon_30Nov_Figure7
    Figure 7 – Create a JCL file to delete a VSAM dataset using two Code Templates – Note this also shows the JCL Template options accessed via Ctrl+Spacebar


    Choosing between Snippets and Templates

    Snippets provide:

  • More flexibility – through superior variable definition and availability
  • Clearer organization – through the use of Drawers – which categorize Snippets
  • But Snippets require users to learn about each Snippet, and learn how to use them
  • And they’re not Content Assist enabled
  • Templates provide:

  • Much less in the area of defined text-variables:
  • Which suggests that Templates are better at encapsulating short/granular program statements
  • And that they have a lower re-usability merit for longer/complex code patterns
  • Much better workflow than Snippets
  • Through the standard use of Ctrl+Spacebar to access/insert Templates
  • And because when you define Templates for most languages you also define Context further simplifies workflow.
  • 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.”

    Exactly.

    Thank you for your time (this was a lot of detail to wade through) 🙂 Jon Sayles/IBM – jsayles@us.ibm.com

    1 comment on"The Economics of Code Reuse – RDz Snippets & Templates Part II – Jon Sayles/IBM"

    1. I really appreciate the details in your posts. Thanks for that.

    Join The Discussion

    Your email address will not be published. Required fields are marked *