• The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
Menu
  • The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
  • A Snippet Above the Rest

    September 26, 2007 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

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    Tags:

    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
    Email: software@worksright.com
    Website: www.worksright.com

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    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

    B&L Releases Cost Estimating Wizard State of the System i: What’s Going On in the Market?

    Leave a Reply Cancel reply

Volume 7, Number 33 -- September 26, 2007
THIS ISSUE SPONSORED BY:

Help/Systems
WorksRight Software
COMMON

Table of Contents

  • Weird SQL UNION Results
  • A Snippet Above the Rest
  • Admin Alert: What Vendors Want to Know (and How to Get It)

Content archive

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

Recent Posts

  • Public Preview For Watson Code Assistant for i Available Soon
  • COMMON Youth Movement Continues at POWERUp 2025
  • IBM Preserves Memory Investments Across Power10 And Power11
  • Eradani Uses AI For New EDI And API Service
  • Picking Apart IBM’s $150 Billion In US Manufacturing And R&D
  • FAX/400 And CICS For i Are Dead. What Will IBM Kill Next?
  • Fresche Overhauls X-Analysis With Web UI, AI Smarts
  • Is It Time To Add The Rust Programming Language To IBM i?
  • Is IBM Going To Raise Prices On Power10 Expert Care?
  • IBM i PTF Guide, Volume 27, Number 20

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