fhg
Volume 7, Number 12 -- March 28, 2007

Two Views on the WDSc Snippets View, Part 1

Published: March 28, 2007

by Bruce Guetzkow

Developers usually don't like to reinvent the wheel. If we or a co-worker have programmed a task in one source member, it is common to copy that code into another source member when a similar task needs to be done. If you are using WebSphere Development Studio Client (WDSc), there is another option: the Snippets View. Code snippets can be saved and easily inserted into any source member with a simple double-click of the mouse.

A First Look

The Snippets View is typically not displayed in the Remote Systems Explorer (RSE) perspective. If you don't see a tab labeled Snippets, you can open the view from the menu by selecting Window --> Show View --> Other. From the resulting list expand Basic then select Snippets. What you see in the Snippets View is a series of grey horizontal bars with various labels and a white background with text and/or icons.

The gray bars are called drawers and are labeled to identify their contents. The text/icons represent individual code snippet references. The purpose of the drawers is to organize code snippets into logical collections. Often snippets are organized by the language they are written in, but there is no restriction on how you organize them. For example you could have a Subfile drawer containing a DDS fragment for the display file code, and RPGLE subprocedures to load and display the subfile.

To maintain drawers and snippets, start by moving your mouse over any drawer or snippet and right-click. From the context menu, select Customize. . . This will open a pop-up window labeled Customize Palette. If you select a drawer you will see a set of options on the right side of the panel where you can:

  • Maintain the name and description
  • Indicate whether the drawer should be open at start-up and, if so if it is to be pinned open
  • Indicate whether the drawer should be displayed in the view

In the initial list you may see some drawers labeled EGL, JSP, XSL, etc. If you have no need for some of these, you can select the Always hide radio button and they will no longer appear in the view.

Rolling Your Own

To create a drawer of your own click on New on the menu bar. A drop-down menu will appear. Select the option New Category. It would be nice if the terminology was consistent, but for some reason it changes here. Just remember that Category means drawer and Item means snippet. After selecting New Category you will have a new drawer labeled Unnamed Category. You can now change the values on the right side of the panel as you see fit.

Now it's time to create your first snippet. The easiest way to do this is to first exit the Palette by clicking OK. Next open a source member in the LPEX editor containing code that you'd like to create a snippet from. Select and copy the code (we'll paste it later). Now, open the Palette again by right-clicking in the Snippet View and selecting Customize. . .


(Click here to see a larger image)

Create the snippet by clicking on "New", then select New Item. This creates a snippet labeled Unnamed Template. Again the terminology is inconsistent. You can again easily change the values on the right side of the Palette. For now, skip the Variables section. Place your cursor into the Template Pattern area and use the standard Windows keys to paste your copied source into the window: Control-v. You can edit the code directly in the Template Pattern window if needed. Make the snippet available by clicking on Apply or OK.


(Click here to see a larger image)

Of course, it's rare that code can be copied from one source member to another without making some changes. For example, a "subfile load" routine probably needs to specify a unique subfile record format and relative record number for each use. If these values appear more than once in the snippet it is typically up to you to remember to change all occurrences of those values. With snippets there is an easier way to handle variable values.

Variables

You can specify Variables that can be inserted into your snippet. When inserting the snippet into your code you will be prompted for the values to use for the current instance. You can also define a variable and use it multiple times in a snippet. In the subfile example I mentioned earlier, if the subfile record format name is used multiple times in the routine, you can define a single variable but insert it into the snippet at all appropriate locations. When you insert the snippet you will be asked to supply the subfile record format once, but it will be substituted in each location.

To create a variable, click on the New button to the right of the Variables area. A new entry will be added to the table. Simply update the name, description and (optionally) default value. To insert it into the snippet code, find the location where it will be placed. Select and delete the current code, then click Insert Variable Placeholder. . . This will display a list of the variables. Click on the variable you want to insert.

Insert a variable named "sflrcdfmt" and you will see the snippet code change to include the value $(sflrcdfmt). Depending on the amount of code you are replacing and the length of the variable name, you will most likely see the format of the source line shift to accommodate the variable name. When the snippet is inserted into a source member the number of characters that you enter when prompted will replace the entire variable string. If the snippet is an "F" spec and the variable is for a file name, you should always enter exactly 10 characters or the resulting insert of the snippet will not be properly formatted.

When I create variables I always include the length of text as part of the variable name or description as a reminder (filename10) if the snippet is for fixed-length code. That way if I have a file name of only 7 characters I will remember to pad the value with 3 blanks for a total length of 10 characters.

You may use as many variables as you like with each snippet and use each variable as many times as you like in a snippet.

Inserting a Snippet

As I mentioned at the start of this article, snippets are inserted into a source member very easily. While editing a source member in the LPEX editor, place your cursor at the location where you want the snippet inserted. Double-click on the desired snippet. If variables are used in the snippet, you will be prompted to supply values. The modified snippet will then be inserted before your cursor location.

There is one quirk that you should be aware of. Sometimes, after saving a snippet, you may find that blank lines have been inserted after every line in your snippet code, effectively doubling the size of the snippet. If you find that this has happened to your snippet, simply return to the Template Pattern window and delete the blank lines. What is really curious is that this seems to only happen at most once per snippet. Once it has been corrected it doesn't happen again. I have not determined the sequence of steps that causes this so I can't tell you what to avoid. Just remember to review your snippets before you use them for the first time.

While it is still possible to find a piece of code to duplicate in another source member, having the Snippets View means that once I create a useful snippet of code I no longer need to search through the entire source library for common tasks. Snippets View is a great time saver.



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


Sponsored By
PRODATA COMPUTER SERVICES

DBU - Burning Love!

DBU, the "original" database utility, inspires burning love!
With over 20,000 installs of DBU in 31 countries,
it is the leading database utility.

Being without DBU has been compared to
being naked in a crowd...you don't know
what to do or which way to go!

Enter the DBU Challenge for
your chance to win $1,000!

ProData Computer Services
800.228.6318
www.DoDBU.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

Help/Systems:  SEQUEL is the single solution for all your business intelligence needs
COMMON:  Join us at the 2007 conference, April 29 – May 3, in Anaheim, California
Bug Busters Software Engineering:  Quality software solutions for the iSeries since 1988


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
IBM to Meet Upset WDSc Shops Half-Way on Features?

Oracle Sues SAP Over 'Corporate Theft on a Grand Scale'

IDC Chops Server Forecasts Thanks to Virtualization, Multicore Chips

As I See It: Workplace Heaven

The Linux Beacon
Novell Previews SLES 10 Service Pack 1, OES 2 Extensions

IDC Chops Server Forecasts Thanks to Virtualization, Multicore Chips

Supermicro Shows Off Blades, Posts Financials Ahead of IPO

NEC, Stratus Preview Fault Tolerant Server with Quad Cores

Four Hundred Stuff
IBM and 3Com Unveil New Collaboration Solution for System i

Centerfield Aims to Ease iSeries SQL Management with AutoDBA

MaxAv Updates System i High Availability Software

NGS Boosts BI Offerings for System i

Big Iron
IDC Chops Server Forecasts Thanks to Virtualization, Multicore Chips

Top Mainframe Stories From Around the Web

Chats, Webinars, Seminars, Shows, and Other Happenings

System i PTF Guide
March 24, 2007: Volume 9, Number 12

March 17, 2007: Volume 9, Number 11

March 10, 2007: Volume 9, Number 10

March 3, 2007: Volume 9, Number 9

February 24, 2007: Volume 9, Number 8

February 17, 2007: Volume 9, Number 7

The Windows Observer
IDC Chops Server Forecasts Thanks to Virtualization, Multicore Chips

Microsoft Looks to Boost Voice Strategy with TellMe Buy

Disaster Recovery in a Truck Unveiled by IBM, Cisco

Gateway Adds Entry Opteron Tower Server, Windows NAS Arrays

The Unix Guardian
Sun Taps Linux Guru to Guide Operating System Strategy

IBM's Plan for an Adjacent, Custom Systems Market

IDC Chops Server Forecasts Thanks to Virtualization, Multicore Chips

Mad Dog 21/21: The China Spin Drone

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

THIS ISSUE SPONSORED BY:

ProData Computer Services
Vision Solutions
COMMON



TABLE OF CONTENTS
Two Views on the WDSc Snippets View, Part 1

The Case of the Missing Outline (View)

Admin Alert: Five Things that Kill Backups (and What to Do About Them)

Four Hundred Guru

BACK ISSUES

From the IT Jungle Forums
Problem with Workstation/Subsystem association

Three header line XLS output

Immediate need for a experienced CGIDEV2 programmer

Using QSH with a command string more than 80 chars

WebSphere Remote System Explorer Connection Problems





 
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