Operating Systems

DFSORT: IFTHEN, Numeric Tests & Relative Dates

4 Pages

NUM

NUM is a new function you can use in a logical expression of the INCLUDE and OMIT statements, the INCLUDE and OMIT parameters of the OUTFIL statement, and the WHEN parameter of an IFTHEN clause to test whether a character, zoned-decimal, or packed-decimal value is numeric ( E Q, N UM) o r n o t n ume r i c (NE,NUM).

  • Use FS format to check a character value with NUM. A numeric value of this type has ‘0’-‘9’ in every byte.
  • Use ZD format to check a zoned-decimal value with NUM. A numeric value of this type has ‘0’-‘9’ in all non-sign bytes, and X’F0’-X’F9’, X’D0’-X’D9’ or X’C0’-X’C9’ in the sign (last) byte.
  • Use PD format to check a packeddecimal value with NUM. A numeric value of this type has 0-9 for all digits, and F, D, or C for the sign.

TO=ZDF, TO=ZDC, TO=PDF, TO=PDC

TO=ZDF and TO=ZDC are new output formats you can use in the INREC, OUTREC and OUTFIL statements wherever TO=ZD can be used (converted fields, statistics, page numbers, counts, and so on). With TO=ZDF or TO=ZD, DFSORT uses an F sign for each positive ZD value (for example, +12 = X’F1F2’). With TO=ZDC, DFSORT uses a C sign for each positive ZD value (for example, +12 = X’F1C2’). In either case, DFSORT uses a D sign for each negative ZD value (for example, -12 = X’F1D2’).

Our final example shows how you can use IFTHEN clauses to collect and display data about different date intervals. Figure 4 shows an input file with an amount field (dddd.d) in positions one through six and a date field (yyyy/ dd/mm) in positions 11 through 20. For this example, the current date (date of the run) is 2006/07/07, so the input file has both past dates and future dates relative to the date of the run, ranging from 2006/05/15 to 2006/08/01. We’d like to display the totals of the amounts for three date intervals: from seven days before the current date to three days before the current date, from two days before the current date to two days after the current date, and from three days after the current date to seven days after the current date. We’re not interested in the amounts for dates eight or more days before or after the current date.

For our current date of 2006/07/07, the actual date intervals are: 2006/06/30 through 2006/07/04, 2006/07/05 through 2006/07/09, and 2006/07/10 through 2006/07/14. Since we’re dealing with relative dates, the date intervals would change depending on the date of the run. For example, if we were to run the job on 2007/07/11, the date intervals would be: 2006/07/04 through 2006/07/08, 2006/07/09 through 2006/07/13, and 2006/07/14 through 2006/07/18. We want our report to show the actual dates for each date interval regardless of when the job runs.

Figure 4 shows the DFSORT control statements we need to display our interval report. The new functions here are past date constants (DATE1(/)- days) and future date constants (DATE1(/)+days). We’ll discuss what each control statement does as well as the new functions.

We use the OMIT statement to remove the records with dates we’re not interested in. The 11,10,CH,LT,DATE1(/)-7 test omits each record with a yyyy/mm/dd date less than the current date -7 days. The 11,10,CH,GT,DATE1(/)+7 test omits each record with a yyyy/mm/dd date greater than the current date +7 days. Since OMIT is processed before the other statements, the omitted records aren’t processed by the other statements.

We use three IFTHEN clauses in the INREC statement to handle our three date intervals:

  • The first IFTHEN clause uses WHEN =(11,10,CH,LE,DATE1(/)-3) to indicate it applies only to records with a date less than or equal to the current date -3 days. Since we omitted records with a date less than the current date -7 days, this IFTHEN clause operates on dates from seven days before the current date to three days before the current date; our first date interval. For each input record in the first date interval, BUILD builds an output record with the actual dates for the first interval in positions one through 21, and the amount from that input record in positions 30 through 35. DATE1(/)-7 generates a yyyy/mm/dd constant for the current date -7 days. DATE1(/)-3 generates a yyyy/mm/dd constant for the current date -3 days. For example, with our current date of 2006/07/07, the first IFTHEN clause gives us two records with ‘2006/06/30- 2006/07/04’ in positions one through 21; the first record has ‘6015.8’ in positions 30 through 35, and the second record has ‘8523.0’ in positions 30 through 35.
  • The second IFTHEN clause uses WHEN=(11,10,CH,GT,DATE1(/)- 3,AND, 11,10,CH,LE,DATE1(/)+2) to indicate it applies only to records with a date greater than the current date -3 days and less than or equal to the current date +2 days. Thus, this IFTHEN clause operates on dates from two days before the current date to two days after the current date; our second date interval. For each input record in the second date inter val, BUILD builds an output record with the actual dates for the second interval in positions one through 21, and the amount from that input record in positions 30 through 35. DATE1(/)-2 generates a yyyy/mm/dd constant for the current date -2 days. DATE1(/)+2 generates a yyyy/mm/dd constant for the current date +2 days.
  • The third IFTHEN clause uses WHEN=NONE to indicate it applies only to records that don’t satisfy the first or second IFTHEN clause. Since we omitted records with a date greater than the current date +7 days, this IFTHEN clause operates on dates from three days after the current date to seven days after the current date; our third date interval. For each input record in the third date interval, BUILD builds an output record with the actual dates for the third interval in positions one through 21, and the amount from that input record in positions 30 through 35. DATE1(/)+3 generates a yyyy/mm/dd constant for the current date +3 days. DATE1(/)+7 generates a yyyy/mm/dd constant for the current date +7 days.

We use the SORT statement to sort on the interval dates in positions one through 21. The records for the first interval (lowest dates) will be sorted first, followed by the records for the second interval, and then the records for the third interval (highest dates). This ensures records in the same interval are in consecutive order so we can use OUTFIL’s SECTIONS parameter to total the amounts for each interval.

4 Pages