• The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
Menu
  • The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
  • It’s My (De)fault That You’re a Zero

    July 21, 2010 Ted Holt

    Unless you say otherwise, numeric database fields have a value of zero and character fields are blank, right? Not necessarily. There’s more to default field values than some i Gurus realize.

    A field’s default value is the value the system assigns to the field when an application does not specify a value. Default values come into play in several situations.

    1. A record (row) is added to (inserted into) a physical file (table) by means of a logical file or SQL view that does not contain one or more fields.
    2. RPG O specs list the fields of an externally described file, but not all fields are listed.
    3. An SQL insert command does not include one or more fields in the list of columns.
    4. New fields are added to the DDS of a physical file and Change Physical File (CHGPF) is used to rebuild the file.
    5. The Initialize Physical File Member (INZPFM) command is used with the RECORDS(*DFT) parameter to add records to a database file.

    The default value of a field is based on three criteria:

    1. Whether the programmer specified a default value.
    2. Whether the physical file was created with DDS or SQL.
    3. The field’s data type.

    If you use an SQL command, such as CREATE TABLE, to create a new physical file, fields are null by default. If you use DDS, however, fields are only null-capable if you add the ALWNULL keyword.

    For non-nullable fields, default values are zero for numeric fields, blanks for character fields, and current values for date/time/timestamp fields. If you’re interested, here’s something to try. Create a physical file with fields of different data types:

    A          R DFTVALREC
    A            CHAR           3A 
    A            PACKED         7P 2
    A            ZONED          3S 0
    A            DATE            L
    A            TIME            T
    A            STAMP           Z
    

    Add one record to the file.

    INZPFM FILE(SOMEFILE) RECORDS(*DFT) TOTRCDS(1)
    

    Query the file to see the values in the record. Those are the default values.

    ....+....1....+....2....+....3....+....4....+....5....+....6....+....7...
    CHAR     PACKED   ZONED  DATE        TIME      STAMP
                .00      0   2010-07-21  07.38.59  2010-07-21-07.38.59.766261
    

    To assign your own default values, use the DFT keyword in DDS and WITH DEFAULT in SQL.

    A          R DFTVALREC
    A            CHAR           3A         DFT('ABC')
    A            PACKED         7P 2       DFT(250)
    A            ZONED          3S 0       DFT(-1)
    A            DATE            L         DFT('2000-01-01')
    A            TIME            T         DFT('00.00.00')
    A            STAMP           Z         DFT('2000-12-31-24.00.00')
    

    create table somefile
      (  KeyField    dec  (5,0),
         CharField   char (3)   with default 'XYZ',
         PackedField dec  (7,2) with default 1.5)
    

    In addition to literal values, SQL lets you insert special values:

    • USER (the current user profile)
    • CURRENT_DATE
    • CURRENT_TIME
    • CURRENT_TIMESTAMP

    And if you want the default value to be null, you can make it happen, whether you use DDS or SQL.

    Make it a habit to think about default values when you create new physical files (or SQL tables). For instance, shouldn’t a sales order be a regular order by default, rather than a special order?



                         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
    ARCAD Software

    Embrace VS Code for IBM i Development

    The IBM i development landscape is evolving with modern tools that enhance efficiency and collaboration. Ready to make the move to VS Code for IBM i?

    Join us for this webinar where we’ll showcase how VS Code can serve as a powerful editor for native IBM i code and explore the essential extensions that make it possible.

    In this session, you’ll discover:

    • How ARCAD’s integration with VS Code provides deep metadata insights, allowing developers to assess the impact of their changes upfront.
    • The role of Git in enabling seamless collaboration between developers using tools like SEU, RDi, and VS Code.
    • Powerful extensions for code quality, security, impact analysis, smart build, and automated RPG conversion to Free Form.
    • How non-IBM i developers can now contribute to IBM i projects without prior knowledge of its specifics, while ensuring full control over their changes.

    The future of IBM i development is here. Let ARCAD be your guide!

    Register now!

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    Sponsored Links

    Help/Systems:  Drive your enterprise with event-driven scheduling. FREE white paper!
    PowerTech:  FREE Webinar! An Auditor's View: Assess Your IBM i in 15 Minutes. July 28, 10 a.m. CT
    COMMON:  Join us at the Fall 2010 Conference & Expo, Oct. 4 - 6, in San Antonio, Texas

    IT Jungle Store Top Book Picks

    Easy Steps to Internet Programming for AS/400, iSeries, and System i: List Price, $49.95
    The iSeries Express Web Implementer's Guide: List Price, $49.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 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
    Getting Started With WebSphere Development Studio Client for iSeries: List Price, $89.00
    Getting Started with WebSphere Express for iSeries: List Price, $49.00
    Can the AS/400 Survive IBM?: List Price, $49.00
    Chip Wars: List Price, $29.95

    Crossroads Looks at the Source of Slow Tape Backups More Details on the Entry Power7 Rollout

    Leave a Reply Cancel reply

Volume 10, Number 22 -- July 21, 2010
THIS ISSUE SPONSORED BY:

WorksRight Software
System i Developer
RJS Software Systems

Table of Contents

  • AAA Secures IBM i Server
  • It’s My (De)fault That You’re a Zero
  • Admin Alert: The Poor Manager’s 5250 Single Sign-On

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