• The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
Menu
  • The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
  • Two Views on the WDSc Snippets View, Part 1

    March 28, 2007 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

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    Tags:

    Sponsored by
    Computer Keyes

    Fax Directly from your IBM i

    KeyesFax is a full function automated IBM i fax system. Spooled files are burst by fax number and auto transmitted with overlays.  It combines both a send and receive facsimile processing system with a complete image package.

    The fax software will edit, send, receive, display, print, and track fax documents or images using any standard IBM i without additional expensive hardware, software or subscriptions.

    Computer Keyes has been developing Software Solutions since 1978!

    www.computerkeyes.com

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    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

    Informatica Tackles SaaS Data Integration Issues with SaaS Offering Next Up on the System i5: Native GNU g++ and IBM XL C/C++

    Leave a Reply Cancel reply

Volume 7, Number 12 -- March 28, 2007
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)

Content archive

  • The Four Hundred
  • Four Hundred Stuff
  • Four Hundred Guru

Recent Posts

  • IBM Unveils Manzan, A New Open Source Event Monitor For IBM i
  • Say Goodbye To Downtime: Update Your Database Without Taking Your Business Offline
  • i-Rays Brings Observability To IBM i Performance Problems
  • Another Non-TR “Technology Refresh” Happens With IBM i TR6
  • IBM i PTF Guide, Volume 27, Number 18
  • Will The Turbulent Economy Downdraft IBM Systems Or Lift It?
  • How IBM Improved The Database With IBM i 7.6
  • Rocket Celebrates 35th Anniversary As Private Equity Owner Ponders Sale
  • 50 Acres And A Humanoid Robot With An AI Avatar
  • IBM i PTF Guide, Volume 27, Number 17

Subscribe

To get news from IT Jungle sent to your inbox every week, subscribe to our newsletter.

Pages

  • About Us
  • Contact
  • Contributors
  • Four Hundred Monitor
  • IBM i PTF Guide
  • Media Kit
  • Subscribe

Search

Copyright © 2025 IT Jungle