• The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
Menu
  • The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
  • Easily Avoid a Common Data Structure Error

    February 25, 2009 Ted Holt

    A shop with which I’m acquainted had an undesirable experience recently. A program that, to my understanding, had been working properly, ended abnormally. The error could have easily been avoided, had the programmer followed one simple rule of thumb.

    Take a look at the following program fragment.

    D MyData          ds                 
    D  OneField                      4a  
    D  TwoField                      7p 0
    D  RedField                      3s 0
    D  BlueField                     5u 0
    D                                    
    D Number          s             15p 5
                                         
     /free                               
         Number = TwoField;              
    

    If the calculation is the first executable statement in the program, what is the new value of Number? The answer is that Number never gets a new value. TwoField has an initial value of hexadecimal 40404040, which is not a valid packed decimal value. The program receives message MCH1202 and that’s the end of that.

    Suppose the first executable statement is this one:

         Number = BlueField;
    

    What’s the value of Number after this assignment? That’s right! Sixteen thousand, four hundred forty-eight, the decimal equivalent of hex 4040. In this case, the program runs, but has a logic error.

    Such errors won’t occur if you habitually initialize data structures. That is, add the INZ keyword to the first line.

    D MyData          ds                  inz
    

    The best way to debug a program is not to put bugs into it in the first place. Little rules of thumb, like “always initialize data structures,” move you toward that goal.



                         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
    New Generation Software

    Attend the SUMMIT Lunch & Learn Series

    Register today for any of the nine free, online educational sessions offered March 14-30, 2023. Learn from the Summit’s IBM i experts and top independent software vendors.

    NGS recommends “RPG Arrays for Today” with Jon Paris and “Modernizing IBM i? Let’s Take Another Look at Data Access,” March 29, 2023.

    NGS-IQ affordably brings IBM i query and analytics to Windows, Web, and 5250 users.

    Ask about our QDK and subscription offers.

    www.ngsi.com – 800-824-1220

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    Sponsored Links

    WMCPA:  24rd Annual Spring Technical Conference, April 1 & 2, 2009, Delavan, WI
    COMMON:  Join us at the 2009 annual meeting and expo, April 26-30, Reno, Nevada
    Vision Solutions:  Learn About Data Integration for Business Intelligence

    IT Jungle Store Top Book Picks

    Easy Steps to Internet Programming for AS/400, iSeries, and System i: List Price, $49.95
    Getting Started with PHP for i5/OS: List Price, $59.95
    The System i RPG & RPG IV Tutorial and Lab Exercises: List Price, $59.95
    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

    New InfoPrint 5000 Printers Unveiled IBM Adds i Shops to Expanded p Shop Trade-In Deal

    Leave a Reply Cancel reply

Volume 9, Number 7 -- February 25, 2009
THIS ISSUE SPONSORED BY:

Profound Logic Software
WorksRight Software
Northeast User Groups Conference

Table of Contents

  • A Bevy of BIFs: %SCAN and %CHECK
  • Easily Avoid a Common Data Structure Error
  • Admin Alert: Robot/SCHEDULE’s DST Work-Around and More

Content archive

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

Recent Posts

  • IBM i Has a Future ‘If Kept Up To Date,’ IDC Says
  • When You Need Us, We Are Ready To Do Grunt Work
  • Generative AI: Coming to an ERP Near You
  • Four Hundred Monitor, March 22
  • IBM i PTF Guide, Volume 25, Number 12
  • Unattended IBM i Operations Continue Upward Climb
  • VS Code Is The Full Stack IDE For IBM i
  • Domino Runs on IBM i 7.5, But HCL Still Working on Power10
  • Four Hundred Monitor, March 6
  • IBM i PTF Guide, Volume 25, Number 11

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 © 2023 IT Jungle