• The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
Menu
  • The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
  • OPNQRYF Has No “If” But You Can Fake It

    November 5, 2008 Hey, Ted

    We recently started adding Web customers to our customer master file, in which a customer ID is a field of seven characters. The ID’s of Web customers consist of the letter “W” followed by six digits. Is there any way using OPNQRYF to change only the customer IDs that start with “W” to the customer number “5000000” for reporting purposes? Doing so would allow us to keep a lot of existing programs running without a lot of modification.

    –John

    OPNQRYF does not have conditional logic, John, but in your case, you can fake it out. Here’s the type of OPNQRYF command you need.

    OPNQRYF  FILE((SOMEFILE)) +                                    
       KEYFLD((CUSTNBR)) +                                          
       MAPFLD((WORK10  '%max((1/CustNbr *cat "2") "Z0000000")') +   
              (WORK20  '%sst(Work10 8 1) *cat %sst(Work10 1 7)') +  
              (WORK30  '%max(Work20 "15000000")') +                 
              (CUSTNBR '%sst(Work30 2 7)'))                         
    

    Now let me explain how it works.

    The first mapped field, WORK10, is the larger of two values–the customer number with a “2” appended to it, or the literal “Z00000000”. I chose this literal because the value of the first seven digits lies between the highest possible Web customer number–W9999999–and the lowest possible non-Web customer number–0000001. For Web customers, WORK10 is Z0000000. For non-Web customers, WORK10 is the customer number followed by a two.

    WORK20 reformats WORK10, moving the last digit to the front of the literal. Non-Web customers have their own ID’s with a prefix of “2”. Web customers have the value “0Z000000”.

    WORK30 takes the value 15000000 for Web customers and keeps the value of WORK20 for non-Web customers. The last seven digits of WORK30 are either the original customer number or 5000000.

    The only thing left to do is to extract the last seven digits into CUSTNBR.

    The following table summarizes the processing:

    Customer ID in database file

    Work10

    Work20

    Work30

    Mapped customer ID

    1234567

    12345672

    21234567

    21234567

    1234567

    W000020

    Z0000000

    0Z000000

    15000000

    5000000

    4509876

    45098762

    24509876

    24509876

    4509876

    9876543

    98765432

    29876543

    29876543

    9876543

    W870000

    Z0000000

    0Z000000

    15000000

    5000000

    Your program will use the value of the CUSTNBR mapped field, not the CUSTNBR from the database file. It’s not elegant, but maybe it will save you some work. Please let me know how it goes.

    –Ted

    Congratulations, it worked. However, it also changed customers that start with other letters to 5000000. You assumed that all non-Web customers had customer ID’s of seven digits. That is not the case. We begin customer ID’s with other letters as well. I only want to change the customer numbers that start with “W” to 5000000.

    –John

    Sorry, John. That’s not the first time I assumed something and goofed up as a result. I have good news, though. You can still convert only the “W” customers to 5000000.

    OPNQRYF FILE((WalshCust)) +
       KEYFLD((CUSTNBR)) +
       MAPFLD(+
        (WORK10 '%min((1/CustNbr  *cat 1/CustNbr *cat "2") +
                      ("W      "  *cat 1/CustNbr *cat "0"))') +
        (WORK20 '%max((%sst(Work10 8 7) *cat 1/CustNbr *cat %sst(Work10 15 1) +
                                    *cat "2") +
                    ("X      "          *cat 1/CustNbr *cat %sst(Work10 15 1) +
                                        *cat "0"))') +
          (WORK30 '%sst(Work20 15 2) *cat %sst(Work20 8 7)') +
          (WORK40 '%max(Work30 "015000000")') +
          (CUSTNBR '%sst(Work40 3 7)'))
    

    The first work field, WORK10, appends a “2” to records with customer ID’s below W and a zero to the records of W customers and above.

    Customer ID

    WORK10

    W123456

    W W1234560

    9876543

    W 98765430

    S222333

    S222333S2223332

    Z011011

    W Z0110110

    WORK20 appends a “2” to records for customers whose IDs start with the letter X or above.

    Customer ID

    WORK20

    W123456

    W123456W12345600

    9876543

    X 987654302

    S222333

    S222333S22233320

    Z011011

    X Z01101102

    WORK30 moves the two suffixes generated by the previous steps to the front and moves the customer ID to the end.

    Customer ID

    WORK30

    W123456

    00W123456

    9876543

    029876543

    S222333

    20S222333

    Z011011

    02Z011011

    WORK40 contains the customer number with its two prefix digits, or the special value 015000000, whichever is greater. This is the step that replaces “W” customers with the special value 5000000.

    Customer ID

    WORK40

    W123456

    015000000

    9876543

    029876543

    S222333

    20S222333

    Z011011

    02Z011011

    The last work field, CUSTNBR, extracts the customer number.

    Customer ID

    CUSTNBR

    W123456

    5000000

    9876543

    9876543

    S222333

    S222333

    Z011011

    Z011011

    –Ted

    Thanks for all your efforts, Ted. It works great!

    –John



                         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
    Midrange Dynamics North America

    With MDRapid, you can drastically reduce application downtime from hours to minutes. Deploying database changes quickly, even for multi-million and multi-billion record files, MDRapid is easy to integrate into day-to-day operations, allowing change and innovation to be continuous while reducing major business risks.

    Learn more.

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    Sponsored Links

    PowerTech:  Incorporating real-time security events from the System i into a security program
    Seagull Software:  Update your System i apps with LegaSuite GUI
    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

    Classic Software and System i Power World’s Largest Truck Stop A Few More Strands in the DNA of the Midrange

    Leave a Reply Cancel reply

Volume 8, Number 38 -- November 5, 2008
THIS ISSUE SPONSORED BY:

Help/Systems
WorksRight Software
Vision Solutions

Table of Contents

  • OPNQRYF Has No “If” But You Can Fake It
  • Embed PJL Statements in a Workstation Customizing Object
  • Admin Alert: Avoiding Restoration Problems with Remote Output Queues

Content archive

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

Recent Posts

  • 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
  • Big Blue Raises IBM i License Transfer Fees, Other Prices
  • Keep The IBM i Youth Movement Going With More Training, Better Tools
  • Remain Begins Migrating DevOps Tools To VS Code
  • IBM Readies LTO-10 Tape Drives And Libraries
  • IBM i PTF Guide, Volume 27, Number 23

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