When is the DFT keyword in PF used?

  • Home
  • /
  • Blog
  • /
  • When is the DFT keyword in PF used?

September 25, 2011

When is the DFT keyword in PF used?

By NickLitten

September 25, 2011

DFT, keyword

The DFT Keyword is used to specify the default value of a field in the Physical File. The format of the keyword is:

DFT('value' | numeric-value | X'hexadecimal-value' | *NULL)

Without this keyword, character and hexadecimal fields are set to blanks as default and numeric fields are set to zeros as default.

However, if you specify the ALWNULL keyword for the field, then the character, hexadecimal, and numeric fields are set to the null value as default.

This keyword does not affect the physical file on input operations.

Example

The following example shows how to specify the DFT keyword.

dds

If you want to copy/paste the DDS source code grab this:

** SAMPLE DDS FOR PHSYICAL FILE WITH VARIOUS FIELD TYPES
R RECORD1
  CHARFLD1      20A          DFT('SAMPLE FIELD')
  CHARFLD2       5A          DFT(X'D985955185')
  HEXFLD1        3H          DFT('ABC')
  HEXFLD2        3H          DFT(X'C1C2C3')
  NUMFLD1        5S 0        DFT(99999)
  NUMFLD2        5S 2        DFT(999.99)
  NUMFLD3        5S 2        DFT(999)
  NUMFLD4        5S 2        DFT(*NULL) ALWNULL
  NUMFLD5        5S 2        DFT(999.99) ALWNULL
  DATFLD1         L          DATFMT(*MDY)
                             DATSEP('-')
                             DFT('12-31-91')
  TIMFLD1         T          DFT('11.15.00')
  TIMESTAMP       Z 
  
  • For the date (L) data type, the format specified on the DATFMT keyword dictates the length of the field. If you do not specify the DATFMT keyword, then the format is set to *ISO as default, which has a field length of 10. If you specify DATFMT(*JOB), the field length will always be 10, even if the Job Date Format Definition Attribute displays an 8 character date.
  • For the time (T) data type, the format specified on the TIMFMT keyword dictates the length of the field. All formats for the TIMFMT keyword, including the default of *ISO, have field lengths of 8.
  • For the timestamp (Z) data type, the field length is 26. The format of a timestamp field isyyyy-mm-dd-hh.mm.ss.mmmmmmWhere yyyy = year, mm = month, dd = day, hh = hour, mm = minute, ss = second, and mmmmmm = microsecond.

What about those DEFAULT Values?

  • The default value for CHARFLD1 is ‘Sample field’.
  • The default value for CHARFLD2 is hex D985955185.
  • The default value for HEXFLD1 is C1C2C3 (the hexadecimal representation of the character constant).
  • The default value for HEXFLD2 is C1C2C3.
  • The default value for NUMFLD1 is 99999 (no decimal character is required because the field has zero decimal positions).
  • The default value for NUMFLD2 is 999.99.
  • The default value for NUMFLD3 is 999 (no decimal character is required if you do not need to specify decimal values).
  • The default value for NUMFLD4 is the null value (ALWNULL is a required keyword for the field if DFT(*NULL) is specified).
  • The default value for NUMFLD5 is 999.99; the field also allows the null value.
  • The default value for DATFLD1 is 12-31-91.
  • The default value for TIMFLD1 is 11.15.00 (*ISO format).

You big silly.

Isn’t it obvious?

Now you feel silly for googling that right?


UPDATE DEC 2020: responding to a comment from Gabriel 😉

  • No, because it doesn’t work out of the box in an RPGLE program. Never has without special coding. (Unless I’m missing something and that’s always a possibility.)

    • You cannot use a DFT or INZ value to populate a field in DDS… so we normally just handle the population of the values in the program that is WRITING the data to the file.

      For example in RPGLE:
      date_field = %date();
      time_field=%time();
      timestamp_field=%timestamp();

      Or if you are using SQL just use the DEFAULT option… in fact I will record a quick video showing you how and update this blog 😉

  • {"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}

    Join the IBM i Community for FREE Presentations, Lessons, Hints and Tips

    >