02
Sat, Nov
2 New Articles

Windows of Opportunity

Microsoft
Typography
  • Smaller Small Medium Big Bigger
  • Default Helvetica Segoe Georgia Times

Y2K date solutions seem as varied as the vendors who offer them. One overlooked yet critical piece of logic in Y2K conversion is the Open Query File (OPNQRYF) command. Here are a few OPNQRYF techniques for those of you who have chosen windowing as your Y2K solution.

Many shops have chosen windowing as their solution to the Y2K issue. Consequently, one problem AS/400 sites inevitably encounter is how to use windowing with Open Query File (OPNQRYF). It is rare that an AS/400 shop does not have at least a few of these CL-based front-ends to assist in report processing, and rewriting OPNQRYF commands can escalate costs at a time when your completion deadline is nonnegotiable.

Typically, you use the OPNQRYF command to select a set of records based on certain criteria and place them in the proper sequence. Usually, a high-level language (HLL) program is called to process the data OPNQRYF selects. Common use of the 6-byte date field (YYMMDD) leads to obvious sorting errors after this data crosses the boundary between 1999 and 2000.

The two most common methods of addressing the Y2K problem are database conversion and windowing. Database conversion entails using the date data type, converting 6-byte fields (YYMMDD) to 8 bytes (YYYYMMDD), or some other accepted format. The object-to-database conversion alters the way dates are stored so dates sort chronologically.

In contrast, windowing leaves dates in a two-digit year format, assuming the dates are within a 100-year window (1950-2049, for example). In some cases, however, database conversion entails far more code changes than does windowing. For that reason, many shops have chosen windowing based on time considerations. This article discusses only the windowing conversion of OPNQRYF.

Original Query

To illustrate this technique, assume you have a file of inventory transactions keyed in by item number, as shown in Figure 1. (For this example, ITEMFILE in Figure 2 contains the data.) Figure 3 shows how OPNQRYF selects the data in the file by CHANGEDATE. This code is not ready for 2000.

OPNQRYF selects all records greater than the value passed in through parameter &TSTDATE. You call the ITEMQRYR program to produce a basic report of the records that OPNQRYF filters. Figure 4 shows the results for the original query if &TSTDATE has the value 901210. Note that the dates are printed in standard MMDDYY format.

The problem with OPNQRYF is that it doesn’t select dates from the Year 2000 and beyond, but we know of several ways to fix that problem. Here are a couple.

Query Renovated Using %DATE

You can use the %DATE function to renovate an OPNQRYF command for Y2K. This function converts the date in the field CHANGEDATE. The reformatted CHANGEDATE is then compared with the CL variable &TSTDATE. This is illustrated in Figure 5.

The %DATE returns a date from a given value. Two criteria determine the format of the value: the system date separator and system date format. In the United States, the date separator character is typically the slash (/), and the usual date format is *MDY.

You need to make only two changes in the CL program to renovate it for Y2K. First, you change the format of the variable &TSTDATE and reformat the date to match the standards set by the system date separator and format. For example, &TSTDATE now reads 12/10/90 instead of 901210.

The second change is more complex. You need to create three mapped fields to produce the date field Y2KDATE (Y2KDATE is used in the “greater than” comparison instead of CHANGEDATE):

1. Y2KDATE1. The %DIGITS function converts packed field CHANGEDATE to a character type.

2. Y2KDATE2. Reformat Y2KDATE1 into MM/DD/YY format through substringing and concatenation. Note that this format must use the values of the system date separator and format (/ and *MDY in our example).

3. Y2KDATE. Create the final map field by using the %DATE function on Y2KDATE2. Use of the %DATE function forces a date to be evaluated using the range 1940-2039. Because the value of Y2KDATE occurs in the date window 1940-2039, any date in the proper format compared with it is also evaluated in the window.

The renovated query now selects any records greater than 12/10/1990, based on a 1940-2039 window (see Figure 6). However, a drawback to this approach is the current limit to using 1940-2039 as your date window. Many shops may use a different window or may want more precise control of their window’s range.

Query Renovated Using a Mathematical Calculation

This version of Y2K renovation takes a mathematical approach. You use a simple formula to produce a century field with a value of 19 or 20. This field is then concatenated onto a date YYMMDD to produce a date field YYYYMMDD. The formula is shown below: Take the date 980101, for example (January 1, 1998). The decade of the year is the first digit in a two-digit year. For the year 98, the decade is 9. The pivot decade is the first digit in the two-digit window-beginning year, divided by 10. For a window of 1950-2049, the pivot decade is 0.5.

Therefore, to calculate the century field for January 1, 1998, the system calculates as follows:

1. Century = ((199 - 9) * .1 ) + .5
2. Century = 19.5
3. Century truncated = 19
4. Century appended to sample date = 19980101

Century = ((199 - Decade of Year) * .1) + Pivot Decade

As before, two changes must be applied to renovate the CL. (The revised code is shown in Figure 7.) The first is to alter the &TSTDATE field to the YYYYMMDD format. The second is more extensive.

Use MAP fields to produce a YYYYMMDD-formatted version of CHANGEDATE:
1. Y2KDATE1. The %DIGITS function converts CHANGEDATE to character
2. Y2KDECADE. The decade of the date is extracted.
3. Y2KCENTUR1. The century creation formula is applied. Because a pivot decade of 0.5 has been chosen, the date is forced into a 1950-2049 window.

4. Y2KCENTUR2. The result from Y2KCENTUR1 is truncated to two digits.
5. Y2KCENTURY. Y2KCENTUR2 is converted to a character field.
6. Y2KDATE. Y2KCENTURY and Y2KDATE1 are concatenated to produce a date format of YYYYMMDD.

The renovated query now selects any records greater than 12/10/1990 based on a 1950-2049 window (see Figure 8).

Processing Invalid Dates

A disadvantage of these two approaches is that they do not correctly process invalid date values, such as all 0s and all 9s. The %DATE function cannot process invalid date values whatsoever, and the mathematical approach allows invalid values but does not sequence them properly. Typically, a date of all 0s should appear at the beginning of reports and a date of all 9s, at the end.

However, if you’re willing to introduce a little messy code into the MAPFLD parameter, you can account for these special dates.

The revised query in Figure 9 sorts the records by the new MAPFLD SORTFIELD but can easily be changed to do the previous record selection (the CL driver has been slightly modified):

1. Create a physical file WORKFILE with the same fields as ITEMFILE but add one more field, SORTFIELD, defined as 7 alphanumeric. WORKFILE does not contain data and does not have to contain a member.

2. Change the HLL program ITMQRYR to read from WORKFILE rather than from ITEMFILE. The program does not read WORKFILE; it only appears to do so.

3. Change the OPNQRYF to sort on SORTFIELD rather than on the date field.
4. In the MAPFLD parameter, define SORTFIELD as a modified version of CHANGDATE. SORTFIELD comprises other mapped fields:

• SORT1. CHANGEDATE is divided by 999,999, and the result is truncated to a length of one digit. This division produces a 0 for all values except the date 99/99/99, which produces a 1.

• SORTW. CHANGEDATE is divided by itself or one, whichever is greater, and the result is truncated to a length of one digit. This division produces a 1 for all date values except the date 00/00/00, which produces a 0.

• SORT2. Adding 600,000 to CHANGEDATE and keeping the remainder after dividing by 1,000,000 results in a windowed date. Multiplying by SORTW causes dates of all 0s to remain 0 and nonzero dates to keep their windowed values.

Figure 10 shows the output for this OPNQRYF. For this example, two records using 00/00/00 and 99/99/99 have been added. The column entitled “Unprinted Value of SORTFIELD” illustrates the value of SORTFIELD at completion of the query.

Be Creative!

You can use different approaches to prepare OPNQRYF for Y2K. Windowing techniques can lead to a maintenance nightmare, but if time is running out, you can use these tips to maintain business functionality. Some of these methods may prove most practical to address the programs and processes your business relies upon, and you can

type.

find more techniques in the book Y2K Survival Kit for AS/400 Programmers published by Midrange Computing.

Whatever you do, don’t be afraid to try unfamiliar techniques. Creativity may be the most important tool of all for riding out the Y2K storm.

A
A R ITEMREC
A ITEMNUM 10
A CHANGEDATE 6P 0
A ITEMTYPE 10
A ITEMDESC 40
A K ITEMNUM

Figure 1: Physical file ITEMFILE is typical of files used with OPNQRYF.

ITEMNUM CHANGEDATE ITEMTYPE ITEMDESC

9999 991231 BOX CARDBOARD 9999 000101 BOX CARDBOARD 9999 900101 BOX CARDBOARD 9999 490101 BOX CARDBOARD 9999 500101 BOX CARDBOARD 9999 891225 BOX CARDBOARD 9999 690101 BOX CARDBOARD 9999 110228 BOX CARDBOARD 9999 990315 BOX CARDBOARD 9999 050615 BOX CARDBOARD 9999 100917 BOX CARDBOARD 9999 220503 BOX CARDBOARD 9999 300930 BOX CARDBOARD

Figure 2: ITEMFILE contains the following data.

PGM PARM(&TSTDATE)
DCL VAR(&TSTDATE) TYPE(*CHAR) LEN(6)

OVRDBF FILE(ITEMFILE) TOFILE(*LIBL/ITEMFILE) +

SHARE(*YES)
OPNQRYF FILE((ITEMFILE)) + QRYSLT('CHANGEDATE *GT ' *CAT &TSTDATE)
CALL PGM(ITEMQRYR)
CLOF OPNID(ITEMFILE)
DLTOVR FILE(ITEMFILE)

ENDPGM

Figure 3: This OPNQRYF routine is not ready for 2000.

ITEMNUM CHANGEDATE ITEMTYPE ITEMDESC

9999 12/31/99 BOX CARDBOARD 9999 03/15/99 BOX CARDBOARD

Figure 4: OPNQRYF incorrectly selects 20

th

-century dates only.

PGM DCL VAR(&TSTDATE) TYPE(*CHAR) LEN(8) VALUE('12/10/90')

OVRDBF FILE(ITEMFILE) TOFILE(*LIBL/ITEMFILE) +

SHARE(*YES)
OPNQRYF FILE((ITEMFILE)) +

QRYSLT('Y2KDATE *GT "' *CAT &TSTDATE *CAT '"') +

MAPFLD((Y2KDATE1 '%DIGITS(CHANGEDATE)' *CHAR 6) +

(Y2KDATE2 '%SST(Y2KDATE1 3 2) *CAT "/" *CAT +

%SST(Y2KDATE1 5 2) *CAT "/" *CAT +

%SST(Y2KDATE1 1 2)' *CHAR 8) +

(Y2KDATE '%DATE(Y2KDATE2)'))

CALL PGM(ITEMQRYR)
CLOF OPNID(ITEMFILE)
ENDPGM

Figure 5: This query has been renovated using the %DATE function.

ITEMNUM CHANGEDATE ITEMTYPE ITEMDESC

9999 12/31/99 BOX CARDBOARD 9999 01/01/00 BOX CARDBOARD 9999 02/28/11 BOX CARDBOARD 9999 03/15/99 BOX CARDBOARD 9999 06/15/05 BOX CARDBOARD 9999 09/17/10 BOX CARDBOARD 9999 05/03/22 BOX CARDBOARD 9999 09/30/30 BOX CARDBOARD

Figure 6: Using the %DATE function makes OPNQRYF use the 1940-2039 window.

PGM DCL VAR(&TSTDATE) TYPE(*CHAR) LEN(8) VALUE('19901210')
OVRDBF FILE(ITEMFILE) TOFILE(*LIBL/ITEMFILE) +

SHARE(*YES)
OPNQRYF FILE((ITEMFILE)) +

QRYSLT('Y2KDATE *GT "' *CAT &TSTDATE *CAT '"') +

MAPFLD((Y2KDATE1 '%DIGITS(CHANGEDATE)' *CHAR 6) +

(Y2KDECADE '%SST(Y2KDATE1 1 1)' *ZONED 1) +

(Y2KCENTUR1 '(((199 - Y2KDECADE) * .1) + .5)' +

*ZONED 3 1) +

(Y2KCENTUR2 Y2KCENTUR1 *ZONED 2) +

(Y2KCENTURY Y2KCENTUR2 *CHAR 2) +

(Y2KDATE 'Y2KCENTURY *CAT Y2KDATE1'))
CALL PGM(ITEMQRYR)

CLOF OPNID(ITEMFILE)
ENDPGM

Figure 7: A mathematical calculation renovates this query.

ITEMNUM CHANGEDATE ITEMTYPE ITEMDESC

9999 12/31/99 BOX CARDBOARD 9999 01/01/00 BOX CARDBOARD 9999 01/01/49 BOX CARDBOARD 9999 02/28/11 BOX CARDBOARD 9999 03/15/99 BOX CARDBOARD 9999 06/15/05 BOX CARDBOARD 9999 09/17/10 BOX CARDBOARD 9999 05/03/22 BOX CARDBOARD 9999 09/30/30 BOX CARDBOARD

Figure 8: Using this math formula, OPNQRYF uses the 1950-2049 window.

PGM OPNQRYF FILE((ITEMFILE)) FORMAT(ITEMFILTEM) +

KEYFLD((SORTFIELD)) +

MAPFLD((SORT1 'CHANGEDATE / 999999' *DEC 1 0) +

(SORTW 'CHANGEDATE / %MAX(CHANGEDATE 1)' *DEC 1 0) +

(SORT2 'SORTW * ((CHANGEDATE + 600000) // 1000000)' +

*DEC 6 0) +

(SORTFIELD '%DIGITS(SORT1) *CAT %DIGITS(SORT2)'))

OVRDBF FILE(WORKFILE) TOFILE(ITEMFILE) SHARE(*YES)
CALL PGM(ITEMQRYR)
CLOF OPNID(ITEMFILE)

ENDPGM

Figure 9: A mathematical calculation using MAP fields renovates this query.

ITEMNUM CHANGEDATE Unprinted ITEMTYPE ITEMDESC

Value of SORTFIELD 9999 00/00/00 0000000 BOX CARDBOARD 9999 01/01/49 0090101 BOX CARDBOARD 9999 01/01/50 0100101 BOX CARDBOARD 9999 01/01/69 0290101 BOX CARDBOARD 9999 12/25/89 0491225 BOX CARDBOARD 9999 01/01/90 0500101 BOX CARDBOARD 9999 03/15/99 0590315 BOX CARDBOARD 9999 12/31/99 0591231 BOX CARDBOARD 9999 01/01/00 0600101 BOX CARDBOARD 9999 06/15/05 0650615 BOX CARDBOARD 9999 09/17/10 0700917 BOX CARDBOARD 9999 02/28/11 0710228 BOX CARDBOARD 9999 05/03/22 0820503 BOX CARDBOARD 9999 09/30/30 0900930 BOX CARDBOARD 9999 99/99/99 1599999 BOX CARDBOARD

Figure 10: With this math formula, OPNQRY uses the 1940-2039 window.

BLOG COMMENTS POWERED BY DISQUS

LATEST COMMENTS

Support MC Press Online

$

Book Reviews

Resource Center

  • SB Profound WC 5536 Have you been wondering about Node.js? Our free Node.js Webinar Series takes you from total beginner to creating a fully-functional IBM i Node.js business application. You can find Part 1 here. In Part 2 of our free Node.js Webinar Series, Brian May teaches you the different tooling options available for writing code, debugging, and using Git for version control. Brian will briefly discuss the different tools available, and demonstrate his preferred setup for Node development on IBM i or any platform. Attend this webinar to learn:

  • SB Profound WP 5539More than ever, there is a demand for IT to deliver innovation. Your IBM i has been an essential part of your business operations for years. However, your organization may struggle to maintain the current system and implement new projects. The thousands of customers we've worked with and surveyed state that expectations regarding the digital footprint and vision of the company are not aligned with the current IT environment.

  • SB HelpSystems ROBOT Generic IBM announced the E1080 servers using the latest Power10 processor in September 2021. The most powerful processor from IBM to date, Power10 is designed to handle the demands of doing business in today’s high-tech atmosphere, including running cloud applications, supporting big data, and managing AI workloads. But what does Power10 mean for your data center? In this recorded webinar, IBMers Dan Sundt and Dylan Boday join IBM Power Champion Tom Huntington for a discussion on why Power10 technology is the right strategic investment if you run IBM i, AIX, or Linux. In this action-packed hour, Tom will share trends from the IBM i and AIX user communities while Dan and Dylan dive into the tech specs for key hardware, including:

  • Magic MarkTRY the one package that solves all your document design and printing challenges on all your platforms. Produce bar code labels, electronic forms, ad hoc reports, and RFID tags – without programming! MarkMagic is the only document design and print solution that combines report writing, WYSIWYG label and forms design, and conditional printing in one integrated product. Make sure your data survives when catastrophe hits. Request your trial now!  Request Now.

  • SB HelpSystems ROBOT GenericForms of ransomware has been around for over 30 years, and with more and more organizations suffering attacks each year, it continues to endure. What has made ransomware such a durable threat and what is the best way to combat it? In order to prevent ransomware, organizations must first understand how it works.

  • SB HelpSystems ROBOT GenericIT security is a top priority for businesses around the world, but most IBM i pros don’t know where to begin—and most cybersecurity experts don’t know IBM i. In this session, Robin Tatam explores the business impact of lax IBM i security, the top vulnerabilities putting IBM i at risk, and the steps you can take to protect your organization. If you’re looking to avoid unexpected downtime or corrupted data, you don’t want to miss this session.

  • SB HelpSystems ROBOT GenericCan you trust all of your users all of the time? A typical end user receives 16 malicious emails each month, but only 17 percent of these phishing campaigns are reported to IT. Once an attack is underway, most organizations won’t discover the breach until six months later. A staggering amount of damage can occur in that time. Despite these risks, 93 percent of organizations are leaving their IBM i systems vulnerable to cybercrime. In this on-demand webinar, IBM i security experts Robin Tatam and Sandi Moore will reveal:

  • FORTRA Disaster protection is vital to every business. Yet, it often consists of patched together procedures that are prone to error. From automatic backups to data encryption to media management, Robot automates the routine (yet often complex) tasks of iSeries backup and recovery, saving you time and money and making the process safer and more reliable. Automate your backups with the Robot Backup and Recovery Solution. Key features include:

  • FORTRAManaging messages on your IBM i can be more than a full-time job if you have to do it manually. Messages need a response and resources must be monitored—often over multiple systems and across platforms. How can you be sure you won’t miss important system events? Automate your message center with the Robot Message Management Solution. Key features include:

  • FORTRAThe thought of printing, distributing, and storing iSeries reports manually may reduce you to tears. Paper and labor costs associated with report generation can spiral out of control. Mountains of paper threaten to swamp your files. Robot automates report bursting, distribution, bundling, and archiving, and offers secure, selective online report viewing. Manage your reports with the Robot Report Management Solution. Key features include:

  • FORTRAFor over 30 years, Robot has been a leader in systems management for IBM i. With batch job creation and scheduling at its core, the Robot Job Scheduling Solution reduces the opportunity for human error and helps you maintain service levels, automating even the biggest, most complex runbooks. Manage your job schedule with the Robot Job Scheduling Solution. Key features include:

  • LANSA Business users want new applications now. Market and regulatory pressures require faster application updates and delivery into production. Your IBM i developers may be approaching retirement, and you see no sure way to fill their positions with experienced developers. In addition, you may be caught between maintaining your existing applications and the uncertainty of moving to something new.

  • LANSAWhen it comes to creating your business applications, there are hundreds of coding platforms and programming languages to choose from. These options range from very complex traditional programming languages to Low-Code platforms where sometimes no traditional coding experience is needed. Download our whitepaper, The Power of Writing Code in a Low-Code Solution, and:

  • LANSASupply Chain is becoming increasingly complex and unpredictable. From raw materials for manufacturing to food supply chains, the journey from source to production to delivery to consumers is marred with inefficiencies, manual processes, shortages, recalls, counterfeits, and scandals. In this webinar, we discuss how:

  • The MC Resource Centers bring you the widest selection of white papers, trial software, and on-demand webcasts for you to choose from. >> Review the list of White Papers, Trial Software or On-Demand Webcast at the MC Press Resource Center. >> Add the items to yru Cart and complet he checkout process and submit

  • Profound Logic Have you been wondering about Node.js? Our free Node.js Webinar Series takes you from total beginner to creating a fully-functional IBM i Node.js business application.

  • SB Profound WC 5536Join us for this hour-long webcast that will explore:

  • Fortra IT managers hoping to find new IBM i talent are discovering that the pool of experienced RPG programmers and operators or administrators with intimate knowledge of the operating system and the applications that run on it is small. This begs the question: How will you manage the platform that supports such a big part of your business? This guide offers strategies and software suggestions to help you plan IT staffing and resources and smooth the transition after your AS/400 talent retires. Read on to learn: