Easytrieve Internal Date Representation

External date formats—MMDDYY, CCYYMMDD, Julian YYDDD—exist so humans and legacy files can read calendar parts in digit positions. Internal date representation collapses a calendar position into one integer: typically the count of days before or after a fixed base date such as December 31, 1900. That encoding makes adding thirty days or comparing two dates a numeric operation instead of month-end logic with leap years scattered through IF blocks. Easytrieve batch programs often start with external N fields from COBOL files, then convert to internal packed values inside DATECALC, DATECONV, or installation date exit routines for arithmetic. This page explains internal versus external storage, packed P day-count fields, conversion boundaries, and how subsystem documentation describes ADD_DAYS and FROM_EXTERNAL patterns compatible with Easytrieve date processing ecosystems.

Progress0 of 0 lessons

External vs Internal: Two Layers

External display vs internal storage
AspectExternalInternal
PurposeHuman and file interchangeCalendar arithmetic
Typical typeN 6 or N 8 digit stringP or B integer day count
Example031585 MMDDYY30728 days from base (illustrative)
Add 30 daysNeeds conversion firstAdd 30 to integer
Report printDirect with MASKConvert out via DATECONV

Confusing layers causes subtle bugs: comparing FILE MMDDYY hire date to internal packed run date without conversion looks like IF logic works on some records and fails on others because byte patterns encode different meanings at the same numeric magnitude.

Day-Count Base Date Model

CA-family date modeling often defines day zero as December 31, 1900. January 1, 1901 becomes day 1; earlier calendar dates become negative integers. A five-digit internal field supports roughly 273 years of range from that base in related documentation examples. Easytrieve core DEFINE does not expose a separate D type letter like some IDEAL dataviews, but date routines and companion utilities consume the same day-count concept when converting external strings to packed internal values for ADD_DAYS style operations.

Packed Internal Date Fields

Internal dates frequently store as packed decimal P with zero decimal positions—four or seven byte examples appear in subsystem integration docs. P 7 0 holds seven-digit day magnitudes efficiently. Binary four-byte internal dates also appear in ADD_DAYS function signatures where FROM_DATE, DAYS, and RESULT_DATE are four-byte packed internal forms. Match byte length and packed layout to the routine you call—declaring internal date as N 7 display when file carries P 4 packed misaligns every subsequent field.

text
1
2
3
4
5
6
7
DEFINE EXT-HIRE W 8 N DEFINE INT-HIRE W 4 P 0 DEFINE INT-RUN W 4 P 0 DEFINE DAYS-SERV W 4 P 0 * After DATECONV external to internal: DAYS-SERV = INT-RUN - INT-HIRE

Conversion at the Boundary

Pattern: read external FILE date, validate with %DATEVAL and format literal, convert to internal with DATECONV or installation FROM_EXTERNAL equivalent, perform arithmetic, convert back for REPORT LINE external MASK display. SET_FORMAT or installation defaults tell conversion routines how to interpret character external literals like YYYY/MM/DD before FROM_EXTERNAL populates internal packed fields.

text
1
2
3
4
5
%DATEVAL EXT-HIRE MMDDCCYY IF DATEVAL-FLAG EQ 'YES' %DATECONV EXT-HIRE MMDDCCYY INT-HIRE P-int-format %DATECALC INT-HIRE int-fmt PLUS 30 EXT-DUE ext-fmt END-IF

Exact internal format parameter names depend on installed routine variants—consult site macro library. Concept remains: never add thirty to MMDDYY digits directly—month lengths forbid it.

DATECALC and Day Arithmetic

DATECALC adds or subtracts a day count from a formatted date field, writing another formatted field—not always exposing internal integers to application code. Internally the routine still applies calendar rules including month lengths and leap years. THRESHOLD governs century on two-digit external formats during calculation. Validate inputs with DATEVAL when feeds are untrusted—invalid February 30 should fail before arithmetic propagates garbage.

Julian vs Internal

Julian YYDDD external is not the same encoding as day-count internal though both feel numeric. Julian keeps year visible in digits; internal hides year into scalar offset. Converting Julian to internal requires DATECONV with YYDDD format literal, not manual multiplication of day-of-year by constants—which breaks across century and leap rules.

SYSDATE and Internal Run Date

SYSDATE and %GETDATE deliver external display form for titles. If job logic needs internal run date for aging calculations against internal stored customer open dates, add conversion step once after GETDATE: external run date to packed internal INT-RUN, then subtract internal invoice dates for days-past-due numeric comparisons without string parsing in every detail line.

Subsystem ADD_DAYS Pattern

CA-1 and related utilities document ADD_DAYS with four-byte packed internal FROM_DATE, DAYS, and RESULT_DATE. TO_EXTERNAL converts internal packed back to ten-byte character external with SET_FORMAT controlling separator pattern. Easytrieve programs participating in those ecosystems DEFINE compatible P 4 fields and call interfaces documented for the utility—not reimplement leap-year tables in PROC unless policy requires self-contained logic.

When to Stay External Only

  • Simple hire date reporting with overlays—no day arithmetic.
  • Files never converted—match COBOL PIC 9(6) exactly.
  • Sort using CCYYMMDD external eight-digit keys.
  • One-time DISPLAY debugging of file contents.

When Internal Pays Off

  • Aging buckets: current internal minus due internal compared to thresholds 30 60 90.
  • Accrual windows spanning month and year boundaries.
  • Repeated date math inside high-volume loops—convert once per record edge.
  • Integration with utilities expecting packed internal dates.

Common Internal Date Mistakes

  1. Subtracting MMDDYY digits as if internal day count.
  2. Wrong packed length on internal field—four vs seven bytes.
  3. Skipping DATEVAL on external feed before conversion.
  4. Mixing negative internal base-era dates with unsigned P definitions.
  5. Printing internal packed directly without DATECONV—unreadable totals on reports.

Explain It Like I'm Five

External date is writing March 15 on a calendar page. Internal date is counting how many days from a starting line you drew on a long strip of paper—day one, day two, thousands later. Adding thirty days on the strip means count thirty steps forward, which is easy. Adding thirty on the calendar page means crossing month ends and February rules—hard without a helper. Easytrieve helpers convert between the page view and the strip count.

Exercises

  1. Explain why INT-RUN minus INT-HIRE works but CURR-YY minus HIRE-YY fails near birthdays.
  2. Define four-byte packed P 0 internal date working storage fields.
  3. Sketch conversion flow from FILE MMDDCCYY to internal to plus 90 days back to external.
  4. Contrast Julian YYDDD with internal day-count encoding.
  5. List two scenarios staying external-only is sufficient.

Quiz

Test Your Knowledge

1. Internal date storage often uses:

  • Numeric day count or packed integer days from a base date
  • Alphabetic month names only
  • IEEE floating point
  • EBCDIC graphics

2. External date MMDDYY differs from internal because:

  • External is human layout; internal is single number for arithmetic
  • They are always identical bytes
  • Internal always has slashes
  • External cannot print

3. DATECALC adds days by:

  • Converting through format-aware calendar logic to a result field
  • Concatenating strings
  • Sorting files only
  • Changing JCL CLASS

4. Five-byte internal date value can represent roughly:

  • 273 years from base era per field modeling docs
  • One week only
  • Milliseconds
  • Hex colors

5. Before comparing internal and external dates you should:

  • Convert both to the same representation with DATECONV or routines
  • Compare bytes directly always
  • Use alphabetic GT
  • Skip validation
Published
Read time14 min
AuthorMainframeMaster
Reviewed by MainframeMaster teamVerified: Broadcom DATECALC DATECONV day arithmetic; CA internal date ADD_DAYS packed patternsSources: Broadcom Easytrieve 11.6 DATECALC DATECONV, CA-1 Date Processing, CA field modeling day-zero referenceApplies to: Easytrieve internal packed date storage and conversion