• 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
    DRV Tech

    Get More Out of Your IBM i

    With soaring costs, operational data is more critical than ever. IBM shops need faster, easier ways to distribute IBM applications-based data to users more efficiently, no matter where they are.

    The Problem:

    For Users, IBM Data Can Be Difficult to Get To

    IBM Applications generate reports as spooled files, originally designed to be printed. Often those reports are packed together with so much data it makes them difficult to read. Add to that hardcopy is a pain to distribute. User-friendly formats like Excel and PDF are better, offering sorting, searching, and easy portability but getting IBM reports into these formats can be tricky without the right tools.

    The Solution:

    IBM i Reports can easily be converted to easy to read and share formats like Excel and PDF and Delivered by Email

    Converting IBM i, iSeries, and AS400 reports into Excel and PDF is now a lot easier with SpoolFlex software by DRV Tech.  If you or your users are still doing this manually, think how much time is wasted dragging and reformatting to make a report readable. How much time would be saved if they were automatically formatted correctly and delivered to one or multiple recipients.

    SpoolFlex converts spooled files to Excel and PDF, automatically emailing them, and saving copies to network shared folders. SpoolFlex converts complex reports to Excel, removing unwanted headers, splitting large reports out for individual recipients, and delivering to users whether they are at the office or working from home.

    Watch our 2-minute video and see DRV’s powerful SpoolFlex software can solve your file conversion challenges.

    Watch Video

    DRV Tech

    www.drvtech.com

    866.378.3366

    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

  • The Power11 Transistor Count Discrepancies Explained – Sort Of
  • Is Your IBM i HA/DR Actually Tested – Or Just Installed?
  • Big Blue Delivers IBM i Customer Requests In ACS Update
  • New DbToo SDK Hooks RPG And Db2 For i To External Services
  • IBM i PTF Guide, Volume 27, Number 33
  • Tool Aims To Streamline Git Integration For Old School IBM i Devs
  • IBM To Add Full System Replication And FlashCopy To PowerHA
  • Guru: Decoding Base64 ASCII
  • The Price Tweaking Continues For Power Systems
  • IBM i PTF Guide, Volume 27, Numbers 31 And 32

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