Developer > WebSphere

Developer

Presented by:


PENTAX - Continuous Laser Printers

WDSC Code Templates and Snippets for RPG programmers

WebSphere - WDSC Code Templates and Snippets for RPG programmers

Bookmark and Share Print Email

Note: This article is accompanied by a video/audio tutorial to provide a more tangible learning experience. The video tutorial can be found on my Web site. Please let me know if having video makes your learning experience better. This tutorial uses WDSC V7.0.

Sometimes I like to think of myself as a lazy programmer. I say that somewhat in jest, but I don't like to repeat myself when writing code. I’ve become a big fan of writing RPG modules, among other techniques, and it flows into the tooling I use. In this article, we’ll see how code templates and snippets can save you time letting you store your most common pieces of WDSC code.

Code templates work great if you find yourself repeating the same section of code a lot. By default, WDSC comes with a good handful of code templates for you to review and learn how to compose. To view existing code templates, go to Window>Preferences>Remote Systems>Remote Systems LPEX Editor>iSeries Parsers>ILE RPG>Templates.

Using Code Templates

To use a code template, simply place your cursor between a beginning and ending /FREE and /END-FREE (or in C specs for those who still code in fixed format) and hit Ctrl+Space to bring up a window to select a template. Figure 1 shows how you can type “Dow” and it will bring up all built-in functions (BIFs) and code templates that match what you’ve typed. An icon to the left of each entry denotes whether it’s a BIF, code template or other live parsing and extensible (LPEX) facet. Pausing on a list entry will result in a display of a sampling of the code template to the right of the window.

Figure 2 shows what was created in your code after you hit enter to select the DOW_loop code template.

Developers can export and import templates to more easily share them with other developers. It’d be nice to skip the step of exporting and importing, but I haven’t yet found an easy way to have every developer in a shop pull from the same repository.

Using Snippets

Snippets are an alternative to code templates. They let you store blocks of source that aren’t meant to be used with Ctrl+Space functionality and also work outside of /FREE and /END-FREE (read C specs). I find them useful for things like subprocedure skeletons because I can easily store the basis of a new subprocedure without having to browse to another source member. I also insert new subprocedures outside of C specs, which means I couldn’t accomplish this seamlessly with code templates. To display the snippets view, select Window>Show View>Other>General>Snippets. By default, there are no System i platform-related snippets. Right-click anywhere on the snippet view and select “Customize.” Click “New” to add a category and name it RPG (see Figure 3).

Next, right-click on the RPG category and select New>New Item as show in Figure 4. Name the snippet and designate variables with names to be occupied when you insert this snippet during development (see Figure 5). Paste the desired code into the snippet (in this case, a skeleton of an RPG subprocedure). Place your cursor in the template pattern area where you want a variable and click “Insert Variable Placeholder.”

Last, place your cursor in a source member and double-click the snippet you just created from the snippets view. In this case, I made sure to place my cursor at the very beginning of a source line so the preceding spaces of the first snippet entry will line up appropriately. Figure 6 shows the prompting for the variables; modify them and select “Insert.” Rock on! You just saved yourself 45 seconds of mundane coding!

Aaron Bartell is an RPG and Java developer for www.krengeltech.com. Aaron can be reached at aaronbartell@mowyourlawn.com.

Advertisement



Buyers Guide

Browse products and services for Developer.



Advertisement