fhg
Volume 7, Number 33 -- September 26, 2007

A Snippet Above the Rest

Published: September 26, 2007

by Paul Tuohy

You all know that a lot of code consists of similar patterns. In my previous article Be Content with Content Assist, I explained how Content Assist could be used to insert a standard piece of code. This is well and good, but it only applies to free form RPG or COBOL. What about fixed form specs or code that need some alteration?

Although not specifically designed with RPG or COBOL in mind, RSE contains a Snippets view that allows you to define snippets of code that may be amended as you insert them into your program.

The Snippets View

On the RSE menu, select "Window>Show View>Other." In the resulting window, expand "Basic" and select the "Snippets" view to see the window shown in Figure 1. Right-click in the "Snippets" view and select "Customize" to see the "Customize Palette," also shown in Figure 1.


Figure 1. Snippets View and Customizing Palette


A New Category

The first step (you will only have to do this once) is to define a new drawer for your Snippets. In the "Customize Palette" window select "New Category" from the drop-down menu on the "New" button and complete the description of the "Category" as shown in Figure 2.


Figure 2. Defining a New Category


Provide a name and description for the drawer and customize how and when you want it displayed in the "Snippets" view window. Click on the "Apply" button and your new Snippets drawer is defined.

While you are here, note the "Import" and "Export" buttons on the Toolbar. You can use them to share all the wonderful Snippets you are about to define.

Defining a Snippet

It is time to define a Snippet of code that you might find useful. As a simple example let's use a standard "Do While" loop for performing a sequential read of a file. (Feel free to change it to a "Do Until" loop if you prefer.)

In the "Customize Palette" window, right-click on the drawer name (RPG in the example) and select "New Item" from the drop-down menu. Start by providing a name and a description for the Snippet, as shown in Figure 3.


Figure 3. Defining a Snippet - Name and Description


Now you define "Variables" and the "Template Pattern." Variables are values that you can change when you use the Snippet and the template pattern is the code you want to insert with special placeholders for the variable values.

Define a variable by selecting the "New" button and completing the name of the variable, a description and, if required, a default value. When you have defined all the variables you think you might need, proceed to define the "Template Pattern" by entering the code for the snippet. Wherever you want a variable value inserted, simply click on the "Insert Variable Placeholder" button and select the required variable. Figure 4 shows the definition of a variable for the file name and the Snippet code for the "Do While" loop. The placeholders have already been inserted for the file name on the first read and in the "EOF BIF" and it is being inserted for the second read.


Figure 4. Defining a Snippet - Variables and Template


You might want to copy and paste code from the editor to the "Template Pattern," especially if you a coding a fixed-format spec.

When you are finished, click on the "OK" or "Apply" button. You now have a Snippet ready to use – it is listed in the RPG drawer in the Snippets view.

Using a Snippet

To make use of a Snippet while editing a source member simply double-click on the snippet (in the "Snippets View"), change the values for any variables and click "Insert" to have the Snippet inserted. In the example shown in Figure 5, the source member consists of a /Free directive. You position the cursor on the next line and double-click on the "Do While File Loop" Snippet and change the value of the "FileName" variable from "MyFile" to "Customer." When you click "Insert the Do While" loop for a sequential read, the "Customer" file is inserted in the code.


Figure 5. Using a Snippet


It's a Snip

There you have it. Snippets are a very useful feature when it comes to defining any type of "standard" code with variable information that needs to be changed when you use it. There is also the added benefit that Snippets may be used for standard specification types as well as free form.

It's time to start building that useful library of snippets.


RELATED STORY

Two Views on the WDSc Snippets View, Part 1



                     Post this story to del.icio.us
               Post this story to Digg
    Post this story to Slashdot


Sponsored By
WORKSRIGHT SOFTWARE

Do you need area code information?
Do you need ZIP Code information?
Do you need ZIP+4 information?
Do you need city name information?
Do you need county information?
Do you need a nearest dealer locator system?

We can HELP! We have affordable AS/400 software and data to do all of the above. Whether you need a simple city name retrieval system or a sophisticated CASS postal coding system, we have it for you!

The ZIP/CITY system is based on 5-digit ZIP Codes. You can retrieve city names, state names, county names, area codes, time zones, latitude, longitude, and more just by knowing the ZIP Code. We supply information on all the latest area code changes. A nearest dealer locator function is also included. ZIP/CITY includes software, data, monthly updates, and unlimited support. The cost is $495 per year.

PER/ZIP4 is a sophisticated CASS certified postal coding system for assigning ZIP Codes, ZIP+4, carrier route, and delivery point codes. PER/ZIP4 also provides county names and FIPS codes. PER/ZIP4 can be used interactively, in batch, and with callable programs. PER/ZIP4 includes software, data, monthly updates, and unlimited support. The cost is $3,900 for the first year, and $1,950 for renewal.

Just call us and we'll arrange for 30 days FREE use of either
ZIP/CITY or PER/ZIP4.

WorksRight Software, Inc.
Phone: 601-856-8337
Fax: 601-856-9432
E-mail: software@worksright.com
Web site: www.worksright.com


Senior Technical Editor: Ted Holt
Technical Editors: Howard Arner, Joe Hertvik, Shannon O'Donnell, Kevin Vandever
Contributing Technical Editors: Joel Cochran, Wayne O. Evans, Raymond Everhart,
Bruce Guetzkow, Brian Kelly, Marc Logemann, David Morris
Publisher and Advertising Director: Jenny Thomas
Advertising Sales Representative: Kim Reed
Contact the Editors: To contact anyone on the IT Jungle Team
Go to our contacts page and send us a message.

Sponsored Links

COMMON:  Join us at the annual 2008 conference, March 30 - April 3, in Nashville, Tennessee
looksoftware:  Stop recoding with end-to-end modernization solutions
NowWhatJobs.net:  NowWhatJobs.net is the resource for job transitions after age 40


 

IT Jungle Store Top Book Picks

The System i Pocket RPG & RPG IV Guide: List Price, $69.95
The iSeries Pocket Database Guide: List Price, $59.00
The iSeries Pocket Developers' Guide: List Price, $59.00
The iSeries Pocket SQL Guide: List Price, $59.00
The iSeries Pocket Query Guide: List Price, $49.00
The iSeries Pocket WebFacing Primer: List Price, $39.00
Migrating to WebSphere Express for iSeries: List Price, $49.00
iSeries Express Web Implementer's Guide: List Price, $59.00
Getting Started with WebSphere Development Studio for iSeries: List Price, $79.95
Getting Started With WebSphere Development Studio Client for iSeries: List Price, $89.00
Getting Started with WebSphere Express for iSeries: List Price, $49.00
WebFacing Application Design and Development Guide: List Price, $55.00
Can the AS/400 Survive IBM?: List Price, $49.00
The All-Everything Machine: List Price, $29.95
Chip Wars: List Price, $29.95


 
The Four Hundred
SAP Plants Its Flag in Mid-Market Territory with SaaS Apps

A1S Is to Applications What AS/400 Was to Systems

EGL: At Least It's Not Java, But It Ain't RPG, Either

As I See It: Shocking

The Linux Beacon
Canonical, VMware Create Skinny Linux for Virtual Appliances

HP Engineers New Blade Server Box for SMB Shops

SCO Files for Bankruptcy Protection

Transitive Rejiggers Emulation Software, Adds Partners

Four Hundred Stuff
Windows Vista Poses Challenges to Emulation Vendors

NetCustomer Capitalizes on Dissatisfaction with Oracle

Infor Provides Details on SOA Roadmap

Microsoft Ships BizTalk Server R2

Big Iron
Leverage

Top Mainframe Stories From Around the Web

Chats, Webinars, Seminars, Shows, and Other Happenings

System i PTF Guide
September 15, 2007: Volume 9, Number 37

September 8, 2007: Volume 9, Number 36

September 1, 2007: Volume 9, Number 35

August 25, 2007: Volume 9, Number 34

August 18, 2007: Volume 9, Number 33

August 11, 2007: Volume 9, Number 32

The Windows Observer
Microsoft Loses Antitrust Appeal in European Court

In Search Of a More Secure Internet

Sun and Microsoft Go All the Way with Windows

HP Engineers New Blade Server Box for SMB Shops

The Unix Guardian
SCO Files for Bankruptcy Protection

Sun and Microsoft Go All the Way with Windows

SAP Plants Its Flag in Mid-Market Territory with SaaS Apps

As I See It: The Dons of Dialogue

Four Hundred Monitor
Four Hundred Monitor's
Full iSeries Events Calendar

THIS ISSUE SPONSORED BY:

Help/Systems
WorksRight Software
COMMON


Printer Friendly Version


TABLE OF CONTENTS
Weird SQL UNION Results

A Snippet Above the Rest

Admin Alert: What Vendors Want to Know (and How to Get It)

Four Hundred Guru

BACK ISSUES

From the IT Jungle Forums
What's coalesce good for?

Duplicated printer files

Urgent Help Needed--Limit the result set in SQL stored procedure

Problem with "cpyfrmimpf"

FNDSTRPDM Output Member Name to *OUTFILE





 
Subscription Information:
You can unsubscribe, change your email address, or sign up for any of IT Jungle's free e-newsletters through our Web site at http://www.itjungle.com/sub/subscribe.html.

Copyright © 1996-2008 Guild Companies, Inc. All Rights Reserved.
Guild Companies, Inc., 50 Park Terrace East, Suite 8F, New York, NY 10034

Privacy Statement