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 youre running native code, you may have programs that use the Format Data (FMTDTA) command. Maybe youll be able to modernize all of that code as part of your Year 2000 effort, but chances are you wont, 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, well cover a few fundamentals of #GSORT. Even if youre an old hand at #GSORT, you may want to read this section anyway. Possibly, theres information here youve 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 youre 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 selectedwhether 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
LATEST COMMENTS
MC Press Online