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_field1 | Specifies the starting byte of the numeric field in the record. |
field1_length | Specifies the length of the numeric field. |
existing_date_field1_format | Specifies source date field formats.
|
conversion_operator | Specifies the keyword for target format operator.
The below are the list of format operators -
|
target_date_field1_formats | Specifies 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 -
|
+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.