• The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
Menu
  • The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
  • Asserting the Ostensibly Unassertable

    May 25, 2011 Hey, Ted

    Assertions are great for validating conditions that can be tested with IF, DOW, SELECT, etc., but what about other types of conditions? For instance, can I use an assertion to test that a variable contains valid decimal data?

    –A Nice Lady

    (I’m sorry. A nice lady asked me this question in person and I forgot her name.)

    Yes, it is possible to check for conditions that one cannot test with conditional OPCODES such as IF, but you must use a different method.

    When something goes amiss, the system loads a five-digit, zoned-decimal status code with a non-zero value. You can access this status through file and program status data structures, but that is so 20th century. The modern way is to use the %STATUS built-in function. The status for invalid decimal data is 907. You can find a complete list of status codes in the RPG reference manual.

    Here’s one possibility:

    H dftactgrp(*no) actgrp(*new)
    H bnddir('TOOLKITBD')
    
    D AGoodPgm        pr                  extpgm('AGOODPGM')
    D  inDecNbr                      5p 0
    D AGoodPgm        pi
    D  inDecNbr                      5p 0
    
    D DecNbr          s                   like(inDecNbr)
    D Status          s              5s 0
    
     /copy prototypes,assert
     /copy qrpglesrc,psds
    
     /free
         *inlr = *on;
         monitor;
            DecNbr = inDecNbr;
         on-error;
            Status = %status;
         endmon;
         assert (Status = *zero:
                 %trimr(psdsProcName) +
                    ' canceled with status ' +
                    %editc(Status: 'X'));
         return;
    

    Here’s another method with more specific error handling:

        monitor;
           DecNbr = inDecNbr;
        on-error 907;
           assert (*off: 'Parameter inDecNbr has invalid decimal data');
        on-error;
           Status = %status;
           assert (*off: %trimr(psdsProcName) +
                         ' canceled with status ' +
                         %editc(Status: 'X'));
        endmon;
    

    In each case, the assertion will fail, immediately halting the program, if the inDecNbr parameter does not contain valid decimal data.

    –Ted

    RELATED STORY

    Programming with Assertions



                         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

    VAULT400:  Take a 14-question Disaster Recovery Survey, 4 will win $50 Visa gift card
    SEQUEL Software:  View the recorded Webinar: 10 Ways SEQUEL Makes Developers More Productive
    looksoftware:  FREE Webcast: RPG Open Access Demystified. June 7 (Europe) & June 8 (USA)

    IT Jungle Store Top Book Picks

    BACK IN STOCK: Easy Steps to Internet Programming for System i: List Price, $49.95

    The iSeries Express Web Implementer's Guide: List Price, $49.95
    The iSeries Pocket Database Guide: List Price, $59
    The iSeries Pocket SQL Guide: List Price, $59
    The iSeries Pocket WebFacing Primer: List Price, $39
    Migrating to WebSphere Express for iSeries: List Price, $49
    Getting Started with WebSphere Express for iSeries: List Price, $49
    The All-Everything Operating System: List Price, $35
    The Best Joomla! Tutorial Ever!: List Price, $19.95

    ASCI Job Scheduler Gets Hooks for Nagios I, Cloud-i-us

    Leave a Reply Cancel reply

Volume 11, Number 17 -- May 25, 2011
THIS ISSUE SPONSORED BY:

WorksRight Software
SEQUEL Software
VAULT400

Table of Contents

  • Finding Duplicate Rows in a Name and Address Table
  • Asserting the Ostensibly Unassertable
  • Admin Alert: Other Options for a Post-Upgrade Backup

Content archive

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

Recent Posts

  • Liam Allan Shares What’s Coming Next With Code For IBM i
  • From Stable To Scalable: Visual LANSA 16 Powers IBM i Growth – Launching July 8
  • VS Code Will Be The Heart Of The Modern IBM i Platform
  • The AS/400: A 37-Year-Old Dog That Loves To Learn New Tricks
  • IBM i PTF Guide, Volume 27, Number 25
  • 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

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