02
Sat, Nov
2 New Articles

Are You Ready to Play the Dating Game?

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

A very high percentage of AS/400 software systems were not designed to handle the change of the century. In fact, Gartner Group estimates that, without corrective measures, 90 percent of all applications and systems will be affected by the year 2000 date change by 1999, producing unknown or erroneous results. It also estimates that addressing the year 2000 date change will cost as much as $600 billion. (Yes, you read that right. That's billion with a b.)

The problem exists primarily because most business systems have dates stored in six-digit formats and are not capable of handling the change of the century. These systems will interpret the two-digit year 00 as 1900, not 2000. As a result, many programs will crash and burn on or before January 1, 2000, if they are left unchanged.

If you think that you can wait until 1998 or 1999 to start thinking about the problem, you could be in big trouble. The magnitude of the problem can be mind-boggling. Many systems have routines that calculate projected dates or follow-up dates in the future. These routines could begin to have problems long before the year 2000.

So, are you planning to retire in the next three years, or are you thinking about job security? The fact that you are still reading tells us that you will not be shuffling off to Leisure World anytime soon. But since you are an AS/400 programmer, not all of this is gloom and doom. The introduction of RPG IV includes the ability to work with the date data type. Careful implementation of this new technology can offer some pretty significant shortcuts that will take your software well into the 21st century.

Data fields may now be designated as date data types when they are defined in DDS or RPG IV definition specifications. Along with this new data type, we have been introduced to a series of new operation codes that were designed to help us manipulate dates. Routines that use a series of moves or math routines to switch the format of dates from month-day-year to year-month-day are a thing of the past. As you'll see, complicated routines to increment or decrement dates are now unnecessary, too.

The date data type allows you to store your data in a number of six- and eight-digit date formats (see 1), all of which include the century. The date separator is automatically stored with your data, making the field lengths appear to be either six, eight, or ten characters. In other words, if you print or look at your data on the screen, you will see your date fields in the date format you defined with the separator characters already in place. The number and style of the separator character that appears depend upon the date format chosen.

The date data type allows you to store your data in a number of six- and eight-digit date formats (see Figure 1), all of which include the century. The date separator is automatically stored with your data, making the field lengths appear to be either six, eight, or ten characters. In other words, if you print or look at your data on the screen, you will see your date fields in the date format you defined with the separator characters already in place. The number and style of the separator character that appears depend upon the date format chosen.

Date fields are entirely interchangeable. Moving a date stored in the *ISO format to a date field that has been defined with a *MDY date format requires only a simple move operation.

One of the good things about the date data type is that, regardless of the date format chosen, DB2/400 stores the new date data type fields in only 4 bytes on disk, which happens to be the same amount of storage required to store a six-digit date in packed format. So, as you convert your six-digit date fields from numeric or packed data types to the new date data types, you won't notice an increase in DASD use.

You may find that there is no longer a reason to store dates in your database in year-month-day format just to get the key sequence you want. Date fields are stored and compared based upon their chronological value, so you may even want to store the dates in month-day-year format. Doing so means that you will not need to convert the date when you print it on a report. You can compare a date stored in month-day-year format to a date stored in Julian date format, or any of the other supported date formats, without performing any kind of conversion and still get your desired results. As a matter of fact, you don't even need to use an edit code or an edit word when printing dates.

Before you run off to reformat all of your date fields into month-day-year format, however, you need to be aware that the six-digit date fields (*YMD, *MDY, and *DMY) cover only the years from 1940 to 2039. This should be ample for most transaction dates but may be unacceptable in systems that perform some type of forecasting function or that record birth dates, which could easily be prior to 1940.

The reason for this anomaly is the way IBM employed its date windowing algorithms as they apply to the six-digit date. The system automatically assumes that, when this format is used, the two-digit years between 40 and 99 are for the 20th century, and the years between 00 and 39 belong in the 21st century. Consequently, the system-defined *LOVAL for a date field differs depending upon the date format chosen. If a date is defined with the eight-digit *ISO format type, *LOVAL is going to be 0001-01-01. If a date field is defined with the six-digit *YMD format, *LOVAL is going to be 40/01/01.

One thing that makes working with date data types relatively painless is the operation codes that have been introduced in RPG IV. Four new operation codes (as illustrated in 2) allow you to perform a variety of date manipulation functions. These operation codes are designed to work with the date, time, and time-stamp data types that are part of the DB2/400 database.

One thing that makes working with date data types relatively painless is the operation codes that have been introduced in RPG IV. Four new operation codes (as illustrated in Figure 2) allow you to perform a variety of date manipulation functions. These operation codes are designed to work with the date, time, and time-stamp data types that are part of the DB2/400 database.

Date fields are very particular about data validity. If you define a field as a date data type, the system expects to see a valid date in that field. If there is any question about the content of the data you're going to place in a date field, you should use the TEST operation code described in 2 to check the field prior to placing it in the date field. If you think you can just leave zeros in a date field, forget it. The system will insist that you allow only valid dates in a field defined with a date data type.

Date fields are very particular about data validity. If you define a field as a date data type, the system expects to see a valid date in that field. If there is any question about the content of the data you're going to place in a date field, you should use the TEST operation code described in Figure 2 to check the field prior to placing it in the date field. If you think you can just leave zeros in a date field, forget it. The system will insist that you allow only valid dates in a field defined with a date data type.

You knew it sounded too good to be true, didn't you? The bad news is that V3R1 doesn't support the date data type for display files or printer files. Why, you ask? We wish we knew. But it really is not much of an obstacle, as you will see.

We put together a simple RPG IV program that tests dates keyed at a workstation by using two of the new date operation codes. The display file in 3 has a six-digit numeric field called date. Two messages are used to reflect whether the date keyed is valid or not. The program in 4 first tests the date field to see if it's a valid date based on the *MDY format specified in factor 1 of the TEST operation code. We could have made the date field alphanumeric, but the system would have insisted that the date keyed include the date separator characters before it would be considered valid. You can see an example of the output from our simple program in 5.

We put together a simple RPG IV program that tests dates keyed at a workstation by using two of the new date operation codes. The display file in Figure 3 has a six-digit numeric field called date. Two messages are used to reflect whether the date keyed is valid or not. The program in Figure 4 first tests the date field to see if it's a valid date based on the *MDY format specified in factor 1 of the TEST operation code. We could have made the date field alphanumeric, but the system would have insisted that the date keyed include the date separator characters before it would be considered valid. You can see an example of the output from our simple program in Figure 5.

If the date keyed is valid and function key F5 is pressed, the Subtract Duration (SUBDUR) operation code is used to subtract one month from the date. If the date test is passed and function key F6 is pressed, the Add Duration (ADDDUR) operation code is used to increment the date by one day. In both examples of these operation codes, the value to be added or subtracted is specified in factor 2 as well as the duration interval. Valid duration intervals for date data types are *D (days), *M (months), and *Y (years). You'll notice that we had to move the date field to a field defined with a date type before performing the ADDDUR or SUBDUR operations. While TEST may be performed on fields that are not defined with a date data type, that's not the case with the ADDDUR, SUBDUR, or Extract (EXTRCT) operations.

Entering the new millennium is going to be an "E-ticket ride" for most of us in data processing. But if you plan carefully and far enough ahead, you just may avoid many of the pitfalls that your counterparts are certain to experience. Proper use and implementation of the new date data type will help ease your pain.

Doug Pence is the founder and Ron Hawkins is the research and development manager of Computer Processing Unlimited, Inc., in San Diego, California. They are the authors of Power RPG III, published by Midrange Computing. Doug Pence can be reached by E-mail at This email address is being protected from spambots. You need JavaScript enabled to view it..

REFERENCE

AS/400 ILE RPG/400 Reference (SC09-1526, CD ROM QBKAQE00).

Are You Ready to Play the Dating Game?

Figure 1: RPG IV Date Data Types


Are You Ready to Play the Dating Game?

Figure 2: RPG IV Operation Codes for Date and Time Manipulation



Are You Ready to Play the Dating Game?

Figure 3: The DATESDF Display File

 *. 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 A DSPSIZ(24 80 *DS3) A R FORMAT1 A CF03 A CF05 A CF06 A 1 36'Date Test' A DSPATR(HI) A 9 35'Date:' A DATE 6D 0B 9 41 A 98 ERRMSG('You keyed a Valid Date!') A 99 ERRMSG('Invalid Date!') A 23 2'F3=Exit' A COLOR(BLU) A 23 13'F5=Subtract a month' A COLOR(BLU) A 23 36'F6=Add a day' A COLOR(BLU) 
Are You Ready to Play the Dating Game?

Figure 4: The DATESRG Program

 *. 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 ...+ FDATESDF CF E Workstn D Workdate S D Datfmt(*MDY) C DOU *Inkc = *on C EXFMT Format1 C MOVEA '00' *In(98) C *MDY TEST(D) Date 99 C IF *In99 * Test failed, date is invalid. Display error message C ITER C ENDIF * If no function keys were pressed, just send the message C *Inke IFEQ *off C *Inkf ANDEQ *off C EVAL *In98 = *on C ITER C ENDIF C MOVE Date WorkDate C SELECT * If F5 was pressed, decrement date and redisplay screen C WHEN *Inke = *on C SUBDUR 1:*M WorkDate * If F6 was pressed, increment date and redisplay screen C WHEN *Inkf = *on C ADDDUR 1:*D WorkDate C ENDSL C MOVE WorkDate Date C ENDDO C EVAL *Inlr = *on 
Are You Ready to Play the Dating Game?

Figure 5: Example of the DATESRG Program


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: