HR_HK_DIFF_BT_2_DATES — Hong Kong Date Difference Function Module
HR_HK_DIFF_BT_2_DATES is a Hong Kong country-specific (molga 25) function module that calculates the difference between two dates for use inside Hong Kong payroll and time schemas, typically to support statutory calculations such as continuous service length, notice period, or leave proration. It is not released for general customer use, so SAP gives no interface stability guarantee outside its intended country-specific context.
This page covers HR_HK_DIFF_BT_2_DATES, a Hong Kong payroll support function module used to compute date differences for Employment Ordinance related calculations. It focuses on how the module is actually invoked inside schemas and custom reports, what the exception handling really protects against, and the operational mistakes that surface when it is called outside its intended country context.
Published 16 Sept 2026· 1,148 words
What it does
HR_HK_DIFF_BT_2_DATES sits in the Hong Kong country-specific payroll and time evaluation stack (molga 25) inside SAP HCM. Its job is to return the elapsed period between two calendar dates in a form that Hong Kong payroll schemas and personnel calculation rules can use directly, most often for length-of-service based entitlements under the Hong Kong Employment Ordinance: continuous contract testing, severance and long-service payment eligibility, notice period calculation, and pro-rated annual leave. It is not a generically released function module. Like most HR_XX_ prefixed function modules, it ships as an internal building block for the country payroll driver and associated reports rather than as a supported public API, so it carries no release contract and no guarantee that its interface stays unchanged across support packages or releases.
Parameters
Exact parameter names for this function module are not part of any generally published interface and should be confirmed directly in SE37 before coding against it, since HR_XX_ country function modules are not documented outside the payroll schema context. Based on its naming and typical pattern for this family of date-difference modules, the interface can be expected to include the following roles.
- An importing parameter for the earlier of the two dates, normally in the internal YYYYMMDD date format used throughout HR tables
- An importing parameter for the later date, compared against the first
- Possibly an importing flag or indicator controlling whether the result is calculated as pure calendar days or as completed months and years, relevant to how Hong Kong continuous-service rules count time
- One or more exporting parameters returning the computed difference, likely split into years, months, and days rather than a single total, mirroring other HR date-diff utilities
- No confirmed table or structure parameters; if the module returns a structure rather than scalar fields, that structure name must also be verified in SE37 rather than assumed
Exceptions
Country-specific HR date modules of this kind typically raise an exception when the two input dates are invalid (not real calendar dates, or blank) and another when the end date falls before the start date, since a negative difference has no meaning for a service-length calculation. If either exception is defined and left unhandled or swallowed with a blanket sy-subrc check that ignores the value, the calling schema or report proceeds with whatever the exporting parameters held before the call, or with initial values, which silently produces a zero or wildly wrong service period. In payroll this is dangerous because a wrong continuous-service duration feeds directly into severance, long-service payment, or leave accrual wage types without any runtime error, so the fault only appears later as a wrong payment or an audit discrepancy, not as a dump.
- Invalid date exception: one or both dates are not valid calendar dates or are initial; treat as a hard stop, do not default to today's date
- End date before start date exception: signals a data entry or master data sequencing error upstream, most often a wrong action date or infotype record overlap
- Any generic OTHERS branch: masks which of the above occurred; log the actual return code before deciding how to proceed
How to call it safely
Call it with both dates already converted to the internal HR date format, never with external DD.MM.YYYY strings, since HR function modules assume the internal representation used across infotypes. Check the return code or exception branch immediately after the call rather than assuming success, and inspect the exporting fields for plausibility, particularly that the returned duration is non-negative and consistent with the input dates, before passing it into any wage type or eligibility check. Because this module is not released, wrap the call in a small local wrapper function so that if the interface changes in a later support package the fix is contained to one place instead of scattered across custom reports and schema rules.
ECC vs S/4HANA
This function module belongs to the on-premise SAP HCM payroll and time evaluation stack and behaves the same whether that stack runs under classic ECC or under S/4HANA with the on-premise HCM component. There is no Fiori app or side-by-side successor for it, and SuccessFactors Employee Central for Hong Kong does not use this on-premise object at all, it applies its own leave and service calculations in the cloud. Because the module is not released, any custom code calling it directly outside a SAP-delivered schema or PCR context should be treated as a clean-core risk item during an S/4HANA move and flagged for review rather than migrated unchanged.
Common pitfalls
Most incidents involving this module trace back to using it outside the Hong Kong payroll context it was written for.
- Calling it for employees in a different personnel country grouping and assuming the date arithmetic matches local statutory rules, when the underlying logic encodes Hong Kong-specific counting conventions
- Passing dates in external display format instead of the internal HR date format, producing a technically valid but meaningless difference
- Reusing the same working variables across a loop over multiple employees without clearing the exporting fields between calls, so a failed call for one employee silently carries forward the previous employee's result
- Assuming the module counts calendar days when it may in fact return completed months and years, leading to leave or severance amounts that are off by a rounding convention nobody checked
- Treating the module as RFC-callable or stable across releases because it is easy to find via SE37, when it has no release contract and can change without notice
Whose problem this is
Ownership sits with the Hong Kong payroll or time management functional consultant who maintains the country-specific schemas and personnel calculation rules, working together with an ABAP developer when the module is called from custom reports rather than standard schemas. This is not a Basis or technical-infrastructure issue; incorrect results point to a schema logic, PCR configuration, or master data sequencing problem in the Hong Kong payroll build.
Related SAP objects
Reviewed pages this object connects to in the ERPClimb knowledge graph.
Source: ERPClimb — https://erpclimb.com/sap-function-modules/hr-hk-diff-bt-2-datesERPClimb is an independent platform and is not affiliated with SAP SE. Reference pages are written and reviewed by SAP consultants for learning and troubleshooting.