Operating Systems

DFSORT: IFTHEN, Numeric Tests & Relative Dates

4 Pages

WHEN=INIT clauses can be used for actions that apply to all records. WHEN=(logexp) clauses can be used for actions that apply only to records that satisfy the specified logical expression. All the logical expression capabilities available for INCLUDE also are available for WHEN, including comparisons, substring comparison tests, bit logic tests, date comparisons, numeric tests, AND and OR. WHEN=ANY clauses can be used for actions that apply only to records that satisfied a preceding WHEN=(logexp) clause. WHEN=NONE clauses can be used for actions that apply only to records that didn’t satisfy any of the WHEN=(logexp) clauses.

OVERLAY was discussed in a previous article as a parameter in its own right, but it also can be used in an IFTHEN clause to overlay specific data without affecting the rest of the record. BUILD, which also was discussed in a previous article, is a parameter in its own right, but also can be used in an IFTHEN clause to build a record itemby- item.

By default, as soon as a WHEN=(logexp) clause is satisfied for a record, IFTHEN processing for that record stops. However, you can use IFTHEN’s HIT=NEXT parameter to continue with the next IFTHEN clause as we’ll see in the next example.

This example shows how you can use IFTHEN clauses to check and correct multiple numeric fields in each input record. Figure 3 shows an input file with two ZD fields, one in positions four through eight and another in positions 10 through 14. All the negative ZD fields have a D sign (for example, ‘0521L’ = X’F0F5F2F1D3’). However, some of the positive ZD fields have a C sign (for example, ‘1234E’ = X’F1F2F3F4C5’), and others have an F sign (for example, ‘68200’ = X’F6F8F2F0F0’). We’d like to normalize the positive ZD fields to all have F signs. In addition, not all the values are valid ZD values (for example, ‘582B3’ = X’F5F8F2C2F3’ has an invalid zone of C). We’d like to change the invalid ZD values to ‘00000.’

Figure 3 shows the DFSORT control statements we need to check and change the numeric values. The new functions here are NUM and TO=ZDF. We’ll discuss what each control statement does as well as the new functions.

We use the OPTION COPY statement to tell DFSORT to copy the records without sorting or merging them.

We use four IFTHEN clauses in the OUTREC statement; two for each ZD field.

  • The first IFTHEN clause uses WHEN=(4,5,ZD,EQ,NUM) to indicate that it applies only to records with a valid ZD value in positions four through eight. OVERLAY uses TO=ZDF to ensure positive ZD values have an F sign. HIT=NEXT tells DFSORT to continue to the next IFTHEN clause for this record even if this IFTHEN clause is satisfied. We need HIT=NEXT in each of the IFTHEN clauses (except the last) to let us continue to the next IFTHEN clause so we can check the field in positions four through eight and the field in positions 10 through 14 independently of each other. For example, without HIT=NEXT, since the R1 record has a valid ZD value in positions four through eight, which satisfies the first IFTHEN clause, processing for the R1 record would stop with the first IFTHEN clause. Thus, the invalid ZD value in positions 10 through 14 of the R1 record would never be found or corrected by the fourth IFTHEN clause. By using HIT=NEXT, we ensure both ZD fields are checked in each record.
  • The second IFTHEN clause uses WHEN=(4,5,ZD,NE,NUM) to indicate it applies only to records with an invalid ZD value in positions four through eight. OVERLAY changes the invalid ZD value to ‘00000’. HIT=NEXT tells DFSORT to continue to the next IFTHEN clause.
  • The third IFTHEN clause uses WHEN=(10,5,ZD,EQ,NUM) to indicate it applies only to records with a valid ZD value in positions 10 through 14. OVERLAY uses TO=ZDF to ensure positive ZD values have an F sign. HIT=NEXT tells DFSORT to continue to the next IFTHEN clause.
  • The fourth IFTHEN clause uses WHEN=(10,5,ZD,NE,NUM) to indicate it applies only to records with an invalid ZD value in positions 10 through 14. OVERLAY changes the invalid ZD value to ‘00000’. Since this is the last IFTHEN clause, we don’t need HIT=NEXT.

Figure 3 shows the output records with an F sign for each positive ZD value (for example, ‘12345’ = X’F1F2F3F4F5’) and ‘00000’ instead of each invalid value.

4 Pages