Supported RPG Features

The EXTRCT opcode extracts a single component from a date, time, or timestamp field into a numeric result field. It is a fixed-format C-spec operation:

C                   EXTRCT    source:*Code  result

Factor 1 is always blank. Factor 2 contains the source field name and extraction code separated by a colon. The result is a numeric field that receives the extracted integer value.

C                   EXTRCT    myDate:*Y     myYear         // extract year (e.g. 2024)
C                   EXTRCT    myDate:*M     myMonth        // extract month (e.g. 7)
C                   EXTRCT    myDate:*D     myDay          // extract day (e.g. 15)
C                   EXTRCT    myTime:*H     myHour         // extract hour (e.g. 14)
C                   EXTRCT    myTime:*MN    myMin          // extract minute (e.g. 30)
C                   EXTRCT    myTime:*S     mySec          // extract second (e.g. 45)
C                   EXTRCT    myTs:*MSECONDS myMs          // extract microseconds (e.g. 123456)

The same duration codes as ADDDUR/SUBDUR apply - the code must be compatible with the source field type (e.g. *HOURS is not valid for a date field). Despite its name, *MSECONDS (short form *MS) extracts microseconds - the timestamp's 6-digit fractional-second value (so .123456 yields 123456). The free-format equivalent is %SUBDT.

The (E) operation extender traps extraction errors, setting %ERROR / %STATUS instead of throwing (and clearing the error state on a subsequent successful (E) operation).