OUTREC Date Operations


The OUTREC statement can be used for performing various date-related operations, such as formatting current dates, calculating future or past dates, and converting dates from one format to another.

Converting date -


OUTREC statement can convert the date formats of a date field while sorting.

Syntax -

//SYSIN   DD  *
  OUTREC BUILD=(starting_pos_of_field1,
		field1_length,
		existing_date_field1_format, 
		conversion_operator=target_date_field1_formats,…)
/*
starting_pos_of_field1Specifies the starting byte of the numeric field in the record.
field1_lengthSpecifies the length of the numeric field.
existing_date_field1_formatSpecifies source date field formats.
  • Y4W and Y4T are two of DFSORT's 4-digit year date field formats.
  • Y4W indicates a date value with the year (ccyy) last such as 'mmddccyy' or 'dddccyy'.
  • Y4T indicates a date value with the year first such as 'ccyymmdd' or 'ccyyddd'.
  • Y2W and Y2T are two of DFSORT's 2-digit year date field formats.
  • Y2W indicates a date value with the year (yy) last such as 'mmddyy' or 'dddyy'.
  • Y2T indicates a date value with the year first such as 'yymmdd' or 'yyddd'.
  • The two formats can be represented in common as Y2X, Y4X.
  • X should be either W or T.
conversion_operatorSpecifies the keyword for target format operator. The below are the list of format operators -
  • TOJUL=YnX - converts to a julian date without a separator.
  • TOJUL=YnX(s) - converts to a julian date with a separator.
  • TOGREG=YnX - converts to a gregorian date without separators.
  • TOGREG=YnX(s) - converts to a gregorian date with separators.
  • WEEKDAY=CHAR3 - converts to a 3 character day of the week.
  • WEEKDAY=CHAR9 - converts to a 9 character day of the week.
  • WEEKDAY=DIGIT1 - converts to a 1 digit indicator for the day of the week.
target_date_field1_formatsSpecifies the target date field formats.

Examples -


Scenario1 - Converting Date from mmddccyy to ccyymmm.

//SYSIN    DD *
     SORT FIELDS=(1,5,CH,A)
     OUTREC FIELDS=(1,54,55,8,Y4W,TOJUL=Y4T)
/*

Converts data from 55th byte of length 8 will be converted to Y4T julian date format.

Scenario2 - Converting Date from mmddccyy to ccyymmm.

//SYSIN    DD *
     SORT FIELDS=(1,5,CH,A)
     OUTREC FIELDS=(1,54,55,8,Y4W,TOGREG=Y4T)
/*

Converts data from 55th byte of length 8 will be converted to Y4T gregorian date format.

Arithmetic operations on date -


OUTREC statement is used for arithmetic data operations on the date field while sorting.

Syntax -

//SYSIN   DD  *
  OUTREC BUILD=(starting_pos_of_field1,
		field1_length,
		existing_date_field1_format, 
		arithmetic operator,+n/-n,…)
/*
arithmetic_operator Specifies arithmetic operation to perform. The below are list of arithmetic operations used -
  • ADDDAYS, ADDMONS and ADDYEARS Used to add days, months or years to a date field.
  • SUBDAYS, SUBMONS and SUBYEARS Used to subtract days, months or years from a date field.
  • DATEDIFF Used to calculate the number of days between two date fields.
  • NEXTDday Used to calculate the next specified day of the week for a date field.
  • PREVDday Used to calculate the previous specified day of the week for a date.
  • LASTDAYW, LASTDAYM, LASTDAYQ and LASTDAYY Used to calculate the last day of the week, month, quarter or year for a date field.
+n/-n Specifies the number days/months/years used to perform an arithmetic operation

Examples -


Scenario1 - Adding a Date (Future Date).

//SYSIN   DD  *
  SORT FIELDS=COPY
  OUTREC FIELDS=(1,20,21:DATENS=(+30,Y4T))
/*

Adds a future date 30 days from today in YYYY-MM-DD format starting at position 21. If today is September 17, 2024, it will display 2024-10-17.

Scenario2 - Subtracting a Date (Past Date).

//SYSIN   DD  *
  SORT FIELDS=COPY
  OUTREC FIELDS=(1,20,21:DATENS=(-7,Y2T))
/*

Adds a date 7 days in the past from the current system date in YY/MM/DD format starting at position 21.