## 4.2.15.4  Factory Calendar
Get an overview of the ABAP classes, interfaces, and methods you can use to access calendar-related information.
The calendar system comprises the definition of the following categories:
- Public holidays
- Holiday calendars (a collection of public holidays)
- Factory calendars
A factory calendar is based on a country-specific holiday calendar and defines which days are working days, for example, Monday to Friday, and location-specific rules.
Read on to learn about the set of data we deliver for these categories.
##  Note
Class CL\_SCAL\_API is still available, but deprecated. We recommend that you use class CL\_FHC\_CALENDAR\_RUNTIME and the related interfaces IF\_FHC\_FCAL\_RUNTIME , IF\_FHC\_HCAL\_RUNTIME and IF\_FHC\_HOLIDAY\_RUNTIME instead. Furthermore, the CDS views from the section Accessing Holiday and Factory Calendar Tables Using VDM-Compliant CDS Views [page 1349] can be used to get an overview of existing factory- and holiday calendars. For information about the mapping between SCAL-relevant IDs and FHC-relevant IDs, see the corresponding section below.
## Creating a Runtime to Access Calendar-Related Information
Use class CL\_FHC\_CALENDAR\_RUNTIME that contains the following list of methods to create a runtime for holidays, holiday calendars, and factory calendar:
## Method
## Description
| create_factorycalendar_runtime   | Provides a factory calendar runtime   |
|----------------------------------|---------------------------------------|
| create_holidaycalendar_runtime   | Provides a holiday calendar runtime   |
| create_holiday_runtime           | Provides a holiday runtime            |
## 
```
Sample Code try. data(lo_fcal_run) = cl_fhc_calendar_runtime=>create_factorycalendar_runtime ( iv_factorycalendar_id = 'ExampleID' ). catch cx_fhc_runtime into data(lx_err). "exception handling endtry.
```
## Reading Factory Calendar-Related Information
Use the before created runtime to access the following list of methods provided in the interface IF\_FHC\_FCAL\_RUNTIME to get information about the factory calendar:
Method
| convert_date_to_factorydate    | Converts a date to a factory date                       |
|--------------------------------|---------------------------------------------------------|
| convert_factorydate_to_date    | Converts a factory date to a date                       |
| get_last_factorydate           | Provides the last factory date of the calendar          |
| calc_workingdays_between_dates | Calculates the number of working days between two dates |
| add_workingdays_to_date        | Adds working days to a date                             |
| subtract_workingdays_from_date | Subtracts working days to a date                        |
| get_validity_start             | Provides the first valid date                           |
| get_validity_end               | Provides the last valid date                            |
| is_date_workingday             | Check if a weekday is a working day                     |
| is_holiday_workingday          | Check if holiday is a working day                       |
| get_description                | Provides the description of the calendar                |
| get_hcal_assignment            | Provides the assigned holiday calendar runtime          |
| get_id                         | Provides the ID of the factory calendar                 |
## 
```
Sample Code
```
```
try. data(lv_date) = lo_fcal_run->convert_factorydate_to_date(
```
```
iv_factorydate = '123' ). catch cx_fhc_runtime into data(lx_run_err). "exception handling endtry.
```
## Reading Holiday Calendar-Related Information
Use the before created runtime to access the following list of methods provided in the interface IF\_FHC\_HCAL\_RUNTIME to get information about the holiday calendar:
Description
| Method                      | Description                                             |
|-----------------------------|---------------------------------------------------------|
| is_holiday                  | Check if a date is a holiday                            |
| get_holiday                 | Provides the assigned holiday for a date                |
| calc_holidays_between_dates | Calculates the number of holidays between two dates     |
| get_validity_start          | Provides the first valid date                           |
| get_validity_end            | Provides the last valid date                            |
| get_description             | Provides the description of the calendar                |
| get_holiday_assignments     | Get the assigned holidays from current holiday calendar |
| get_id                      | Provides the ID of the holiday calendar                 |
## Reading Holiday-Related Information
Use the before created runtime to access the following list of methods provided in the interface IF\_FHC\_HOLIDAY\_RUNTIME to get information about the holidays:
| Method         | Description                                                              |
|----------------|--------------------------------------------------------------------------|
| get_holiday_id | Provides the ID of the holiday                                           |
| get_type       | Provides the type of the holiday                                         |
| get_class      | Provides the class of the holiday                                        |
| get_confession | Provides the confession of the holiday                                   |
| get_text       | Provides the title and description of the holiday in a specific language |
## Mapping between SCAL-relevant IDs and FHC-relevant IDs
Class CL\_FHC\_CALENDAR\_RUNTIME uses longer IDs (32 digits) than the deprecated class CL\_SCAL\_API , which had only two-digit IDs for the factory calendars and holiday calendars, and three-digit IDs for the public holidays (also referred to as legacy IDs). The longer IDs make it easier to categorize calendar data.
To enable the use of the above mentioned runtimes, it may be necessary that an application establishes a connection between a legacy two-digit ID (as formerly used with CL\_SCAL\_API ) and a longer ID that the newer class CL\_FHC\_CALENDAR\_RUNTIME uses.
You can do such a mapping using the interface IF\_FHC\_ID\_MAPPER and class CL\_FHC\_CALENDAR\_ID\_MAPPER . The mapping is available for holidays, holiday calendars, and factory calendars.
The CL\_FHC\_CALENDAR\_ID\_MAPPER class returns an ID mapper instance. Subsequently, you can use the methods provided by the interface IF\_FHC\_ID\_MAPPER to perform the desired mappings.
##  Caution
It can't be guaranteed that the 2-digit legacy ID will point to the same calendar on each system. The 2-digit legacy ID should only be used if applications have already used CL\_SCAL\_API , stored the 2-digit legacy ID and have not yet migrated to the new APIs and IDs. The 2-digit legacy IDs are only intended for the transition phase.
We recommend using and saving the new 32-digit IDs on the application side. The whole functionality is optimized for using the new 32-digit ID.
## Creating an ID Mapper Instance
## Method
## Description
| create_id_mapper   | Provides an ID mapper instance   |
|--------------------|----------------------------------|
##  Sample Code
data(lo\_id\_mapper) = cl\_fhc\_calendar\_id\_mapper=&gt;create\_id\_mapper(  ).
## Mapping the IDs
| Method                      | Description                                                                         |
|-----------------------------|-------------------------------------------------------------------------------------|
| mapping_fcal_legacyid_to_id | Provides the 32-digit factory calendar ID for a two-digit SCAL factory calendar ID  |
| mapping_hcal_legacyid_to_id | Provides the 32-digit holiday calendar ID for a two-digit SCAL holiday calendar ID  |
| mapping_hol_legacyid_to_id  | Provides the 32-digit holiday ID for a three-digit SCAL holi- day ID                |
| mapping_fcal_id_to_legacyid | Provides the two-digit SCAL factory calendar ID for a 32-digit factory calendar ID  |
| mapping_hcal_id_to_legacyid | Provides the two-digit SCAL holiday calendar ID for a 32- digit holiday calendar ID |
| mapping_hol_id_to_legacyid  | Provides the three-digit SCAL holiday calendar ID for a 32- digit holiday ID        |
## 
```
Sample Code try. data(lv_new_id) = lo_id_mapper->mapping_fcal_legacyid_to_id( iv_legacy_id = '01' ). catch cx_fhc_runtime into data(lx_err). "exception handling endtry.
```
```
"another example try. data(lv_legacy_id) = lo_id_mapper->mapping_fcal_id_to_legacyid( iv_factorycalendar_id = 'ExampleID' ). catch cx_fhc_runtime into lx_err. "exception handling endtry.
```
## Reading Additional Factory Calendar-Related Information
Independently from the above factory calendar information, you can use class CL\_SCAL\_UTILS , which contains the following methods:
| Method             | Description                                                        |
|--------------------|--------------------------------------------------------------------|
| MONTH_NAMES_GET    | Provides the names of the months                                   |
| WEEK_GET_FIRST_DAY | Provides the first day of a week                                   |
| DATE_GET_WEEK      | Provides the year and week of a date                               |
| DATE_COMPUTE_DAY   | Provides the name and number of the weekday for a speci- fied date |
## 
```
Sample Code try. cl_scal_utils=>date_get_week( exporting iv_date = '20201001' importing ev_year = data(lv_year) ev_week = data(lv_week) ). catch cx_scal into data(lx_scal). "exception handling endtry.
```