fhg
Volume 8, Number 38 -- November 5, 2008

OPNQRYF Has No "If" But You Can Fake It

Published: 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


Sponsored By
HELP/SYSTEMS

SEQUEL™ -- IBM® System i™ Business Intelligence Made Easy

                  · Easy to use by IT and end users
                  · Automated data access and display
                  · Complete BI package: reports, tables, key performance indicators, and dashboards
                  · System i-centric for real-time data analysis
                  · Multiple interface options: graphical, green-screen, browser
                  · Expert support and training

SEQUEL meets your System i data access and analysis needs.

http://www.helpsystems.com/400g


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


 
The Four Hundred
Is the Smart Cube the New i?

You Can Still Walk Upgrade Paths with Power Systems i

IBM Sues to Block Server Executive from Joining Apple

The i Gives Manufacturers and Distributors Cost Control

Forrester CEO Weighs In on IT Spending for 2009

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
Seagull Unveils New LegaSuite Reporting Tool

Spectrum Manages 'E-Assets' with SCM Tool

ProData Expands Database Support in DBU

Micro Focus Works on COBOL Standardization, Training

Oracle Launches 'Best Practice Center' for SOA-Enabling JDE EnterpriseOne

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
November 1, 2008: Volume 10, Number 44

October 25, 2008: Volume 10, Number 43

October 18, 2008: Volume 10, Number 42

October 11, 2008: Volume 10, Number 41

October 4, 2008: Volume 10, Number 40

September 27, 2008: Volume 10, Number 39

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
WorksRight Software
Vision Solutions


Printer Friendly Version


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

Four Hundred Guru

BACK ISSUES

From the IT Jungle Forums
Data Queues vs. MQ Series: Performance

Removing blanks from a CL Variable

XML

SQL "Hidden" Field

Java Messages

MQ Help Desired





 
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