21
Thu, Nov
1 New Articles

Sorting Two-digit Years with #GSORT and FMTDTA

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

If your Year 2000 concerns include FMTDTA or #GSORT, we have a tip for you. You can correctly sort two-digit years!

Whatever your opinion of the S/36 and its application architecture may be, the reality is that a lot of S/36 code is still in production. Even if you’re running native code, you may have programs that use the Format Data (FMTDTA) command. Maybe you’ll be able to modernize all of that code as part of your Year 2000 effort, but chances are you won’t, especially if your files are described in programs rather than with external definitions.

If you want to keep your existing software running, you have a few choices:
• Expand all date fields by one digit (for a century value) or two digits (to store the first two digits of a four-digit year).

• Add extra fields to each record to hold a century value or the missing two digits.
• Leave the files as they are, and change programs as required to keep them working with two-digit years. This technique is commonly known as windowing.

If your Y2K solution is a software-only solution (that is, you are not changing your database files), then you can use forced control fields in FMTDTA and #GSORT to correctly sort by date even when the data file being sorted contains no century value. The advantage to this method is that you do not have to preprocess the file with a program to extract the requested records. As the Year 2000 bears down on us, we can use every timesaving device available.

This article shows you how to modify these sorts. We use #GSORT to illustrate, but remember that this applies to FMTDTA as well.

A Few Fundamentals

First, we’ll cover a few fundamentals of #GSORT. Even if you’re an old hand at #GSORT, you may want to read this section anyway. Possibly, there’s information here you’ve forgotten or maybe never knew about.

For #GSORT to select the correct records and sort on the appropriate fields, it must read sequence specifications from a source member or from a job stream. These sequence specs are similar to RPG in that they are 80 columns wide and contain a specification identifier in column 6.

The first sequence spec is the control spec, designated by an H in column 6. When you’re modifying the H-spec for Year 2000 readiness, the most important entry in the control spec is in positions 13 through 17, which tells how many bytes to allocate for the control field. You may have to increase the size of this entry by one byte.

Following the H-spec are one or more include/omit sets. An include/omit set consists of zero or more include and/or omit specifications, followed by one or more field specifications. Include specifications tell #GSORT to include a subset of records from the input file(s) and are indicated by an I in position 6. Omit specifications, which are indicated by an O in position 6, tell #GSORT not to include a subset of records. If you are selecting records based on a cutoff date or range of dates, you may have to modify the logic of these specifications.

Field specifications have an F in column 6. Use them to specify which fields are to be copied into the control field (the field dynamically built for sorting) and which fields are to be included in the data record produced by the sort. If you are sorting by date, you will have to make modifications to the field specs, but they will not be major ones.

Figure 1 shows sort specifications before changes for Y2K. There are no include or omit specs, so this is one include/omit set, and all records will be included in the sort.

Figure 2 shows the sort specifications after Y2K changes. There are two include/omit sets. The first include/omit set selects records for years 70 through 99. In the fourth line, you will see the forced field specification, identified by an F in column 7. This line forces a value of 1 into the sort fields after TYPE and ahead of YEAR. The second include/omit set selects the rest of the records in the file, which would be for years 00 through 69. Line 12 forces a 2. Years 70 through 99 are sorted ahead of years 00 through Since column 28 of the H specification has an X, the sort fields are not included in the output record. This means the output file of the sort that is read by a program will be unchanged to the program, and, therefore, the program will not need to be modified because of the forced field sorting. This also means that the century value will not be available to the program, and if you need to determine the century, you will have to do that with program logic.

You should also notice that the control field length, columns 13 through 17 on the H specification, also has to be changed to reflect the increased size of the sort fields.

Another way to modify the sort for Y2K readiness is through conditional forced control fields, as illustrated in Figure 3. The first forced control field line builds a control field value of 0 if position 209 contains a 7. The following line has a nonblank character in column 20, indicating that it is a continuation of the previous line. This line loads the control field with a 1 if the input data is an 8. The next eight lines build control field values of 2 through 9 from the other digits. This forced control field value precedes the two-digit year field in the sorting priority, so the data is ordered in chronological sequence.

Record Selection

Once we realized what a help forced field sorting could be with the Y2K problem, we decided to try using that technique for record selections by date range. Although it is a little more complicated, you can use nothing but S/36 operation control language (OCL) to select by date across centuries even when the data file does not contain a century value.

In Figure 4 you will notice two sort routines. The first routine is the original routine, which is used if the starting and ending dates do not cross a century boundary. The second routine is used when the requested date range does cross a century boundary. The key to making this work is found in lines 5 through 10, where the local data area is used to

Sorting

determine if a century boundary is crossed. If a century boundary is crossed, we select all records with dates on or after the beginning date, and all records before or on the ending date. To cause them to sort correctly, we use the forced field sorting technique from Figure 2 to correctly select and sort our data.

Obviously, if the user makes an error in keying the date range, the century sort could be invoked erroneously. However, anytime the user keys the wrong date range, the wrong items are selected—whether or not this involves a cross-century sort.

Programmers who use FMTDTA or store S/36 sequence specifications in source members will not be able to use this dual sort routine method because no substitution variables are permitted in sequence specs stored in source members.

An interesting phenomenon of this technique is that a cut-over year is not needed, and, consequently, this method will work through the year 2100 and beyond. Do you think SSP and OCL will still be running then?

....+... 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6

HSORTR 38A 3X 256

FNC 1 2 TYPE

FNC 209 210 YEAR

FNC 211 212 MONTH

FNC 213 214 DAY

FNC 13 32 NAME

FDC 1 256

Figure 1: Sort sequence specifications; not ready for Y2K

....+... 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6

HSORTR 39A 3X 256

FNC 1 2 TYPE

FFC 20970 7 -> 0

FFC 20981+ 8 -> 1

FFC 20992+ 9 -> 2

FFC 20903+ 0 -> 3

FFC 20914+ 1 -> 4

FFC 20925+ 2 -> 5

FFC 20936+ 3 -> 6

FFC 20947+ 4 -> 7

FFC 20958+ 5 -> 8

FFC 20969+ 6 -> 9

FNC 209 210 YEAR

FNC 211 212 MONTH

FNC 213 214 DAY

FNC 13 32 NAME

FDC 1 256

Figure 3: Using a conditional forced control field

....+... 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6

HSORTR 39A 3X 256

I C 209GTC6

FNC 1 2 TYPE

FFC 1 FORCED CENTURY VALUE

FNC 209 210 YEAR

FNC 211 212 MONTH

FNC 213 214 DAY

FNC 13 32 NAME

FDC 1 256

I

FNC 1 2 TYPE

FFC 2 FORCED CENTURY VALUE

FNC 209 210 YEAR

FNC 205 206 MONTH

FNC 207 208 DAY

FNC 13 32 NAME

FDC 1 256

Figure 2: Sort sequence specifications; ready for Y2K

// * 'Enter Starting Date as YYMMDD'
// IF ?1R?= CANCEL
// * 'Enter Ending Date as YYMMDD'
// IF ?2R?= CANCEL
// LOCAL DATA-'000000000000'
// LOCAL DATA-'?1?'
// LOCAL OFFSET-7,DATA-'?2?'
// EVALUATE P51=?L'1,2'?
// EVALUATE P52=?L'7,2'?
// IF ?51?>?52? GOTO DOCENT
// * 'Sorting File - you only need a normal sort here'
// LOAD #GSORT
// FILE NAME-INPUT,LABEL-FILEIN
// FILE NAME-OUTPUT,LABEL-FILEOUT
// RUN HSORTR 38A 3X 256

O 209 214LTC?1?

I 209 214LEC?2?

FNC 1 2 TYPE

FNC 209 210 YEAR

FNC 211 212 MONTH

FNC 213 214 DAY

FNC 13 32 NAME

FDC 1 256
// END
// GOTO SORTED
*

// TAG DOCENT
// * 'Sorting File - only if a century is crossed'
// LOAD #GSORT
// FILE NAME-INPUT,LABEL-FILEIN
// FILE NAME-OUTPUT,LABEL-FILEOUT
// RUN HSORTR 39A 3X 256

I C 209 214GEC?1?

FNC 1 2 TYPE

FFC 1 FORCED CENTURY VALUE

FNC 209 210 YEAR

FNC 211 212 MONTH

FNC 213 214 DAY

FNC 13 32 NAME

FDC 1 256

I 209 214LEC?2?

FNC 1 2 TYPE

FFC 2 FORCED CENTURY VALUE

FNC 209 210 YEAR

FNC 211 212 MONTH

FNC 213 214 DAY

FNC 13 32 NAME

FDC 1 256
// END
*

// TAG SORTED

Figure 4: Record selection across the millennium break

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: