fhg
Volume 8, Number 43 -- December 17, 2008

End-of-Year Odds and Ends

Published: December 17, 2008

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


Sponsored By
PRODATA COMPUTER SERVICES

Don't Break the Bank,
We Can Keep You Rolling!

Select any of our productivity tools and ask to finance thru our Lease-to-Own Plan.

Lease-to-Own RDB Connect or DBU, database and connectivity utilities
over a three year period for only a few dollars a day.
No risks, no hassles, no problems.

Download your FREE 30 day trial today!

800.228.6318
sales@prodatacomputer.com
www.prodatacomputer.com


Senior Technical Editor: Ted Holt
Technical Editor: Joe Hertvik
Contributing Technical Editors: Edwin Earley, Brian Kelly, Michael Sansoterra
Publisher and Advertising Director: Jenny Thomas
Advertising Sales Representative: Kim Reed
Contact the Editors: To contact anyone on the IT Jungle Team
Go to our contacts page and send us a message.

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


 
The Four Hundred
IBM Adds Disk Storage Options for i Shops

Seasons Greetings, Happy Holidays, and Thank Heavens We All Made It

Forrester: Brace Yourself for Slow IT Growth

As I See It: The Swami Speaks

Micro Focus Snatches Relativity, Expands App Modernization

The Linux Beacon
Why Blade Servers Still Don't Cut It, and How They Might

Intel Keeps Both Arms Swinging with Xeons, Jabs with Itanium

Microsoft Ponies Up Another $100 Million for Novell Linux

Mad Dog 21/21: Newtonian Economics

Two More Xeon-Based Galaxy Servers from Sun

Four Hundred Stuff
IBM Adds 'Rich UI' Design Tool to Rational Business Developer

Original Bolsters Support for Java, Mainframe in Testing Tool

Development Horror Stories Surface as Aldon Unveils Turkey Award Winners

Tick, Tock: mrc Unveils '24-Hour Challenge'

IBM Gives RPG Devotees Their Own Café

Big Iron
For Some Customers, the Mainframe Is Green

Top Mainframe Stories From Around the Web

Chats, Webinars, Seminars, Shows, and Other Happenings

System i PTF Guide
December 13, 2008: Volume 10, Number 50

December 6, 2008: Volume 10, Number 49

November 29, 2008: Volume 10, Number 48

November 22, 2008: Volume 10, Number 47

November 15, 2008: Volume 10, Number 46

November 8, 2008: Volume 10, Number 45

The Windows Observer
Citrix Addresses Performance with XenApp 5

Server Buyers Shop Like It's 1999 in the Second Quarter

Intel Keeps Both Arms Swinging with Xeons, Jabs with Itanium

Mad Dog 21/21: Newtonian Economics

Microsoft Does Something About Those SQL Injection Attacks

The Unix Guardian
What the Heck Is the Midrange, Anyway?

Overseas and Notebook Sales Offset Printer Declines for HP in Q3

Two More Xeon-Based Galaxy Servers from Sun

Mad Dog 21/21: Newtonian Economics

Intel's Nehalems to Star at IDF, AMD Pitches Shanghai

Four Hundred Monitor
Four Hundred Monitor's
Full iSeries Events Calendar

THIS ISSUE SPONSORED BY:

Help/Systems
ProData Computer Services
Group8 Security


Printer Friendly Version


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

Four Hundred Guru

BACK ISSUES

From the IT Jungle Forums
Insert via Java

iSeries Access for Web

Mimix installation and configuration docs

EDI Inovis Programmer - Heavy Duty Problem Solver - Anytime

Data Queues vs. MQ Series: Performance

Removing blanks from a CL Variable

XML





 
Subscription Information:
You can unsubscribe, change your email address, or sign up for any of IT Jungle's free e-newsletters through our Web site at http://www.itjungle.com/sub/subscribe.html.

Copyright © 1996-2008 Guild Companies, Inc. All Rights Reserved.
Guild Companies, Inc., 50 Park Terrace East, Suite 8F, New York, NY 10034

Privacy Statement