• 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
    FalconStor

    Simplify Secure Offsite Data Protection for IBM Power with FalconStor Habanero™

    IBM i teams are under growing pressure to ensure data is protected, recoverable, and compliant—without adding complexity or disrupting stable environments.

    FalconStor Habanero™ provides secure, fully managed offsite data protection purpose-built for IBM Power. It integrates directly with existing IBM i backup tools and processes, enabling reliable offsite copies without new infrastructure, workflow changes, or added operational overhead.

    By delivering and managing the service end-to-end, FalconStor helps organizations strengthen cyber resilience, improve disaster recovery readiness, and meet compliance requirements with confidence. Offsite copies are securely maintained and available when needed, supporting recovery, audits, and business continuity.

    FalconStor Habanero offers a straightforward way to modernize offsite data protection for IBM i: focused on simplicity, reliability, and resilience.

    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 Embed PJL Statements in a Workstation Customizing Object

    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

  • Q&A With IBM’s New GM Of Power, Hillery Hunter
  • When IBM i Skills Become A Resilience Risk
  • Guru: Load A Varying-Dimension Array With One SQL Fetch
  • You Have To Speak IBM’s Language If You Want To Be Heard
  • Raz-Lee Revs iSecurity Suite With 2026 Updates
  • The Big Easy: Connecting The Dots On Big Blue’s AI Strategy For IBM i
  • From Migration To Maturity: The Cloud Reality For IBM i Shops
  • COMMON Dances To A Fresh New Tune In New Orleans
  • Eradani Touts Native Git Connection As AI Tools Spread
  • IBM i PTF Guide, Volume 28, Number 17

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