SAP HR Guide: Model Employee Records with Validity Periods

This content was generated with the assistance of AI and should be verified against the official documentation before being relied on in production.

Checked on 2026-11-13 against CAP Node.js 10.2 (@sap/cds 10.2.2, @sap/cds-dk 10.2.1), the Fiori elements preview of cds watch (SAPUI5 1.145.0), curl 8.7 and Node.js 24.21.

What you build

This is a teaching model built with CAP. It is not SAP S/4HANA or SAP SuccessFactors and does not reproduce their screens.

You build a small model of employee records that are valid for a period, the idea behind the infotypes of SAP HR. An organizational assignment and a basic pay record each have a begin date and an end date. They follow time constraint 1: exactly one record is valid on any day. A parking permit (a record of this model’s own, not an SAP infotype) follows time constraint 2: at most one record is valid, and gaps are allowed. When you add a record, the model sets the end date of the previous record to the day before the new begin date, which SAP calls delimiting. A record of time constraint 1 cannot be deleted, one of time constraint 2 can. You read the history of an employee in the browser and in a Fiori elements object page.

Fiori elements object page of the employee Ana Torres with the tabs General, Organizational Assignment, Basic Pay and Parking Permits: the table Organizational Assignment (2) shows the records from Mar 1, 2024 to Jun 30, 2026 in personnel subarea 0001 and from Jul 1, 2026 to Dec 31, 9999 in personnel subarea 0002, the table Basic Pay (1) shows 4,000.00 EUR monthly from Mar 1, 2024 and the table Parking Permits (1) shows the permit A-1 from Jan 1, 2025 to May 31, 2025

Before you start

  • No account is needed: the CAP tools and curl install without signing in. Installing @sap/cds-dk means accepting the SAP Developer License Agreement, version 3.2, which the lab README names.

  • Do the guide Your First CAP Service first (it explains cds init, CDS files, CSV data and cds watch) and, for the object page, the guide Add a Fiori Elements App to a CAP Service.

  • Read Infotypes, Time Constraints and Validity Periods and HR and Payroll Basics for the ideas that the model copies.

  • You need curl 7.82 or newer, which has the option --json. curl --version prints the version.

  • The example is the one of the HR pages: Example Trading Co., personnel area EX01, and the employees Ana Torres 00001234, Ben Okoye 00001235 and Chloe Martin 00001236. All codes and dates are invented example values, not values delivered by SAP. Dates in the model are written YYYY-MM-DD, as in code; the SAP screens of the reference pages show DD.MM.YYYY, so 01.07.2026 is 2026-07-01. The high date 31.12.9999 is 9999-12-31.

  • The change you make to Ana’s organizational assignment, from 01.07.2026, extends the example: it moves her from personnel subarea 0001 to 0002, and the reason is made up. The parking permits also extend the example.

  • The figures are drawings of the editor, the terminal, the browser and the Fiori pages, not screenshots. A highlighted box with a number marks the file, the line or the page part of the step with the same number.

Steps

Create the project and model the records

  1. Create a CAP project named people and install it, as in the first guide:

    cds init people --nodejs
    cd people
    npm install
  2. Create db/schema.cds. Employees holds one row per personnel number. Each record entity has the employee and the BeginDate as its key, so an employee can have many records, told apart by their begin date, and an EndDate that defaults to the high date 9999-12-31, a record without a planned end. The comments say which time constraint each entity follows.

    namespace sap.guide.people;
    
    // A teaching model of infotype-style employee records, not SAP S/4HANA and not
    // SAP SuccessFactors. Names, numbers and dates are invented example values.
    entity Employees {
      key PersonnelNumber : String(8);
      Name                : String(40);
      EntryDate           : Date;
      OrgAssignments      : Composition of many OrganizationalAssignments
                              on OrgAssignments.Employee = $self;
      BasicPay            : Composition of many BasicPayRecords
                              on BasicPay.Employee = $self;
      ParkingPermits      : Composition of many ParkingPermits
                              on ParkingPermits.Employee = $self;
    }
    
    // Time constraint 1: exactly one record is valid at any time.
    entity OrganizationalAssignments {
      key Employee      : Association to Employees;
      key BeginDate     : Date;
      EndDate           : Date default '9999-12-31';
      PersonnelArea     : String(4);
      PersonnelSubarea  : String(4);
      EmployeeGroup     : String(1);
      EmployeeSubgroup  : String(2);
      Position          : String(8);
      PayrollArea       : String(2);
    }
    
    // Time constraint 1 as well.
    entity BasicPayRecords {
      key Employee  : Association to Employees;
      key BeginDate : Date;
      EndDate       : Date default '9999-12-31';
      PayBasis      : String(10);
      Amount        : Decimal(9,2);
      Currency      : String(3) default 'EUR';
    }
    
    // Time constraint 2: at most one record is valid at any time; gaps are allowed.
    // A record of the model's own, not an SAP infotype.
    entity ParkingPermits {
      key Employee  : Association to Employees;
      key BeginDate : Date;
      EndDate       : Date default '9999-12-31';
      Permit        : String(10);
    }
    Visual Studio Code with the file db/schema.cds of the people project: an excerpt with the comment Time constraint 1 and the entity OrganizationalAssignments, whose key is the employee and the begin date and which has an end date that defaults to 9999-12-31; callout 2 marks the file in the explorer
  3. Create the four CSV files in db/data. They hold the three employees with one open-ended organizational assignment and basic pay record each (Ana 4,000.00 EUR a month, Ben 2,400.00 EUR a month, Chloe 14.00 EUR an hour) and one parking permit of Ana from 2025-01-01:

    PersonnelNumber,Name,EntryDate
    00001234,Ana Torres,2024-03-01
    00001235,Ben Okoye,2024-09-01
    00001236,Chloe Martin,2025-01-15
    Employee_PersonnelNumber,BeginDate,EndDate,PersonnelArea,PersonnelSubarea,EmployeeGroup,EmployeeSubgroup,Position,PayrollArea
    00001234,2024-03-01,9999-12-31,EX01,0001,1,AA,51000001,E1
    00001235,2024-09-01,9999-12-31,EX01,0001,1,AA,51000002,E1
    00001236,2025-01-15,9999-12-31,EX01,0002,1,AB,51000003,E1
    Employee_PersonnelNumber,BeginDate,EndDate,PayBasis,Amount,Currency
    00001234,2024-03-01,9999-12-31,Monthly,4000.00,EUR
    00001235,2024-09-01,9999-12-31,Monthly,2400.00,EUR
    00001236,2025-01-15,9999-12-31,Hourly,14.00,EUR
    Employee_PersonnelNumber,BeginDate,EndDate,Permit
    00001234,2025-01-01,9999-12-31,A-1

Write the delimitation rules

  1. Create srv/people-service.cds. It exposes the four entities as an OData service:

    using { sap.guide.people as db } from '../db/schema';
    service PeopleService {
      entity Employees                  as projection on db.Employees;
      entity OrganizationalAssignments  as projection on db.OrganizationalAssignments;
      entity BasicPayRecords            as projection on db.BasicPayRecords;
      entity ParkingPermits             as projection on db.ParkingPermits;
    }
  2. Create srv/people-service.js. The function delimitOnCreate runs before a record is created. It looks up the latest record of the employee. A new record must begin after it. If the latest record is still valid on the new begin date, its end date is set to the day before, and the service issues a message. This is the delimitation of time constraint 1 and 2. The second block makes the difference between the two constraints: a record of time constraint 1 must exist at all times, so deleting one is rejected.

    import cds from '@sap/cds'
    
    const HIGH_DATE = '9999-12-31'
    
    // The day before a date, as YYYY-MM-DD (UTC, so daylight saving time cannot
    // move the date).
    const dayBefore = (date) => {
      const d = new Date(`${date}T00:00:00Z`)
      d.setUTCDate(d.getUTCDate() - 1)
      return d.toISOString().slice(0, 10)
    }
    
    export default class PeopleService extends cds.ApplicationService {
      init() {
        const { OrganizationalAssignments, BasicPayRecords, ParkingPermits } =
          this.entities
        const timeConstraint1 = [OrganizationalAssignments, BasicPayRecords]
        const timeConstraint2 = [ParkingPermits]
    
        // Creating a record ends the record that is valid on its start date: the
        // end date of the old record becomes the new start date minus one day.
        const delimitOnCreate = (entity) => async (req) => {
          const record = req.data
          const who = record.Employee_PersonnelNumber
          record.EndDate ??= HIGH_DATE
          if (record.EndDate < record.BeginDate) {
            return req.error(400, 'The end date must not be before the begin date',
              'in/EndDate')
          }
          const latest = await SELECT.one.from(entity)
            .where({ Employee_PersonnelNumber: who })
            .orderBy('BeginDate desc')
          if (!latest) return
          if (record.BeginDate <= latest.BeginDate) {
            return req.error(400,
              `A record from ${latest.BeginDate} already exists; add records after it`,
              'in/BeginDate')
          }
          if (latest.EndDate >= record.BeginDate) {
            const end = dayBefore(record.BeginDate)
            await UPDATE(entity).set({ EndDate: end })
              .where({ Employee_PersonnelNumber: who, BeginDate: latest.BeginDate })
            req.info(`The record from ${latest.BeginDate} was delimited to ${end}`)
          }
        }
        for (const entity of [...timeConstraint1, ...timeConstraint2]) {
          this.before('CREATE', entity, delimitOnCreate(entity))
        }
    
        // Time constraint 1: a record must exist at all times, so it cannot be
        // deleted.
        for (const entity of timeConstraint1) {
          this.before('DELETE', entity, (req) =>
            req.error(400, 'A record with time constraint 1 cannot be deleted'))
        }
    
        return super.init()
      }
    }
    Visual Studio Code with the file srv/people-service.js: the excerpt looks up the latest record of the employee, rejects a begin date that is not after it, and otherwise sets the end date of the old record to the day before the new begin date and issues a message; callout 5 marks the file in the explorer

Start the service and add records

  1. In the terminal, in the project folder, start the server. The log shows the four CSV files loaded and PeopleService served at /odata/v4/people with the implementation srv/people-service.js.

    cds watch
    Terminal after cds watch in the people project: the log lists the model files, loads the four CSV files into an in-memory SQLite database, serves PeopleService at /odata/v4/people with the implementation srv/people-service.js and ends with server listening on http://localhost:4004; callout 6 marks the command
  2. Create the folder http and in it new-assignment.json, Ana’s new organizational assignment from 2026-07-01:

    {
      "Employee_PersonnelNumber": "00001234",
      "BeginDate": "2026-07-01",
      "PersonnelArea": "EX01",
      "PersonnelSubarea": "0002",
      "EmployeeGroup": "1",
      "EmployeeSubgroup": "AA",
      "Position": "51000001",
      "PayrollArea": "E1"
    }

    Open a second terminal in the project folder and post it. The option --json sets the content type; -i prints the response headers, and grep keeps the status line and the message header:

    curl -s -i --json @http/new-assignment.json http://localhost:4004/odata/v4/people/OrganizationalAssignments | grep -E "^(HTTP|sap-messages)"

    The answer is HTTP/1.1 201 Created and a message: The record from 2024-03-01 was delimited to 2026-06-30. The service ended Ana’s first record on the day before the new one began.

  3. Do the same for the parking permit, time constraint 2. Create http/new-permit.json, a permit B-2 from 2025-06-01, and post it to ParkingPermits. The message is The record from 2025-01-01 was delimited to 2025-05-31.

    {
      "Employee_PersonnelNumber": "00001234",
      "BeginDate": "2025-06-01",
      "Permit": "B-2"
    }
    curl -s -i --json @http/new-permit.json http://localhost:4004/odata/v4/people/ParkingPermits | grep -E "^(HTTP|sap-messages)"
    Terminal with two curl commands that post a new organizational assignment from 2026-07-01 and a new parking permit from 2025-06-01: each answers HTTP/1.1 201 Created and an sap-messages header that says the old record was delimited, to 2026-06-30 for the assignment (callout 7) and to 2025-05-31 for the permit (callout 8)
  4. Read the history of Ana’s organizational assignment. Open http://localhost:4004/odata/v4/people/Employees('00001234')/OrgAssignments?$select=BeginDate,EndDate&$orderby=BeginDate in the browser. There are two records, from 2024-03-01 to 2026-06-30 and from 2026-07-01 to 9999-12-31. They touch and never overlap: on every day since the hiring, exactly one record is valid. This is time constraint 1.

    Browser with the address of the organizational assignments of the employee 00001234 in the order of the begin date, marked by callout 9: the JSON response holds two records, from 2024-03-01 to 2026-06-30 and from 2026-07-01 to 9999-12-31, without a gap between them
  5. Try to delete Ana’s basic pay record. The service answers A record with time constraint 1 cannot be deleted with HTTP 400, because a basic pay record must exist at all times. To end such a record, you create a new one that replaces it.

  6. Delete the parking permit B-2 instead. The answer is HTTP 204, no content: a record of time constraint 2 may be deleted. Ana’s first permit stays delimited to 2025-05-31, so from 2025-06-01 she has no permit, a gap that time constraint 2 allows.

    curl -s -w "\nHTTP %{http_code}\n" -X DELETE "http://localhost:4004/odata/v4/people/BasicPayRecords(Employee_PersonnelNumber='00001234',BeginDate=2024-03-01)"
    curl -s -w "HTTP %{http_code}\n" -X DELETE "http://localhost:4004/odata/v4/people/ParkingPermits(Employee_PersonnelNumber='00001234',BeginDate=2025-06-01)"
    Terminal with two curl commands that delete a record: the delete of the basic pay record is answered with the message A record with time constraint 1 cannot be deleted and HTTP 400 (callout 10), the delete of the parking permit is answered with HTTP 204 (callout 11)

Show the history in a Fiori elements page

  1. Create app/annotations.cds. The first part gives the fields their labels. The second builds a list report of employees and an object page with one section per record entity, each a table of the history:

    using PeopleService as service from '../srv/people-service';
    
    annotate service.Employees with {
      PersonnelNumber @title : 'Personnel Number';
      Name            @title : 'Name';
      EntryDate       @title : 'Entry Date';
    };
    annotate service.OrganizationalAssignments with {
      BeginDate        @title : 'Valid From';
      EndDate          @title : 'Valid To';
      PersonnelArea    @title : 'Personnel Area';
      PersonnelSubarea @title : 'Personnel Subarea';
      EmployeeSubgroup @title : 'Employee Subgroup';
      Position         @title : 'Position';
    };
    annotate service.BasicPayRecords with {
      BeginDate @title : 'Valid From';
      EndDate   @title : 'Valid To';
      PayBasis  @title : 'Pay Basis';
      Amount    @title : 'Amount';
      Currency  @title : 'Currency';
    };
    annotate service.ParkingPermits with {
      BeginDate @title : 'Valid From';
      EndDate   @title : 'Valid To';
      Permit    @title : 'Permit';
    };
    
    annotate service.Employees with @(
      UI.LineItem : [{ Value : PersonnelNumber }, { Value : Name }, { Value : EntryDate }],
      UI.HeaderInfo : { TypeName : 'Employee', TypeNamePlural : 'Employees', Title : { Value : Name } },
      UI.Facets : [
        { $Type : 'UI.ReferenceFacet', Label : 'General', Target : '@UI.FieldGroup#General' },
        { $Type : 'UI.ReferenceFacet', Label : 'Organizational Assignment', Target : 'OrgAssignments/@UI.LineItem' },
        { $Type : 'UI.ReferenceFacet', Label : 'Basic Pay', Target : 'BasicPay/@UI.LineItem' },
        { $Type : 'UI.ReferenceFacet', Label : 'Parking Permits', Target : 'ParkingPermits/@UI.LineItem' }
      ],
      UI.FieldGroup #General : { Data : [{ Value : PersonnelNumber }, { Value : Name }, { Value : EntryDate }] }
    );
    annotate service.OrganizationalAssignments with @(
      UI.LineItem : [{ Value : BeginDate }, { Value : EndDate }, { Value : PersonnelSubarea }, { Value : EmployeeSubgroup }, { Value : Position }]
    );
    annotate service.BasicPayRecords with @(
      UI.LineItem : [{ Value : BeginDate }, { Value : EndDate }, { Value : PayBasis }, { Value : Amount }, { Value : Currency }]
    );
    annotate service.ParkingPermits with @(
      UI.LineItem : [{ Value : BeginDate }, { Value : EndDate }, { Value : Permit }]
    );
  2. Open http://localhost:4004/$fiori-preview/PeopleService/Employees?sap-language=EN#preview-app. The list report Employees (3) shows the three employees. The model has no drafts, so there is no Create button.

    Fiori elements list report Employees (3) with the columns Personnel Number, Name and Entry Date: Ana Torres 00001234 entered on Mar 1, 2024, Ben Okoye 00001235 and Chloe Martin 00001236; callout 13 marks the row of Ana Torres
  3. Click Ana Torres. The object page shows the tables of the history: Organizational Assignment (2) with the two records of step 9, Basic Pay (1) with 4,000.00 EUR a month, and Parking Permits (1) with the permit A-1, valid from Jan 1, 2025 to May 31, 2025. The preview prints the dates as Mar 1, 2024 and Dec 31, 9999.

Check the result

  • The two posts of steps 7 and 8 answer HTTP/1.1 201 Created with a delimitation message each.

  • The history of step 9 has no gap and no overlap.

  • The delete of the basic pay record answers HTTP 400, the delete of the permit HTTP 204.

  • The object page of Ana Torres shows Organizational Assignment (2).

Variations

  • Post an organizational assignment for Ana with a begin date before 2026-07-01, for example 2026-01-01. The service answers A record from 2026-07-01 already exists; add records after it. The model only adds records after the latest one; SAP also lets you insert a record in the middle of the history, which this model leaves out.

  • Post a record whose EndDate is before its BeginDate. The service answers The end date must not be before the begin date.

What can go wrong

Symptom Cause Fix

A record from 2026-07-01 already exists; add records after it and HTTP 400

The new begin date is not after the begin date of the latest record.

Use a begin date after the latest record.

A record with time constraint 1 cannot be deleted and HTTP 400

You deleted a basic pay or organizational assignment record.

Add a new record instead; deleting is only possible for time constraint 2 records such as the parking permit.

The end date must not be before the begin date and HTTP 400

The EndDate of the new record is earlier than its BeginDate.

Correct the dates.

Clean up

Press Ctrl+C in the terminal that runs cds watch. The database lives only in memory, so your changes are gone at the next start; the CSV files bring back the starting data.