11 MAGEC-BEG-YR-DAYOFWK     PIC X.           11 MAGEC-END-YR-DAYOFWK     PIC X. Your program must be linked to include the MAGDATE subroutine in order for you to call it. (cont.) This is done in the link step of your compile jobstream. MAGDATE is found on the standard MAGEC library (loadlibrary, (cont.) relocatable library, VSE/SP sublibrary, or in the \MAGMF directory). ## Validating a Date The most basic function of the MAGDATE subroutine is date validation. You can pass it a date and a format specification (cont.) (telling it what format the date is in). It will return with a return code of spaces (MAGDATE-OK) or another value (cont.) indicating the type of error found in the date. You can also convert a date to another format, compare two dates to (cont.) determine how many days apart they are, or project the date any number of days before or after a given (cont.) date. To do this you should understand the possible values of both the return code (MAGEC-DATE-RETURN-CODE), and of the (cont.) format specification (MAGEC-DATE-FORMAT). Let us first examine the return codes**. The copybook includes (cont.) condition-names (88-levels) under MAGEC-DATE-RETURN-CODE, as described below. The copybook includes condition names to define the possible return code values. They are: value               condition-name               meaning blank               MAGDATE-OK               successful completion of the requested action, the given date is a valid date in the format specified. 01               INVALID-MAGEC-DATE-FORMAT               the format specification is not valid 02               NON-NUMERIC-JULIAN-DATE               input format was julian and the date given was not numeric 03               NON-NUMERIC-MO-DAY-OR-YR               input format was gregorian and one of the components was not numeric 04               INVALID-MONTH               month of input date was not 01 through 12 - or JAN thru DEC 05               INVALID-DAY-OF-MONTH               the day number is not valid within the month (consider leap years for Feb.) 06               INVALID-JULIAN-DAY               input format was julian and the day number is invalid in the year given 07               INVALID-THRU-DATE-FORMAT               date comparison or projection was requested and the thru-date format is not valid 08               NON-NUMERIC-JULIAN-THRU               date comparison of julian dates was requested and the thru-date is not valid 09               NON-NUMERIC-MDY-THRU               date comparison in gregorian was requested and the thru-date is not valid 10               INVALID-MONTH-THRU               date comparison was requested and the month of the thru-date is invalid 11               INVALID-DAY-OF-MONTH-THRU               date comparison was requested and the day of the thru-month is invalid 12               INVALID-JULIAN-DAY-THRU               date comparison was requested and the day number of the julian thru-date is invalid 20               NON-NUMERIC-NBR-DAYS               date projection was requested and the number of days is invalid The return code field is redefined as a numeric field (PIC 99) which is named: MAGEC-DATE-RETURN-CODE-N. This enables (cont.) you to use the error codes as a subscript into a table of descriptions if you wish. Be careful not to try to use the (cont.) good return code (blanks) as a subscript, however. The **format specifications** which you can give describe the format of the date you wish to have validated, compared, or projected. In the MAGEC-DATE-FORMAT field enter one of: MMDDYY MM/DD/YY MMDDCCYY MM/DD/CCYY DDMMYY DD/MM/YY DDMMCCYY DD/MM/CCYY YYMMDD YY/MM/DD CCYYMMDD CCYY/MM/DD DDMMMYY DD/MMM/YY DDMMMCCYY DD/MMM/CCYY YYMMMDD YY/MMM/DD CCYYMMMDD CCYY/MMM/DD CCYYDDD CCYY/DDD YYDDD YY/DDD BBBBBBBB (binary date) In the above format specifications you notice that you can specify dates with or without slashes. The format (cont.) specifications which include slashes actually describe a format in which slashes, or dashes, or spaces separate the (cont.) date components. Thus, in a date format of MM/DD/YY a date of 02-21-91 would be accepted as valid The format (cont.) specifications use mnemonic codes, i.e. MM               month, 2-digits DD               days, 2-digits YY               year, 2-digits CCYY               century + year, 4-digit year MMM               month abbreviation, 3-char. (English) DDD               julian day number BBBBBBBB               binary date in MAGEC-DATE-FROM-N These same format specifications are used when you request for date conversions or comparisons. In those cases you give a format specification in both MAGEC-DATE-FORMAT and MAGEC-DATE-THRU. The type of operation you request is determined by which of several of the fields within the request area you fill in, (cont.) and which you leave blank (or zero). MAGDATE actually does all possible operations for the given date and fills in all (cont.) of the returned date information regardless of what operation was requested. It is legal for the two input dates, MAGEC-DATE-FROM and MAGEC-DATE-THRU to be in different formats for comparisons or projections. ## Calling MAGDATE You can use MAGDATE to validate a single date in any of the formats supported, to compare two dates of the same or (cont.) different formats, or to project forward or backward a number of days from a given date. The type of operation is (cont.) determined by which portions of the request area you fill in and which portions you leave blank (or zero). MAGDATE (cont.) always sets the return code to indicate successful completion and that your input dates are valid or invalid. It also (cont.) fills in all of the MAGEC-RETURNED-DATE-INFO fields if the return code is blanks (MAGDATE-OK), those fields are filled (cont.) in with zeros if there was an error found in your input date. To do a simple date validation, code: MOVE SPACES TO MAGEC-DATE-REQUEST-AREA. **MOVE subject-date TO MAGEC-DATE-FROM. MOVE date-format TO MAGEC-DATE-FORMAT. CALL 'MAGDATE' USING MAGEC-DATE-REQUEST-AREA. IF (MAGDATE-OK)... In the above example "subject-date" is a dataname of a field containing the date to be validated, "date-format" is the (cont.) dataname of a field containing one of the valid format specifications describing the date being (cont.) edited. To do a date conversion you would code exactly the same as above since MAGDATE always fills in all of the other fields (cont.) in the request area. If MAGDATE-OK is true, you will have the Gregorian, Julian, and alpha-numeric date formats, plus (cont.) the day-of-week, period ending dates, and leap year flag set. A value of "Y" in MAGEC-LEAP-YEAR-CODE indicates that the (cont.) date is in a leap year. To compare two dates to see how many days apart they are, code: MOVE SPACES TO MAGEC-DATE-REQUEST-AREA. MOVE subject-date1 TO MAGEC-DATE-FROM. MOVE subject-date2 TO MAGEC-DATE-THRU. MOVE date-format1 TO MAGEC-DATE-FORMAT. MOVE date-format2 TO MAGEC-DATE-THRU-FORMAT. CALL 'MAGDATE' USING MAGEC-DATE-REQUEST-AREA. IF (MAGDATE-OK)... In the above example "subject-date1" is a dataname of a field containing one date, "subject-date2" is the dataname of a (cont.) field containing another date, "date-format1" is the dataname of a field containing a valid format specification (cont.) describing subject-date1's date, and "date-format2" is the dataname of the field containing subject-date2's date format (cont.) specification. Upon return from MAGDATE, if MAGDATE-OK is true, you will have all of the other fields of the request (cont.) area filled in and the field named MAGEC-PLUS-MINUS-DAYS will contain the number of days between the two dates. If the (cont.) thru-date is earlier than the from-date this value will be negative. *The date information and period ending (cont.) information will apply to the thru-date, not to the from-date.* To do a date projection, code: MOVE SPACES TO MAGEC-DATE-REQUEST-AREA. MOVE subject-date TO MAGEC-DATE-FROM. MOVE date-format1 TO MAGEC-DATE-FORMAT. MOVE date-format2 TO MAGEC-DATE-THRU-FORMAT. MOVE number-of-days TO MAGEC-PLUS-MINUS-DAYS. CALL 'MAGDATE' USING MAGEC-DATE-REQUEST-AREA. IF (MAGDATE-OK)... In the above example "subject-date" is the dataname of a field containing the date you wish to project from, (cont.) "date-format1" is the dataname of a field containing a format specifiction describing the date in subject-date, and (cont.) number-of-days is a numeric value between -99,999 and +99,999. MAGDATE will calculate the date projected either forward (cont.) or backward and place it into MAGEC-DATE-THRU in the format specified in "date-format2". ## Online Demo Next: https://magec.com/DOC/markdown/cstm16.md.txt