• The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
Menu
  • The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
  • End-of-Year Odds and Ends

    December 17, 2008 Timothy Prickett Morgan

    Merry Christmas, intelligent i professional! Let’s end the year with a few little tips, including two unusual ways to use OPNQRYF’s %ABSVAL function from reader Victor Pisman. May 2009 be the best year ever for all of us.

    –Ted

    Run Qshell from CL Procedures

    Q: Do you have a simple example of using Qshell with a script? I think I can muddle through setting up the script. I am unsure of how to call it from a CL procedure.

    A: You can use the dot utility to run a script that you’ve created in the IFS. This command runs the IFS file MyScript.sh.

    SBMJOB CMD(QSH CMD('. MyScript.sh')) JOB(MYJOB) JOBQ(SOMEJOBQ)
    

    Or you can put the script into a CL variable and execute it from there, like this:

          chgvar  &Script +  
            (+               
            'cd' *bcat &CurDir *bcat '|| exit 1; + 
             [[ -d text ]] || exit 3; + 
             [[ -d archive ]] || exit 5; +
             ... more script lines omitted in this example ...
             ')
          qsh cmd(&Script)
    

    Please Find My Message

    Q: How can I search through the descriptions in a message file without manually looking at all the messages?

    A: Print the message descriptions.

    DSPMSGD RANGE(*FIRST *LAST) MSGF(MYMSGF) DETAIL(*BASIC) OUTPUT(*PRINT)
    

    Then look at the spool file and search.

    Everything Is Oojah-cum-spiff

    Q: How do I display a message to a user at the bottom of the screen after a CL program has completed?

    A: Use SNDPGMMSG to send a completion message.

    sndpgmmsg  msgid(cpf9898) msgf(qcpfmsg) msgtype(*comp) +
                  msgdta('Program' *bcat &PgmName *bcat +
                         'completed normally')
    

    Notice the message type is *COMP, for completion.

    DATFMT Error in SQL

    Q: I am having a problem with date data type fields in my files. If the date fields are the default “0001-01-01”, SQL gives me a mapping error. If I put the DATFMT(*ISO) keyword on the HSPEC, it still doesn’t fix the problem. I have to prompt the compile and change the CRTSQLRPGI DATFMT to be *ISO to fix the problem. Have you had this problem?

    A: The compiler wants to use the default *MDY format, which only accepts dates from 1940-2039. Prompting and changing the format makes it use *ISO format instead. If you don’t want to have to prompt, put the compiler option in your source code.

    exec sql set option datfmt=*iso;
    

    Remember that options have to precede all other SQL commands in the program.

    You Can Look, But Don’t Touch!

    Q: I want to have users be able to view a job queue to see that their program is running or waiting to run. I don’t want them to be able to change any attributes or have access to the command line. Is this possible?

    A: Revoke authority to commands ADDJOBQE, CHGJOBQE and RMVJOBQE.

    Use %ABSVAL to Avoid Division by Zero

    We know that division by zero is undefined. But sometimes we are faced with that possibility in real life. For example, a profit margin value is calculated by the following formula.

    Margin = (Price - Cost) / Price
    

    Normally if the price is zero, this formula cannot be used. But with %ABSVAL this formula can be used even if the price is zero. The following margin formula handles division by zero.

    Margin = (Price-Cost) / ((%ABSVAL (Price - 0.01)+Price+0.01)/2)
    

    For example, if price = 9.60 and cost = 7.20 the formula returns a margin of 25 percent.

    Margin = (9.60-7.20) / ((%ABSVAL (9.60-0.01)+9.60+0.01)/2) 
           = 2.40 / ((9.59 + 9.61)/2)
           = 2.40 / 9.60
           = 0.25.	
    

    When the price and the cost are zero, the margin is zero.

    Margin = (0-0) / ((%ABSVAL (0-0.01)+0+0.01)/2) = 0 / (0.01 + 0.01)/2
           = 0 / 0.01
           = 0 
    

    Here’s a CL example showing how the formula would be coded.

    OPNQRYF FILE ((PRR)) FORMAT (TESTF3) KEYFLD ((PRITNO)) + 
       MAPFLD ((FLD1 'PRICE - 0.01')  +       
               (FLD2 'PRICE + 0.01')   +                    
               (FLD3 '(%ABSVAL (FLD1)+(FLD2))*0.5')   +       
               (FLD4  '(PRICE - COST) * 100')   +  
               (MARGIN  'FLD4 / FLD3')) +
       OPNID (QRYFILE)                      
    

    Use %ABSVAL to Convert Negative Numbers to Zero

    The quantity available for purchase for an item is defined as the quantity on hand less the current customer requirements. If there are 100 units of an item on hand, and there are customer requirements for 80 of them, 20 are available. But if there are current requirements for 150, then the available quantity is 100-150, or -50.

    The negative values are equivalent to zero and needs to be converted to zero. The following is the formula to convert negative values to zero using %ABSVAL:

    Available =  (%ABSVAL (OnHand - Requirements) + OnHand - Requirements) / 2
    

    If OnHand is 100 and Requirements is 80, Available is 20.

    Available = (%ABSVAL (100 - 80) + 100 - 80) / 2
              = (20 + 20) / 2
              = 20
    

    And when OnHand is 100 and Requirements is 150, Available is zero.

    Available = (%ABSVAL (100 - 150) + 100 - 150) / 2
              = (50 - 50) / 2
              = 0
    

    The following CL demonstrates this formula:

    OPNQRYF FILE ((IBR)) FORMAT (TESTF1) KEYFLD ((ITEM)) +
       MAPFLD((FLD2 'ONHAND - REQ')  +   
              (FLD1 '(%ABSVAL(FLD2)+FLD2)*0.5')) 
    



                         Post this story to del.icio.us
                   Post this story to Digg
        Post this story to Slashdot

    Share this:

    • Share on Reddit (Opens in new window) Reddit
    • Share on Facebook (Opens in new window) Facebook
    • Share on LinkedIn (Opens in new window) LinkedIn
    • Share on X (Opens in new window) X
    • Email a link to a friend (Opens in new window) 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:

    • Share on Reddit (Opens in new window) Reddit
    • Share on Facebook (Opens in new window) Facebook
    • Share on LinkedIn (Opens in new window) LinkedIn
    • Share on X (Opens in new window) X
    • Email a link to a friend (Opens in new window) Email

    Sponsored Links

    PowerTech:  Incorporating real-time security events from the System i into a security program
    Safedata:  FREE White Paper - IBM iSeries Recovery Options: An Executive Guide
    COMMON:  Join us at the 2009 annual meeting and expo, April 26-30, Reno, Nevada

    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

    Two A-maze-ing Programs Admin Alert: Upcoming i5/OS and AnyNet End of Service Dates

    Leave a ReplyCancel reply

Volume 8, Number 43 -- December 17, 2008
THIS ISSUE SPONSORED BY:

Help/Systems
ProData Computer Services
Group8 Security

Table of Contents

  • Two A-maze-ing Programs
  • End-of-Year Odds and Ends
  • Admin Alert: Upcoming i5/OS and AnyNet End of Service Dates

Content archive

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

Recent Posts

  • More Power Systems Price Hikes, This Time They Are “Directional”
  • AI Is Not Just For Developers, It Is For Everyone At Your Company
  • Guru: Finding Data In The Forest – Exploring Three-Part Naming In SQL
  • Former IBMer’s New Book Puts The Midrange In The Spotlight
  • Have You Tried To Buy A Server Lately?
  • GenAI Is The Death Of Deterministic Project Budgeting
  • PTC Adds Support For VS Code With Implementer 12.7
  • Guru: Single Threading A Program Execution
  • As I See It: Push Back
  • IBM i PTF Guide, Volume 28, Number 21

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