• 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
    Maxava

    Migrate IBM i with Confidence

    Tired of costly and risky migrations? Maxava Migrate Live minimizes disruption with seamless transitions. Upgrading to Power10 or cloud hosted system, Maxava has you covered!

    Learn More

    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

  • Meet The Next Gen Of IBMers Helping To Build IBM i
  • Looks Like IBM Is Building A Linux-Like PASE For IBM i After All
  • Will Independent IBM i Clouds Survive PowerVS?
  • Now, IBM Is Jacking Up Hardware Maintenance Prices
  • IBM i PTF Guide, Volume 27, Number 24
  • Big Blue Raises IBM i License Transfer Fees, Other Prices
  • Keep The IBM i Youth Movement Going With More Training, Better Tools
  • Remain Begins Migrating DevOps Tools To VS Code
  • IBM Readies LTO-10 Tape Drives And Libraries
  • IBM i PTF Guide, Volume 27, Number 23

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